diff --git a/client/src/App.tsx b/client/src/App.tsx index 8dad5f4..19d6bc2 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -172,12 +172,6 @@ function App() { } }, [handleKeyDown]); - // Index v týdnu dnešního dne (0-6) - // TODO tohle má posílat server, klient je nespolehlivý - const currentDayIndex = useMemo(() => { - return (((new Date().getDay() - 1) % 7) + 7) % 7; - }, []) - const doAddChoice = async (event: React.ChangeEvent) => { const index = Object.keys(Locations).indexOf(event.target.value as unknown as Locations); if (auth?.login) { @@ -381,7 +375,7 @@ function App() { {dayIndex != null &&
{dayIndex > 0 && handleDayChange(dayIndex - 1)} />} -

{`${dayIndex === currentDayIndex ? "(Dnes) " : ""}${data.date}`}

+

{`${dayIndex === data.todayWeekIndex ? "(Dnes) " : ""}${data.date}`}

{dayIndex < 4 && handleDayChange(dayIndex + 1)} />}
} @@ -392,8 +386,8 @@ function App() {
- {dayIndex == null || dayIndex >= currentDayIndex && <> -

{`Jak to ${dayIndex == null || dayIndex === currentDayIndex ? 'dnes' : 'tento den'} vidíš s obědem?`}

+ {dayIndex == null || dayIndex >= data.todayWeekIndex && <> +

{`Jak to ${dayIndex == null || dayIndex === data.todayWeekIndex ? 'dnes' : 'tento den'} vidíš s obědem?`}

{Object.entries(Locations) @@ -482,7 +476,7 @@ function App() { :
Zatím nikdo nehlasoval...
}
- {dayIndex === currentDayIndex && + {dayIndex === data.todayWeekIndex &&
{!data.pizzaDay &&
diff --git a/server/src/service.ts b/server/src/service.ts index 8885569..af8fbd4 100644 --- a/server/src/service.ts +++ b/server/src/service.ts @@ -32,7 +32,7 @@ export const getDateForWeekIndex = (index: number) => { /** Vrátí "prázdná" (implicitní) data pro předaný den. */ function getEmptyData(date?: Date): ClientData { const usedDate = date || getToday(); - return { date: getHumanDate(usedDate), isWeekend: getIsWeekend(usedDate), weekIndex: getDayOfWeekIndex(usedDate), choices: {} }; + return { date: getHumanDate(usedDate), isWeekend: getIsWeekend(usedDate), weekIndex: getDayOfWeekIndex(usedDate), todayWeekIndex: getDayOfWeekIndex(getToday()), choices: {} }; } /** diff --git a/types/Types.ts b/types/Types.ts index 118cb06..5a00cda 100644 --- a/types/Types.ts +++ b/types/Types.ts @@ -68,9 +68,10 @@ interface PizzaDay { /** Veškerá data pro zobrazení na klientovi */ export interface ClientData { - date: string, // dnešní datum pro zobrazení - isWeekend: boolean, // příznak, zda je dnes víkend - weekIndex: number, // index aktuálního dne v týdnu (0-6) + date: string, // datum vybraného dne pro zobrazení + isWeekend: boolean, // příznak, zda je zvolené datum víkend + weekIndex: number, // index zvoleného dne v týdnu (0-6) + todayWeekIndex: number, // index dnešního dne v týdnu (0-6) choices: Choices, // seznam voleb menus?: { [restaurant in Restaurants]?: Menu }, // menu jednotlivých restaurací pizzaDay?: PizzaDay, // pizza day pro dnešní den, pokud existuje