diff --git a/app/page.tsx b/app/page.tsx index ee1188d..265c197 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,9 +1,8 @@ "use client"; -import ErrorPopup from "@/components/general/errorPopup"; +import NotificationPopup from "@/components/general/notificationPopup"; import ScoringChart from "@/components/scoring/scoringChart"; import { useState } from "react"; -import DraggableElement from "@/components/wrappers/draggable"; import SessionOptions from "@/components/scoring/sessionOptions"; import ScoreSetupMenu from "@/components/scoring/scoreSetupMenu"; import FinalScoringStats from "@/components/scoring/finalScoringStats"; @@ -12,7 +11,6 @@ import SaveScorePopup from "@/components/scoring/saveScorePopup"; export default function Home() { const [setup, setSetup] = useState(true); const [finished, setFinished] = useState(false); - const [saving, setSaving] = useState(false); const [savingPopup, setSavingPopup] = useState(false); const [location, setLocation] = useState(""); @@ -25,12 +23,13 @@ export default function Home() { const [data, setData] = useState({} as any); - const [error, setError] = useState(false); - const [errorMessage, setErrorMessage] = useState(""); + const [notification, setNotification] = useState(false); + const [notificationType, setNotificationType] = useState({} as "success" | "error"); + const [notificationTitle, setNotificationTitle] = useState(""); + const [notificationMessage, setNotificationMessage] = useState(""); const updateSetup = (value: boolean) => setSetup(value); const updateFinished = (value: boolean) => setFinished(value); - const updateSaving = (value: boolean) => setSaving(value); const updateSavingPopup = (value: boolean) => setSavingPopup(value); const updateLocation = (value: string) => setLocation(value); @@ -40,7 +39,7 @@ export default function Home() { const updateArrowsPerEnd = (value: number) => setArrowsPerEnd(value); const updateSplitEnds = (value: number) => setSplitEnds(value); const updateBow = (value: string) => setBow(value); - + const updateData = (value: any) => setData(value); const defaultSetup = () => { @@ -51,7 +50,7 @@ export default function Home() { setArrowsPerEnd(3); setSplitEnds(1); setBow(""); - } + }; const startScoring = () => { if (!checkIfReady()) return; @@ -60,21 +59,24 @@ export default function Home() { }; const checkIfReady = () => { + setNotificationType("error"); + setNotificationTitle("Error"); + if (location === "") { - setError(true); - setErrorMessage("Please select a location"); + setNotification(true); + setNotificationMessage("Please select a location"); return false; } if (distanceUnit === "") { - setError(true); - setErrorMessage("Please select a distance unit"); + setNotification(true); + setNotificationMessage("Please select a distance unit"); return false; } if (bow === "") { - setError(true); - setErrorMessage("Please select a bow"); + setNotification(true); + setNotificationMessage("Please select a bow"); return false; } @@ -85,7 +87,27 @@ export default function Home() { updateSavingPopup(true); }; - const updateError = (value: boolean) => setError(value); + const continueSaving = ({ + title, + date, + time, + note + }: { + title: string; + date: string; + time: string; + note: string; + }) => { + updateSavingPopup(false); + setNotification(true); + setNotificationType("success"); + setNotificationTitle("Success"); + setNotificationMessage("Score saved successfully!"); + + console.log(title, date, time, note); + }; + + const updateNotification = (value: boolean) => setNotification(value); return (
@@ -111,9 +133,7 @@ export default function Home() { done={false} updateData={updateData} /> - {finished ? ( - - ) : null} + {finished ? : null} )} {savingPopup ? ( - + ) : null} - {error ? ( - ) : null}
diff --git a/components/general/errorPopup.tsx b/components/general/notificationPopup.tsx similarity index 75% rename from components/general/errorPopup.tsx rename to components/general/notificationPopup.tsx index 1e1c54b..37b1c3e 100644 --- a/components/general/errorPopup.tsx +++ b/components/general/notificationPopup.tsx @@ -2,23 +2,25 @@ import { useState, useEffect } from "react"; type Props = { title: string; + type: "success" | "error"; message: string; timeout: number; - updateError: (value: boolean) => void; + updateNotification: (value: boolean) => void; }; -export default function ErrorPopup({ +export default function NotificationPopup({ title, + type, message, timeout, - updateError + updateNotification }: Props) { const [opened, setOpened] = useState(false); useEffect(() => { const timer = setTimeout(() => { setOpened(false); - updateError(false); + updateNotification(false); }, timeout); return () => clearTimeout(timer); }); @@ -27,13 +29,13 @@ export default function ErrorPopup({

{title}

-
diff --git a/components/scoring/scoringChart.tsx b/components/scoring/scoringChart.tsx index a9c9a94..218fad9 100644 --- a/components/scoring/scoringChart.tsx +++ b/components/scoring/scoringChart.tsx @@ -87,9 +87,7 @@ export default function ScoringChart(props: Props) { // set the focus the next arrow if (currentArrow < arrowsPerEnd) { - document - .getElementById(`${currentArrow + 1}-${currentEnd}`) - ?.focus(); + document.getElementById(`${currentArrow + 1}-${currentEnd}`)?.focus(); return; } else { // if the end is not the last end, set the focus to the first arrow of the next end @@ -155,7 +153,7 @@ export default function ScoringChart(props: Props) { Arrow {columnIndex + 1} ) )} -
+
Total Running Total
@@ -171,28 +169,44 @@ export default function ScoringChart(props: Props) { handleChange(event, rowIndex, columnIndex)} + onChange={(event) => + handleChange(event, rowIndex, columnIndex) + } /> ))} -
- { - data[currentSplit][rowIndex].some((value: string) => value === '') ? '0' : - data[currentSplit][rowIndex].reduce((a: string, b: string) => { - return addScores(a, b) - }, 0) - } - { - data[currentSplit][rowIndex].some((value: string) => value === '') ? '0' : - data[currentSplit].slice(0, rowIndex + 1).reduce((a: any, b: any) => { - return a + b.reduce((c: any, d: any) => { - return addScores(c, d); - }, 0); - }, 0) - } +
+ + {data[currentSplit][rowIndex].some( + (value: string) => value === "" + ) + ? "0" + : data[currentSplit][rowIndex].reduce( + (a: string, b: string) => { + return addScores(a, b); + }, + 0 + )} + + + {data[currentSplit][rowIndex].some( + (value: string) => value === "" + ) + ? "0" + : data[currentSplit] + .slice(0, rowIndex + 1) + .reduce((a: any, b: any) => { + return ( + a + + b.reduce((c: any, d: any) => { + return addScores(c, d); + }, 0) + ); + }, 0)} +
))}