diff --git a/vinvoor/src/cards/CardsTable.tsx b/vinvoor/src/cards/CardsTable.tsx index c21829c..6bf0619 100644 --- a/vinvoor/src/cards/CardsTable.tsx +++ b/vinvoor/src/cards/CardsTable.tsx @@ -20,8 +20,8 @@ const getComparator = ( order: TableOrder, orderBy: Key ): (( - a: { [key in Key]: number | string }, - b: { [key in Key]: number | string } + a: { [key in Key]: number | string | Date }, + b: { [key in Key]: number | string | Date } ) => number) => { return order === "desc" ? (a, b) => descendingComparator(a, b, orderBy) @@ -115,7 +115,7 @@ export const CardsTable = () => { const visibleRows = useMemo( () => - stableSort(cards, getComparator(order, orderBy)).slice( + stableSort(cards, getComparator(order, orderBy)).slice( page * rowsPerPage, page * rowsPerPage + rowsPerPage ), diff --git a/vinvoor/src/overview/checkin/CheckIn.tsx b/vinvoor/src/overview/checkin/CheckIn.tsx index a3fc065..d174615 100644 --- a/vinvoor/src/overview/checkin/CheckIn.tsx +++ b/vinvoor/src/overview/checkin/CheckIn.tsx @@ -7,10 +7,9 @@ import { ScanContext } from "../Overview"; export const CheckIn = () => { const { scans } = useContext(ScanContext); - const checkedIn = isTheSameDay( - scans[scans.length - 1].scanTime, - new Date() - ); + const checkedIn = + scans.length > 0 && + isTheSameDay(scans[scans.length - 1].scanTime, new Date()); return checkedIn ? ( { }} > Checked in - Thank you for stopping by the kelder! + Nice of you to stop by! ) : ( { }} > Not checked in - We miss you in the kelder! + We miss you! ); }; diff --git a/vinvoor/src/overview/streak/Streak.tsx b/vinvoor/src/overview/streak/Streak.tsx index 071d1f7..26275c5 100644 --- a/vinvoor/src/overview/streak/Streak.tsx +++ b/vinvoor/src/overview/streak/Streak.tsx @@ -34,8 +34,9 @@ const isStreakDay = (date1: Date, date2: Date) => { const getStreak = (scans: readonly Scan[]): [boolean, number] => { let streak = 0; const isOnStreak = - isTheSameDay(scans[scans.length - 1].scanTime, new Date()) || - isWeekendBetween(scans[scans.length - 1].scanTime, new Date()); + scans.length > 0 && + (isTheSameDay(scans[scans.length - 1].scanTime, new Date()) || + isWeekendBetween(scans[scans.length - 1].scanTime, new Date())); if (isOnStreak) { let i = scans.length; @@ -59,32 +60,21 @@ export const Streak = () => { const { scans } = useContext(ScanContext); const [isOnStreak, streak] = getStreak(scans); - return isOnStreak ? ( - - - {streak} - - - day{streak > 1 ? "s" : ""} streak - - - ) : ( - + const color = isOnStreak ? "primary" : "error"; + const textEnd = isOnStreak ? "streak" : "absent"; + + return ( + {streak} - - day{streak > 1 ? "s" : ""} absent + + day{streak > 1 ? "s" : ""} {textEnd} );