Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 60 additions & 29 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export default function Home() {
const [selectedIndex, setSelectedIndex] = useState(0);
const [circleStates, setCircleStates] = useState<string[]>(Array(8 * 12).fill("red"));
const forward = useRef(true);
const numGreen = useRef(0);
const numYellow = useRef(0);


useEffect(() => {
Expand All @@ -36,17 +38,17 @@ export default function Home() {
const coordinate = getCoordinate(selectedIndex);
const utterance = new SpeechSynthesisUtterance(`${coordinate}`);
window.speechSynthesis.speak(utterance);
if(((selectedIndex + 1) % 12 == 0 && forward.current) && selectedIndex !== 0){
if(((selectedIndex + 1) % cols == 0 && forward.current) && selectedIndex !== 0){
forward.current = false;
changed = true;
setSelectedIndex((prev) => Math.min(prev + 12, totalCircles - 1));
setSelectedIndex((prev) => Math.min(prev + cols, totalCircles - 1));
}


if(selectedIndex % 12 == 0 && !(forward.current)){
if(selectedIndex % cols == 0 && !(forward.current)){
forward.current = true;
changed = true;
setSelectedIndex((prev) => Math.min(prev + 12, totalCircles - 1));
setSelectedIndex((prev) => Math.min(prev + cols, totalCircles - 1));
}


Expand All @@ -64,17 +66,17 @@ export default function Home() {
const coordinate = getCoordinate(selectedIndex);
const utterance = new SpeechSynthesisUtterance(`${coordinate}`);
window.speechSynthesis.speak(utterance);
if((selectedIndex % 12 == 0 && forward.current) && selectedIndex !== 0){
if((selectedIndex % cols == 0 && forward.current) && selectedIndex !== 0){
forward.current = false;
changed = true;
setSelectedIndex((prev) => Math.max(0, Math.min(prev - 12, totalCircles - 1)));
setSelectedIndex((prev) => Math.max(0, Math.min(prev - cols, totalCircles - 1)));
}


if((selectedIndex + 1) % 12 == 0 && !(forward.current)){
if((selectedIndex + 1) % cols == 0 && !(forward.current)){
forward.current = true;
changed = true;
setSelectedIndex((prev) => Math.max(0, Math.min(prev - 12, totalCircles - 1)));
setSelectedIndex((prev) => Math.max(0, Math.min(prev - cols, totalCircles - 1)));
}


Expand All @@ -89,27 +91,41 @@ export default function Home() {
changed = false;
}
} else if (e.key === "b" || e.key === "B") {
setCircleStates((prev) => {
const newStates = [...prev];
newStates[selectedIndex] = "blue";
return newStates;
});

setCircleStates((prev) => {
const newStates = [...prev];
if (newStates[selectedIndex] === "yellow") {
newStates[selectedIndex] = "red";
} else {
newStates[selectedIndex] = "yellow";
}
return newStates;
});

if (circleStates[selectedIndex] === "yellow"){
numYellow.current = numYellow.current - 1;
} else if (circleStates[selectedIndex] === "green"){
numGreen.current = numGreen.current - 1;
numYellow.current = numYellow.current + 1;
} else {
numYellow.current = numYellow.current + 1;
}

const coordinate = getCoordinate(selectedIndex);
const utterance = new SpeechSynthesisUtterance(`${coordinate}`);
window.speechSynthesis.speak(utterance);

if(((selectedIndex + 1) % 12 == 0 && forward.current) && selectedIndex !== 0){
if(((selectedIndex + 1) % cols == 0 && forward.current) && selectedIndex !== 0){
forward.current = false;
changed = true;
setSelectedIndex((prev) => Math.min(prev + 12, totalCircles - 1));
setSelectedIndex((prev) => Math.min(prev + cols, totalCircles - 1));
}


if(selectedIndex % 12 == 0 && !(forward.current)){
if(selectedIndex % cols == 0 && !(forward.current)){
forward.current = true;
changed = true;
setSelectedIndex((prev) => Math.min(prev + 12, totalCircles - 1));
setSelectedIndex((prev) => Math.min(prev + cols, totalCircles - 1));
}


Expand All @@ -126,27 +142,40 @@ export default function Home() {
} else if (e.key === "PageUp" || e.key === "n" || e.key === "N") {
setCircleStates((prev) => {
const newStates = [...prev];
newStates[selectedIndex] = newStates[selectedIndex] === "red" ? "green" : "red";
if (newStates[selectedIndex] === "green") {
newStates[selectedIndex] = "red";
} else {
newStates[selectedIndex] = "green";
}
return newStates;
});




const coordinate = getCoordinate(selectedIndex);
const utterance = new SpeechSynthesisUtterance(`${coordinate}`);
window.speechSynthesis.speak(utterance);

if (circleStates[selectedIndex] === "green"){
numGreen.current = numGreen.current - 1;
} else if (circleStates[selectedIndex] === "yellow"){
numYellow.current = numYellow.current - 1;
numGreen.current = numGreen.current + 1;
} else {
numGreen.current = numGreen.current + 1;
}


if(((selectedIndex + 1) % 12 == 0 && forward.current) && selectedIndex !== 0){
if(((selectedIndex + 1) % cols == 0 && forward.current) && selectedIndex !== 0){
forward.current = false;
changed = true;
setSelectedIndex((prev) => Math.min(prev + 12, totalCircles - 1));
setSelectedIndex((prev) => Math.min(prev + cols, totalCircles - 1));
}


if(selectedIndex % 12 == 0 && !(forward.current)){
if(selectedIndex % cols == 0 && !(forward.current)){
forward.current = true;
changed = true;
setSelectedIndex((prev) => Math.min(prev + 12, totalCircles - 1));
setSelectedIndex((prev) => Math.min(prev + cols, totalCircles - 1));
}


Expand Down Expand Up @@ -179,7 +208,7 @@ export default function Home() {
const handleExport = () => {
const values = circleStates.map((state) => {
if (state === "green") return 1;
if (state === "blue") return 2;
if (state === "yellow") return 2;
return 0;
});
const data = {
Expand Down Expand Up @@ -220,7 +249,7 @@ export default function Home() {
setNotes(data.notes || "");
setCircleStates(data.values.map((v: number) => {
if (v === 1) return "green";
if (v === 2) return "blue";
if (v === 2) return "yellow";
return "red";
}));
}
Expand Down Expand Up @@ -306,7 +335,7 @@ export default function Home() {
</label>
<button
onClick={handleExport}
className="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"
className="bg-yellow-500 text-white px-4 py-2 rounded hover:bg-yellow-600"
>
Export
</button>
Expand Down Expand Up @@ -355,8 +384,8 @@ export default function Home() {
key={index}
onClick={() => handleCircleClick(index)}
className={`w-8 h-8 sm:w-10 sm:h-10 md:w-12 md:h-12 lg:w-10 lg:h-10 xl:w-12 xl:h-12 rounded-full flex justify-center items-center cursor-pointer
${circleStates[index] === "green" ? "bg-green-500" : circleStates[index] === "blue" ? "bg-blue-500" : "bg-red-500"}
${selectedIndex === index ? "border-4 border-blue-500" : ""}`}
${circleStates[index] === "green" ? "bg-green-500" : circleStates[index] === "yellow" ? "bg-yellow-500" : "bg-red-500"}
${selectedIndex === index ? "border-4 border-yellow-500" : ""}`}
>
<span className="text-white text-xs sm:text-sm md:text-base lg:text-sm xl:text-base">
{getCoordinate(index)}
Expand All @@ -366,6 +395,8 @@ export default function Home() {
</div>
</div>
</div>
<div>Number of green states: {numGreen.current}</div>
<div>Number of yellow states: {numYellow.current}</div>
</div>
</div>
</main>
Expand Down
27 changes: 17 additions & 10 deletions src/pages/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type GridData = {

export default function View() {
const [dataList, setDataList] = useState<GridData[]>([]);
const [showBlue, setShowBlue] = useState(true);
const [showyellow, setShowyellow] = useState(true);

const handleImport = async (event: React.ChangeEvent<HTMLInputElement>) => {
const files = event.target.files;
Expand Down Expand Up @@ -68,8 +68,8 @@ export default function View() {
background-color: #10B981 !important;
}

.bg-blue-500 {
background-color: #3B82F6 !important;
.bg-yellow-500 {
background-color: #ECC94B !important;
}

.bg-red-500 {
Expand Down Expand Up @@ -97,8 +97,11 @@ export default function View() {
className="border p-2 rounded"
/>
{dataList.map((data) => {
const yellowCount = data.values.filter((value) => value === 2).length;
const greenCount = data.values.filter((value) => value === 1).length;

const hiddenCells = data.values
.map((value, index) => (value === 2 && !showBlue ? index + 1 : null))
.map((value, index) => (value === 2 && !showyellow ? index + 1 : null))
.filter((index) => index !== null) as number[];

const rowLabels = Array.from({ length: data.rows }, (_, i) => alphabet[i % 26]);
Expand All @@ -109,11 +112,11 @@ export default function View() {
<label className="flex items-center space-x-2">
<input
type="checkbox"
checked={showBlue}
onChange={(e) => setShowBlue(e.target.checked)}
checked={showyellow}
onChange={(e) => setShowyellow(e.target.checked)}
className="form-checkbox"
/>
<span>Show blue circles</span>
<span>Show yellow circles</span>
</label>
<div className="flex-grow flex justify-center items-center py-4">
<div className="flex flex-col space-y-2">
Expand Down Expand Up @@ -152,7 +155,7 @@ export default function View() {
<div
key={index}
className={`w-8 h-8 sm:w-10 sm:h-10 md:w-12 md:h-12 lg:w-10 lg:h-10 xl:w-12 xl:h-12 rounded-full flex justify-center items-center
${value === 1 ? "bg-green-500" : value === 2 ? (showBlue ? "bg-blue-500" : "hidden") : "bg-red-500"}`}
${value === 1 ? "bg-green-500" : value === 2 ? (showyellow ? "bg-yellow-500" : "hidden") : "bg-red-500"}`}
>
<span className="text-white text-xs sm:text-sm md:text-base lg:text-sm xl:text-base">
{getCoordinate(index, data.cols)}
Expand All @@ -168,9 +171,13 @@ export default function View() {
<p><strong>Columns:</strong> {data.cols}</p>
<p><strong>Notes:</strong> {data.notes}</p>
</div>
{!showBlue && hiddenCells.length > 0 && (
<div className="text-center mt-4">
<p><strong>Green Circles:</strong> {greenCount}</p>
<p><strong>Yellow Circles:</strong> {yellowCount}</p>
</div>
{!showyellow && hiddenCells.length > 0 && (
<div className="mt-4">
<h2 className="text-lg font-semibold">Hidden Blue Circles:</h2>
<h2 className="text-lg font-semibold">Hidden yellow Circles:</h2>
<ul className="list-disc list-inside mt-2">
{hiddenCells.map((index) => (
<li key={index}>Circle {index}</li>
Expand Down