diff --git a/apps/next/src/components/ui/restaurant/dishes-view.tsx b/apps/next/src/components/ui/restaurant/dishes-view.tsx index 43801259..0087d835 100644 --- a/apps/next/src/components/ui/restaurant/dishes-view.tsx +++ b/apps/next/src/components/ui/restaurant/dishes-view.tsx @@ -5,6 +5,7 @@ import { useMemo } from "react"; import DishesInfo from "@/components/ui/dishes-info"; import { useRestaurantUIStore } from "@/context/useRestaurantUIStore"; import { useUserStore } from "@/context/useUserStore"; +import { useShowSuitableDishesOnly } from "@/hooks/useShowSuitableDishesOnly"; import { getDietaryConflicts } from "@/utils/dietary"; import { toTitleCase } from "@/utils/funcs"; import { trpc } from "@/utils/trpc"; @@ -25,9 +26,7 @@ export function DishesView({ hallData, }: DishesViewProps) { const isCompactView = useRestaurantUIStore((s) => s.isCompactView); - const showPreferencesOnly = useRestaurantUIStore( - (s) => s.showPreferencesOnly, - ); + const { showSuitableDishesOnly } = useShowSuitableDishesOnly(); const errorMessage = error?.message ?? @@ -47,7 +46,7 @@ export function DishesView({ return new Map( stations.map((station) => [ station.name, - showPreferencesOnly && allergies && preferences + showSuitableDishesOnly && allergies && preferences ? station.dishes.filter( (dish) => getDietaryConflicts( @@ -59,7 +58,7 @@ export function DishesView({ : station.dishes, ]), ); - }, [stations, showPreferencesOnly, preferences, allergies]); + }, [stations, showSuitableDishesOnly, preferences, allergies]); return (
diff --git a/apps/next/src/components/ui/restaurant/header/desktop-tabs.tsx b/apps/next/src/components/ui/restaurant/header/desktop-tabs.tsx index 717d76fc..aff34342 100644 --- a/apps/next/src/components/ui/restaurant/header/desktop-tabs.tsx +++ b/apps/next/src/components/ui/restaurant/header/desktop-tabs.tsx @@ -1,6 +1,5 @@ import type { Station } from "@api/index"; -import { GridView, Menu as MenuIcon } from "@mui/icons-material"; -import { Button, Tab, Tabs } from "@mui/material"; +import { Tab, Tabs } from "@mui/material"; import { useRestaurantUIStore } from "@/context/useRestaurantUIStore"; import { scrollToStation, toTitleCase } from "@/utils/funcs"; @@ -19,8 +18,6 @@ export function DesktopTabs({ }: DesktopTabsProps) { const selectedStation = useRestaurantUIStore((s) => s.selectedStation); const setSelectedStation = useRestaurantUIStore((s) => s.setSelectedStation); - const isCompactView = useRestaurantUIStore((s) => s.isCompactView); - const setIsCompactView = useRestaurantUIStore((s) => s.setIsCompactView); if (!isDesktop) return null; @@ -48,29 +45,6 @@ export function DesktopTabs({ ))} )} - {/* Card / compact view toggles */} -
-
- - -
-
); } diff --git a/apps/next/src/components/ui/restaurant/header/restaurant-filters.tsx b/apps/next/src/components/ui/restaurant/header/restaurant-filters.tsx index 53f957e8..3ef511d5 100644 --- a/apps/next/src/components/ui/restaurant/header/restaurant-filters.tsx +++ b/apps/next/src/components/ui/restaurant/header/restaurant-filters.tsx @@ -1,12 +1,16 @@ "use client"; -import { ArrowDropDownRounded } from "@mui/icons-material"; import { + ArrowDropDownRounded, + GridView, + Menu as MenuIcon, +} from "@mui/icons-material"; +import { + Button, FormControl, InputLabel, MenuItem, Select, - Tooltip, Typography, } from "@mui/material"; import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFns"; @@ -15,9 +19,7 @@ import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider"; import { useTheme } from "next-themes"; import type { CalendarRange } from "@/components/ui/toolbar"; import { useRestaurantUIStore } from "@/context/useRestaurantUIStore"; -import { useUserStore } from "@/context/useUserStore"; import { formatOpenCloseTime, toTitleCase } from "@/utils/funcs"; -import { cn } from "@/utils/tw"; interface RestaurantFiltersProps { isDesktop: boolean; @@ -38,7 +40,6 @@ export function RestaurantFilters({ calendarRange, }: RestaurantFiltersProps) { const { resolvedTheme } = useTheme(); - const { userId } = useUserStore(); const selectedPeriod = useRestaurantUIStore((s) => s.selectedPeriod); const setSelectedPeriod = useRestaurantUIStore((s) => s.setSelectedPeriod); @@ -46,32 +47,8 @@ export function RestaurantFilters({ const setIsDatePickerOpen = useRestaurantUIStore( (s) => s.setIsDatePickerOpen, ); - const showPreferencesOnly = useRestaurantUIStore( - (s) => s.showPreferencesOnly, - ); - const setShowPreferencesOnly = useRestaurantUIStore( - (s) => s.setShowPreferencesOnly, - ); - - const ShowPrefsButton = ( - - ); + const isCompactView = useRestaurantUIStore((s) => s.isCompactView); + const setIsCompactView = useRestaurantUIStore((s) => s.setIsCompactView); return ( // On desktop, items keep their natural widths on one line, and wrap and @@ -174,6 +151,7 @@ export function RestaurantFilters({ handleDateSelect(newValue || undefined)} minDate={calendarRange.earliest} maxDate={calendarRange.latest} @@ -234,14 +212,29 @@ export function RestaurantFilters({ )} -
- {!userId && ( - - {ShowPrefsButton} - - )} - {userId && ShowPrefsButton} -
+ {/* Card / compact view toggles (desktop only; mobile has its own) */} + {isDesktop && ( +
+ + +
+ )} ); } diff --git a/apps/next/src/components/ui/restaurant/restaurant-controls.tsx b/apps/next/src/components/ui/restaurant/restaurant-controls.tsx index 938608ec..e9343e3b 100644 --- a/apps/next/src/components/ui/restaurant/restaurant-controls.tsx +++ b/apps/next/src/components/ui/restaurant/restaurant-controls.tsx @@ -1,10 +1,11 @@ import type { Station } from "@api/index"; import { MoreHoriz } from "@mui/icons-material"; -import { IconButton, Typography } from "@mui/material"; +import { Chip, IconButton, Typography } from "@mui/material"; import type { DishWithRating, Event } from "@peterplate/validators"; import { DiningHallStatus } from "@/components/ui/status"; import type { CalendarRange } from "@/components/ui/toolbar"; import { useRestaurantUIStore } from "@/context/useRestaurantUIStore"; +import { useShowSuitableDishesOnly } from "@/hooks/useShowSuitableDishesOnly"; import { toTitleCase } from "@/utils/funcs"; import type { HallEnum, HallStatusEnum } from "@/utils/types"; import { DesktopTabs } from "./header/desktop-tabs"; @@ -51,6 +52,8 @@ export function RestaurantControls({ ); const selectedPeriod = useRestaurantUIStore((s) => s.selectedPeriod); const showFilters = isDesktop || isFiltersExpanded; + const { showSuitableDishesOnly, setShowSuitableDishesOnly } = + useShowSuitableDishesOnly(); return ( // Sticky while scrolling @@ -99,6 +102,17 @@ export function RestaurantControls({ id="tour-filters-mobile" className="flex flex-col gap-3 w-full md:w-auto md:grow md:flex-row md:items-center md:justify-end" > + {/* Shown even with mobile filters collapsed, since the setting persists */} + {showSuitableDishesOnly && ( + setShowSuitableDishesOnly(false)} + className="self-start ml-3 md:self-auto md:ml-0" + /> + )} + {/* Meal & date selectors */} {showFilters && ( - {/* Station tabs & card/compact view toggles (desktop only) */} + {/* Station tabs (desktop only) */} + {/* On desktop this sits in the sidebar instead */} + {!isDesktop && } +
+ + {/* Hours of operation card */} diff --git a/apps/next/src/components/ui/restaurant/today-events.tsx b/apps/next/src/components/ui/restaurant/today-events.tsx new file mode 100644 index 00000000..6b1cbfe6 --- /dev/null +++ b/apps/next/src/components/ui/restaurant/today-events.tsx @@ -0,0 +1,65 @@ +import { Typography } from "@mui/material"; +import type { Event } from "@peterplate/validators"; +import { endOfDay, startOfDay } from "date-fns"; + +const formatTime = (date: Date) => + date.toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit" }); + +/** Cards for this hall's events happening today, shown above the hours. */ +export function TodayEvents({ events }: { events: Event[] }) { + const now = new Date(); + const todayEvents = events + .map((event) => { + const start = new Date(event.start); + const end = new Date(event.end); + // Some events have no end time (it arrives as the Unix epoch) + return { event, start, end: end > start ? end : null }; + }) + .filter( + ({ start, end }) => + start <= endOfDay(now) && (end ?? start) >= startOfDay(now), + ); + + if (todayEvents.length === 0) return null; + + return ( +
+ {todayEvents.map(({ event, start, end }) => ( +
+
+ ))} +
+ ); +} diff --git a/apps/next/src/components/ui/sidebar/sidebar-content.tsx b/apps/next/src/components/ui/sidebar/sidebar-content.tsx index c3ac9ed9..10f6f01c 100644 --- a/apps/next/src/components/ui/sidebar/sidebar-content.tsx +++ b/apps/next/src/components/ui/sidebar/sidebar-content.tsx @@ -13,7 +13,7 @@ import { Logout as LogoutIcon, Notifications as NotificationsIcon, } from "@mui/icons-material"; -import { Box, Tooltip, Typography } from "@mui/material"; +import { Box, Switch, Tooltip, Typography } from "@mui/material"; import Image from "next/image"; import Link from "next/link"; import { useTheme } from "next-themes"; @@ -22,6 +22,7 @@ import type { ReactNode } from "react"; import { useEffect, useState } from "react"; import { SignInButtons } from "@/components/auth/sign-in-buttons"; import NotificationsPanel from "@/components/ui/notifications-panel"; +import { useShowSuitableDishesOnly } from "@/hooks/useShowSuitableDishesOnly"; import { signOut, useSession } from "@/utils/auth-client"; import { formatDietaryKey } from "@/utils/dietary"; import { trpc } from "@/utils/trpc"; @@ -43,6 +44,8 @@ export default function SidebarContent({ const userId = user?.id; const { theme, setTheme } = useTheme(); const [mounted, setMounted] = useState(false); + const { showSuitableDishesOnly, isPending, setShowSuitableDishesOnly } = + useShowSuitableDishesOnly(); const [showNotifications, setShowNotifications] = useState(false); useEffect(() => setMounted(true), []); @@ -59,11 +62,11 @@ export default function SidebarContent({ const handleSignOut = async () => { const userTheme = theme ?? localStorage.getItem("theme"); - await signOut(); - if (userTheme) { - localStorage.setItem("theme", userTheme); - } - window.location.href = "/"; + await signOut({ + onBeforeRedirect: () => { + if (userTheme) localStorage.setItem("theme", userTheme); + }, + }); }; if (showNotifications) { @@ -154,6 +157,21 @@ export default function SidebarContent({ )}
+ +
+ + Show Suitable Dishes Only + + setShowSuitableDishesOnly(e.target.checked)} + color="primary" + slotProps={{ + input: { "aria-label": "Show suitable dishes only" }, + }} + /> +
)} diff --git a/apps/next/src/components/ui/toolbar.tsx b/apps/next/src/components/ui/toolbar.tsx index 4bba6533..ff5e6842 100644 --- a/apps/next/src/components/ui/toolbar.tsx +++ b/apps/next/src/components/ui/toolbar.tsx @@ -728,13 +728,14 @@ function MobileToolbar(): React.JSX.Element { -
+
+ {/* Less top padding because icons have built-in space above them */}
@@ -754,25 +755,16 @@ function MobileToolbar(): React.JSX.Element { w-[64px] gap-1 transition - ${active ? "opacity-100" : "opacity-85 hover:opacity-100"} + ${active ? "text-white dark:!text-[var(--nav-active-text)]" : "text-[#c1e5fb] hover:text-white dark:text-white dark:opacity-85 dark:hover:opacity-100"} `} > -
+
{element.icon}
{element.title} diff --git a/apps/next/src/context/useRestaurantUIStore.ts b/apps/next/src/context/useRestaurantUIStore.ts index 1fe1559a..1ca4d493 100644 --- a/apps/next/src/context/useRestaurantUIStore.ts +++ b/apps/next/src/context/useRestaurantUIStore.ts @@ -20,10 +20,6 @@ interface RestaurantUIState { isCompactView: boolean; setIsCompactView: (isCompact: boolean) => void; - // Preferences filter - showPreferencesOnly: boolean; - setShowPreferencesOnly: (show: boolean) => void; - // Date picker open state isDatePickerOpen: boolean; setIsDatePickerOpen: (isOpen: boolean) => void; @@ -49,9 +45,6 @@ export const useRestaurantUIStore = create()((set) => ({ isCompactView: false, setIsCompactView: (isCompact) => set({ isCompactView: isCompact }), - showPreferencesOnly: false, - setShowPreferencesOnly: (show) => set({ showPreferencesOnly: show }), - isDatePickerOpen: false, setIsDatePickerOpen: (isOpen) => set({ isDatePickerOpen: isOpen }), diff --git a/apps/next/src/hooks/useShowSuitableDishesOnly.ts b/apps/next/src/hooks/useShowSuitableDishesOnly.ts new file mode 100644 index 00000000..6986bc80 --- /dev/null +++ b/apps/next/src/hooks/useShowSuitableDishesOnly.ts @@ -0,0 +1,41 @@ +import { useUserStore } from "@/context/useUserStore"; +import { trpc } from "@/utils/trpc"; + +/** + * The signed-in user's "Show Suitable Dishes Only" setting, saved to their + * account so it carries across reloads and devices. Updates apply + * optimistically and roll back if saving fails. + */ +export function useShowSuitableDishesOnly() { + const userId = useUserStore((s) => s.userId); + const utils = trpc.useUtils(); + const input = { id: userId ?? "" }; + + const { data: user } = trpc.user.get.useQuery(input, { enabled: !!userId }); + + const { mutate, isPending } = trpc.user.setShowSuitableDishesOnly.useMutation( + { + onMutate: async ({ value }) => { + await utils.user.get.cancel(input); + const previous = utils.user.get.getData(input); + utils.user.get.setData(input, (old) => + old ? { ...old, showSuitableDishesOnly: value } : old, + ); + return { previous }; + }, + onError: (_error, _vars, context) => { + if (context?.previous) utils.user.get.setData(input, context.previous); + }, + onSettled: () => utils.user.get.invalidate(input), + }, + ); + + return { + showSuitableDishesOnly: user?.showSuitableDishesOnly ?? false, + // Not loaded yet, or a save is in flight + isPending: !user || isPending, + setShowSuitableDishesOnly: (value: boolean) => { + if (userId) mutate({ id: userId, value }); + }, + }; +} diff --git a/packages/api/src/users/router.ts b/packages/api/src/users/router.ts index fa38ec81..65b3d9b6 100644 --- a/packages/api/src/users/router.ts +++ b/packages/api/src/users/router.ts @@ -66,9 +66,34 @@ const onboardProcedure = publicProcedure } }); +const setShowSuitableDishesOnlyProcedure = publicProcedure + .input(z.object({ id: z.string(), value: z.boolean() })) + .mutation(async ({ ctx: { db }, input }) => { + const result = await db + .update(users) + .set({ + showSuitableDishesOnly: input.value, + updatedAt: new Date(), + }) + .where(eq(users.id, input.id)) + .returning() + .catch((e) => { + console.error(e); + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "error updating user setting", + }); + }); + + if (result.length === 0) + throw new TRPCError({ code: "NOT_FOUND", message: "user not found" }); + }); + export const userRouter = createTRPCRouter({ get: getUserProcedure, upsert: upsertUserProcedure, onboard: onboardProcedure, + /** Save whether the user only wants to see dishes that suit their preferences/allergies */ + setShowSuitableDishesOnly: setShowSuitableDishesOnlyProcedure, getUserRating: getUserRatingProcedure, }); diff --git a/packages/db/migrations/0016_peterplate.sql b/packages/db/migrations/0016_peterplate.sql new file mode 100644 index 00000000..af2e0175 --- /dev/null +++ b/packages/db/migrations/0016_peterplate.sql @@ -0,0 +1 @@ +ALTER TABLE "users" ADD COLUMN IF NOT EXISTS "showSuitableDishesOnly" boolean DEFAULT false NOT NULL; \ No newline at end of file diff --git a/packages/db/migrations/meta/0016_snapshot.json b/packages/db/migrations/meta/0016_snapshot.json new file mode 100644 index 00000000..b1b18621 --- /dev/null +++ b/packages/db/migrations/meta/0016_snapshot.json @@ -0,0 +1,1274 @@ +{ + "id": "0c935942-b191-43cb-8e71-ccbf082b4e42", + "prevId": "e4298415-61cc-40c9-a8d6-02e1534fb7c3", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.contributors": { + "name": "contributors", + "schema": "", + "columns": { + "login": { + "name": "login", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contributions": { + "name": "contributions", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bio": { + "name": "bio", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'PeterPlate Contributor'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.diet_restrictions": { + "name": "diet_restrictions", + "schema": "", + "columns": { + "dish_id": { + "name": "dish_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "contains_eggs": { + "name": "contains_eggs", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "contains_fish": { + "name": "contains_fish", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "contains_milk": { + "name": "contains_milk", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "contains_peanuts": { + "name": "contains_peanuts", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "contains_sesame": { + "name": "contains_sesame", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "contains_shellfish": { + "name": "contains_shellfish", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "contains_soy": { + "name": "contains_soy", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "contains_tree_nuts": { + "name": "contains_tree_nuts", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "contains_wheat": { + "name": "contains_wheat", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "is_gluten_free": { + "name": "is_gluten_free", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "is_halal": { + "name": "is_halal", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "is_kosher": { + "name": "is_kosher", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "is_locally_grown": { + "name": "is_locally_grown", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "is_organic": { + "name": "is_organic", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "is_vegan": { + "name": "is_vegan", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "is_vegetarian": { + "name": "is_vegetarian", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "diet_restrictions_dish_id_dishes_id_fk": { + "name": "diet_restrictions_dish_id_dishes_id_fk", + "tableFrom": "diet_restrictions", + "tableTo": "dishes", + "columnsFrom": [ + "dish_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dishes": { + "name": "dishes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "num_ratings": { + "name": "num_ratings", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_rating": { + "name": "total_rating", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.favorites": { + "name": "favorites", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "dish_id": { + "name": "dish_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "restaurant": { + "name": "restaurant", + "type": "restaurant_id_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "favorites_user_id_users_id_fk": { + "name": "favorites_user_id_users_id_fk", + "tableFrom": "favorites", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "favorites_dish_id_dishes_id_fk": { + "name": "favorites_dish_id_dishes_id_fk", + "tableFrom": "favorites", + "tableTo": "dishes", + "columnsFrom": [ + "dish_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "favorites_pk": { + "name": "favorites_pk", + "columns": [ + "user_id", + "dish_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.logged_meals": { + "name": "logged_meals", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "dish_id": { + "name": "dish_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "servings": { + "name": "servings", + "type": "real", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "eaten_at": { + "name": "eaten_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "logged_meals_user_id_users_id_fk": { + "name": "logged_meals_user_id_users_id_fk", + "tableFrom": "logged_meals", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "logged_meals_dish_id_dishes_id_fk": { + "name": "logged_meals_dish_id_dishes_id_fk", + "tableFrom": "logged_meals", + "tableTo": "dishes", + "columnsFrom": [ + "dish_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "servings_is_valid": { + "name": "servings_is_valid", + "value": "((\"logged_meals\".\"servings\" * 2) = floor(\"logged_meals\".\"servings\" * 2)) AND (\"logged_meals\".\"servings\" >= 0.5)" + } + }, + "isRLSEnabled": false + }, + "public.push_tokens": { + "name": "push_tokens", + "schema": "", + "columns": { + "token": { + "name": "token", + "type": "text", + "primaryKey": true, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.push_subscriptions": { + "name": "push_subscriptions", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "endpoint": { + "name": "endpoint", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "p256dh": { + "name": "p256dh", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "auth": { + "name": "auth", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_subscribed_food_favorites": { + "name": "is_subscribed_food_favorites", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_subscribed_events": { + "name": "is_subscribed_events", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": {}, + "foreignKeys": { + "push_subscriptions_user_id_users_id_fk": { + "name": "push_subscriptions_user_id_users_id_fk", + "tableFrom": "push_subscriptions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "push_subscriptions_endpoint_unique": { + "name": "push_subscriptions_endpoint_unique", + "nullsNotDistinct": false, + "columns": [ + "endpoint" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ratings": { + "name": "ratings", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "dish_id": { + "name": "dish_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rating": { + "name": "rating", + "type": "real", + "primaryKey": false, + "notNull": true + }, + "restaurant": { + "name": "restaurant", + "type": "restaurant_id_enum", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "ratings_user_id_users_id_fk": { + "name": "ratings_user_id_users_id_fk", + "tableFrom": "ratings", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "ratings_dish_id_dishes_id_fk": { + "name": "ratings_dish_id_dishes_id_fk", + "tableFrom": "ratings", + "tableTo": "dishes", + "columnsFrom": [ + "dish_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "ratings_pk": { + "name": "ratings_pk", + "columns": [ + "user_id", + "dish_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_notifications": { + "name": "saved_notifications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "notification_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "is_read": { + "name": "is_read", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "saved_notifications_user_id_users_id_fk": { + "name": "saved_notifications_user_id_users_id_fk", + "tableFrom": "saved_notifications", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "emailVerified": { + "name": "emailVerified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "hasOnboarded": { + "name": "hasOnboarded", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "showSuitableDishesOnly": { + "name": "showSuitableDishesOnly", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.account": { + "name": "account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "accountId": { + "name": "accountId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "providerId": { + "name": "providerId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "accessToken": { + "name": "accessToken", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refreshToken": { + "name": "refreshToken", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "idToken": { + "name": "idToken", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "accessTokenExpiresAt": { + "name": "accessTokenExpiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "refreshTokenExpiresAt": { + "name": "refreshTokenExpiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "account_userId_users_id_fk": { + "name": "account_userId_users_id_fk", + "tableFrom": "account", + "tableTo": "users", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.session": { + "name": "session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "expiresAt": { + "name": "expiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "ipAddress": { + "name": "ipAddress", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "userAgent": { + "name": "userAgent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "session_userId_users_id_fk": { + "name": "session_userId_users_id_fk", + "tableFrom": "session", + "tableTo": "users", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "session_token_unique": { + "name": "session_token_unique", + "nullsNotDistinct": false, + "columns": [ + "token" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.verification": { + "name": "verification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expiresAt": { + "name": "expiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_allergies": { + "name": "user_allergies", + "schema": "", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "allergy": { + "name": "allergy", + "type": "allergy", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "user_allergies_userId_users_id_fk": { + "name": "user_allergies_userId_users_id_fk", + "tableFrom": "user_allergies", + "tableTo": "users", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "user_allergies_userId_allergy_pk": { + "name": "user_allergies_userId_allergy_pk", + "columns": [ + "userId", + "allergy" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_dietary_preferences": { + "name": "user_dietary_preferences", + "schema": "", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "preference": { + "name": "preference", + "type": "preference", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "user_dietary_preferences_userId_users_id_fk": { + "name": "user_dietary_preferences_userId_users_id_fk", + "tableFrom": "user_dietary_preferences", + "tableTo": "users", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": { + "user_dietary_preferences_userId_preference_pk": { + "name": "user_dietary_preferences_userId_preference_pk", + "columns": [ + "userId", + "preference" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_goals": { + "name": "user_goals", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "calorie_goal": { + "name": "calorie_goal", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 2000 + }, + "protein_goal": { + "name": "protein_goal", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 100 + }, + "carb_goal": { + "name": "carb_goal", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 250 + }, + "fat_goal": { + "name": "fat_goal", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 50 + } + }, + "indexes": {}, + "foreignKeys": { + "user_goals_user_id_users_id_fk": { + "name": "user_goals_user_id_users_id_fk", + "tableFrom": "user_goals", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_goals_by_day": { + "name": "user_goals_by_day", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "calorie_goal": { + "name": "calorie_goal", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 2000 + }, + "protein_goal": { + "name": "protein_goal", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 100 + }, + "carb_goal": { + "name": "carb_goal", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 250 + }, + "fat_goal": { + "name": "fat_goal", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 50 + } + }, + "indexes": {}, + "foreignKeys": { + "user_goals_by_day_user_id_users_id_fk": { + "name": "user_goals_by_day_user_id_users_id_fk", + "tableFrom": "user_goals_by_day", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "user_goals_by_day_user_id_date_pk": { + "name": "user_goals_by_day_user_id_date_pk", + "columns": [ + "user_id", + "date" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.restaurant_id_enum": { + "name": "restaurant_id_enum", + "schema": "public", + "values": [ + "anteatery", + "brandywine" + ] + }, + "public.restaurant_name_enum": { + "name": "restaurant_name_enum", + "schema": "public", + "values": [ + "anteatery", + "brandywine" + ] + }, + "public.notification_type": { + "name": "notification_type", + "schema": "public", + "values": [ + "food", + "event" + ] + }, + "public.allergy": { + "name": "allergy", + "schema": "public", + "values": [ + "eggs", + "fish", + "milk", + "peanuts", + "sesame", + "shellfish", + "soy", + "treeNuts", + "wheat" + ] + }, + "public.preference": { + "name": "preference", + "schema": "public", + "values": [ + "glutenFree", + "halal", + "kosher", + "locallyGrown", + "organic", + "vegan", + "vegetarian" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/db/migrations/meta/_journal.json b/packages/db/migrations/meta/_journal.json index f72c5201..d62b3db5 100644 --- a/packages/db/migrations/meta/_journal.json +++ b/packages/db/migrations/meta/_journal.json @@ -113,6 +113,13 @@ "when": 1779221557656, "tag": "0015_peterplate", "breakpoints": true + }, + { + "idx": 16, + "version": "7", + "when": 1794791473215, + "tag": "0016_peterplate", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/db/src/schema/users.ts b/packages/db/src/schema/users.ts index a9aa481a..4b13494c 100644 --- a/packages/db/src/schema/users.ts +++ b/packages/db/src/schema/users.ts @@ -14,6 +14,9 @@ export const users = pgTable("users", { email: text("email").notNull().unique(), emailVerified: boolean("emailVerified").notNull().default(false), hasOnboarded: boolean("hasOnboarded").default(false).notNull(), + showSuitableDishesOnly: boolean("showSuitableDishesOnly") + .default(false) + .notNull(), image: text("image"), ...metadataColumns, });