Skip to content

Commit

Permalink
Chart box switch timing & input changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cqb13 committed Sep 25, 2023
1 parent 2940240 commit 927919f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
38 changes: 29 additions & 9 deletions components/scoring/scoringChart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import Button from "@components/general/button";
import isMobile from "@/utils/isMobile";
import { useState, useEffect } from "react";

type Props = {
Expand All @@ -16,6 +17,7 @@ type Props = {
export default function ScoringChart(props: Props) {
const [currentSplit, setCurrentSplit] = useState(0);
const [data, setData] = useState({} as any);
const mobileDevice = isMobile();

useEffect(() => {
if (!props.updateData) return;
Expand All @@ -40,26 +42,28 @@ export default function ScoringChart(props: Props) {

const handleChange = (event: any, rowIndex: any, columnIndex: any) => {
if (props.history) return;
let delay = event.target.value.startsWith("1") ? 1000 : 0;

const value = event.target.value;

let delay = value.startsWith("1") && value != "10" ? 1500 : 0;

const updatedData = data[currentSplit].map((row: any, rIndex: any) => {
if (rIndex === rowIndex) {
return row.map((column: any, cIndex: any) => {
if (cIndex === columnIndex) {
switch (event.target.value) {
switch (value) {
case "m":
case "M":
case "x":
case "X":
setTimeout(() => {
switchFocus(event, columnIndex, rowIndex);
switchFocus(columnIndex, rowIndex);
}, delay);
return event.target.value;
return value;
default:
break;
}
return /^(0|[1-9]|1[0-1])$/.test(event.target.value)
? event.target.value
: "";
return /^(0|[1-9]|1[0-1])$/.test(value) ? value : "";
}
return column;
});
Expand All @@ -75,12 +79,12 @@ export default function ScoringChart(props: Props) {

if (/^(0|[1-9]|1[0-1])$/.test(event.target.value)) {
setTimeout(() => {
switchFocus(event, columnIndex, rowIndex);
switchFocus(columnIndex, rowIndex);
}, delay);
}
};

const switchFocus = (event: any, columnIndex: number, rowIndex: number) => {
const switchFocus = (columnIndex: number, rowIndex: number) => {
let arrowsPerEnd = props.arrowsPerEnd;
let ends = props.ends;
let currentArrow = columnIndex + 1;
Expand Down Expand Up @@ -136,6 +140,17 @@ export default function ScoringChart(props: Props) {
}
}, [props.arrowsPerEnd, props.ends, props.splits, props.score]);

const setValueOfSelectedBox = (value: string) => {
for (let i = 0; i < data[currentSplit].length; i++) {
for (let j = 0; j < data[currentSplit][i].length; j++) {
if (data[currentSplit][i][j] === "") {
handleChange({ target: { value: value } }, i, j);
return;
}
}
}
};

return (
<section className='flex flex-col gap-2'>
{props.splits > 1 ? (
Expand Down Expand Up @@ -170,6 +185,7 @@ export default function ScoringChart(props: Props) {
type='text'
id={`${columnIndex + 1}-${rowIndex + 1}`}
pattern='[0-9mxMX]*'
inputMode='numeric'
className='bg-lightest border border-gray-300 rounded-sm outline-none focus:border-highlight px-2 w-11/12'
value={column}
onChange={(event) =>
Expand Down Expand Up @@ -212,6 +228,10 @@ export default function ScoringChart(props: Props) {
))}
</tbody>
</table>
<section className={`${mobileDevice ? "" : ""} flex gap-2`}>
<Button title='X' onClick={() => setValueOfSelectedBox("X")} />
<Button title='M' onClick={() => setValueOfSelectedBox("M")} />
</section>
</section>
);
}
5 changes: 5 additions & 0 deletions utils/isMobile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
);
}

1 comment on commit 927919f

@vercel
Copy link

@vercel vercel bot commented on 927919f Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.