Skip to content

Commit

Permalink
fix menu dates calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
33tm committed Nov 14, 2024
1 parent c57683f commit 59b1374
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
10 changes: 3 additions & 7 deletions client/src/components/layout/PeriodActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ActionButton(props: ActionButtonProps) {
const { children, now, note, onClick } = props;
return (
<button
className={`mt-2 w-full px-3.5 py-1.5 right-5 top-0 rounded-md ${note || 'sm:w-fit sm:absolute sm:my-auto sm:h-fit'} ${now ? 'bottom-8' : 'bottom-0'} bg-black/10 dark:bg-black/20 hover:bg-black/20 dark:hover:bg-black/30 transition duration-75`}
className={`mt-2 w-full px-3.5 py-1.5 right-5 top-0 rounded-md ${note || 'md:w-fit md:absolute md:my-auto md:h-fit'} ${now ? 'bottom-8' : 'bottom-0'} bg-black/10 dark:bg-black/20 hover:bg-black/20 dark:hover:bg-black/30 transition duration-75`}
onClick={onClick}
>
{children}
Expand Down Expand Up @@ -58,12 +58,7 @@ function MenuAction(props: PeriodActionButtonProps) {
const formatted = date.toFormat('MM-dd');
const meal = name.toLowerCase() as 'brunch' | 'lunch';

if (!menu) {
localStorage.removeItem('menu');
return <></>
}

if (formatted in menu && menu[formatted][meal])
if (menu && formatted in menu && menu[formatted][meal]) {
return (
<>
<ActionButton {...props} onClick={() => setModal(true)}>
Expand All @@ -77,6 +72,7 @@ function MenuAction(props: PeriodActionButtonProps) {
/>
</>
)
}

return <></>
}
18 changes: 8 additions & 10 deletions client/src/components/lists/MenuModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function MenuModal(props: MenuModalProps) {
const [nutritionModal, setNutritionModal] = useState<string | null>(null);

return (
<CenteredModal className="relative flex flex-col bg-content rounded-md w-[28rem] max-h-[90%] mx-2 p-6 shadow-xl" isOpen={isOpen} setIsOpen={setIsOpen}>
<CenteredModal className="relative flex flex-col bg-content rounded-md min-w-full sm:min-w-[28rem] max-h-[90%] mx-2 p-6 shadow-xl" isOpen={isOpen} setIsOpen={setIsOpen}>
<Dialog.Title className="text-xl font-semibold mb-3 pr-6">
{name} Menu
</Dialog.Title>
Expand All @@ -29,18 +29,16 @@ export default function MenuModal(props: MenuModalProps) {
<div key={item}>
<div
className="truncate text-center cursor-pointer px-8 py-4 text-secondary rounded-md bg-black/10 dark:bg-black/20 hover:bg-black/20 dark:hover:bg-black/30 transition duration-75"
onClick={() => nutrition && setNutritionModal(item)}
onClick={() => setNutritionModal(item)}
>
{item}
</div>
{nutrition && (
<NutritionModal
item={item}
nutrition={nutrition}
isOpen={(nutritionModal === item)}
setIsOpen={() => setNutritionModal(null)}
/>
)}
<NutritionModal
item={item}
nutrition={nutrition}
isOpen={nutritionModal === item}
setIsOpen={() => setNutritionModal(null)}
/>
</div>
))}
</section>
Expand Down
5 changes: 2 additions & 3 deletions functions/src/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SCHOOL_START, SCHOOL_END } from '@watt/shared/data/schedule';
const firestore = admin.firestore();

export const menu = onSchedule("every day 00:00", async () => {
const now = DateTime.now().setZone('America/Los_Angeles');
const now = DateTime.now();

if (now < SCHOOL_START || now > SCHOOL_END) {
await firestore.collection('gunn').doc('menu').set({
Expand Down Expand Up @@ -66,8 +66,7 @@ export const menu = onSchedule("every day 00:00", async () => {

const days = Array
.from({ length: daysInMonth }, (_, i) => DateTime
.fromObject({ year, month, day: i + 1 })
.setZone('America/Los_Angeles'))
.fromObject({ year, month, day: i + 1 }))
.filter(day => {
const { periods } = getSchedule(day, alternates);
return periods && periods.filter(({ n }) => n === 'B' || n === 'L').length;
Expand Down

0 comments on commit 59b1374

Please sign in to comment.