From f05cf857262226fd11306ca3da035b20ccbb9548 Mon Sep 17 00:00:00 2001 From: Markus Moltke Date: Thu, 18 Jul 2024 23:02:08 +0200 Subject: [PATCH] :sparkles: feat: upgrade to cheaper gpt-4o-mini model and updated deps --- biome.json | 3 +- commitlint.config.ts | 2 +- middleware.ts | 2 +- next-i18next.config.js | 2 +- package.json | 4 +- pages/_app.tsx | 8 +- pages/about.tsx | 4 +- pages/api/_recipeImage.ts | 6 +- pages/api/auth/[...nextauth].ts | 4 +- pages/api/cleanup.ts | 2 +- pages/api/database/cuisine/index.ts | 2 +- pages/api/database/cuisine/search.ts | 2 +- pages/api/database/fridge/index.tsx | 6 +- pages/api/database/ingredient/index.ts | 4 +- pages/api/database/ingredient/search.ts | 2 +- pages/api/database/mealplan/[id].ts | 4 +- pages/api/database/mealplan/index.ts | 4 +- pages/api/database/mealplan/own.ts | 6 +- pages/api/database/recipe/[id]/index.ts | 4 +- .../api/database/recipe/[id]/rating/index.ts | 2 +- pages/api/database/recipe/[id]/rating/own.ts | 6 +- pages/api/database/recipe/image.ts | 4 +- pages/api/database/recipe/index.ts | 9 +- pages/api/database/recipe/popular.ts | 2 +- pages/api/database/recipe/random.ts | 4 +- pages/api/database/recipe/search/image.ts | 2 +- pages/api/database/recipe/search/index.ts | 4 +- pages/api/database/recipe/structured-data.ts | 12 +- pages/api/database/user/[id]/follow.ts | 4 +- pages/api/database/user/[id]/index.ts | 2 +- pages/api/database/user/image.ts | 4 +- pages/auth/signin.tsx | 4 +- pages/auth/signout.tsx | 2 +- pages/feed.tsx | 2 +- pages/fridge.tsx | 15 +- pages/index.tsx | 8 +- pages/meal-plan.tsx | 386 +++++++++--------- pages/policies/privacy.tsx | 2 +- pages/policies/terms.tsx | 2 +- pages/recipe/[recipeId].tsx | 74 ++-- pages/recipe/create.tsx | 8 +- pages/recipe/recipes-sitemap.xml.tsx | 4 +- pages/recipes.tsx | 14 +- pages/settings.tsx | 8 +- pages/user/[id].tsx | 13 +- pages/user/users-sitemap.xml.tsx | 4 +- scripts/translate-site.mts | 12 +- src/components/Account/AccountBox.tsx | 2 +- src/components/Account/AccountUpdateBox.tsx | 4 +- src/components/Account/TabPanel.tsx | 2 +- src/components/AnalyticsWrapper.tsx | 2 +- src/components/Explore/ExploreRow.tsx | 4 +- src/components/Explore/RecipeBox.tsx | 4 +- .../Explore/Search/GridSkeletonBox.tsx | 2 +- .../Explore/Search/SearchResults.tsx | 15 +- src/components/Explore/SkeletonRecipeBox.tsx | 2 +- src/components/Footer/Flag.tsx | 2 +- src/components/Footer/index.tsx | 2 +- src/components/General/YKTextField/index.tsx | 4 +- src/components/Header/index.tsx | 3 +- src/components/Link.tsx | 4 +- src/components/MealPlan/MealCell.tsx | 7 +- src/components/MealPlan/MealPicker.tsx | 94 +++-- src/components/MealPlan/WeekPicker.tsx | 10 +- .../Recipe/CuisineAutocomplete/index.tsx | 10 +- src/components/Recipe/ImageSelect/index.tsx | 10 +- .../Recipe/MealTypeSelect/index.tsx | 4 +- .../Recipe/PreparationTimePicker/index.tsx | 4 +- src/components/Recipe/RecipeRating/index.tsx | 6 +- .../Recipe/RecipeTypeSelect/index.tsx | 4 +- .../StepsTextField/CreateIngredientDialog.tsx | 8 +- .../StepsTextField/FullSearchDialog.tsx | 10 +- .../Recipe/StepsTextField/UnitDialog.tsx | 2 +- .../Recipe/StepsTextField/index.tsx | 9 +- src/components/Recipe/YKChip.tsx | 4 +- src/misc/createEmotionCache.ts | 2 +- src/misc/theme.ts | 2 +- src/models/meal.ts | 2 +- src/utils/index.ts | 2 +- src/utils/meaplanHelper.ts | 12 +- src/utils/validator.ts | 2 +- tsconfig.json | 44 +- types/next-auth.d.ts | 2 +- types/next-seo.d.ts | 4 +- 84 files changed, 501 insertions(+), 489 deletions(-) diff --git a/biome.json b/biome.json index 94c5e2b..9bb8a7d 100644 --- a/biome.json +++ b/biome.json @@ -20,7 +20,8 @@ "recommended": true, "suspicious": { "noExplicitAny": "off", - "noAsyncPromiseExecutor": "off" + "noAsyncPromiseExecutor": "off", + "noArrayIndexKey": "off" } } }, diff --git a/commitlint.config.ts b/commitlint.config.ts index e663aa0..a6650a4 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -1,4 +1,4 @@ -import { UserConfig } from '@commitlint/types' +import type { UserConfig } from '@commitlint/types' const config: UserConfig = { extends: ['@commitlint/config-conventional'], diff --git a/middleware.ts b/middleware.ts index dae9325..da10621 100644 --- a/middleware.ts +++ b/middleware.ts @@ -1,5 +1,5 @@ import acceptLanguage from 'accept-language' -import { NextRequest, NextResponse } from 'next/server' +import { type NextRequest, NextResponse } from 'next/server' acceptLanguage.languages(['en', 'da']) diff --git a/next-i18next.config.js b/next-i18next.config.js index a507532..372bb82 100644 --- a/next-i18next.config.js +++ b/next-i18next.config.js @@ -14,6 +14,6 @@ module.exports = { /** To avoid issues when deploying to some paas (vercel...) */ localePath: typeof window === 'undefined' - ? require('path').resolve('./public/locales') + ? require('node:path').resolve('./public/locales') : '/locales', } diff --git a/package.json b/package.json index 862f152..0cabee7 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "postbuild": "next-sitemap", "postinstall": "prisma generate", "start": "node build/standalone/server.js", - "lint": "biome format --write --no-errors-on-unmatched . && biome lint --apply --no-errors-on-unmatched .", + "lint": "biome format --write --no-errors-on-unmatched . && biome lint --write --no-errors-on-unmatched .", "prisma:update": "prisma format && prisma generate && prisma db push", "analyze": "cross-env ANALYZE=true next build", "prepare": "husky install", @@ -20,7 +20,7 @@ }, "lint-staged": { "*.{js,jsx,ts,tsx}": "biome format --write --no-errors-on-unmatched", - "*.{js,jsx,ts,tsx|json}": "biome lint --apply --no-errors-on-unmatched" + "*.{js,jsx,ts,tsx|json}": "biome lint --write --no-errors-on-unmatched" }, "dependencies": { "@auth/prisma-adapter": "^2.4.1", diff --git a/pages/_app.tsx b/pages/_app.tsx index 50e14e1..e9c1ff6 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -4,17 +4,17 @@ import { Header } from '#components/Header' import createEmotionCache from '#misc/createEmotionCache' import theme, { darkTheme } from '#misc/theme' import { api } from '#network/index' -import { CacheProvider, EmotionCache } from '@emotion/react' +import { CacheProvider, type EmotionCache } from '@emotion/react' import { Box, useMediaQuery } from '@mui/material' import CssBaseline from '@mui/material/CssBaseline' import { ThemeProvider } from '@mui/material/styles' import { initGA } from 'green-analytics-js' -import { Session } from 'next-auth' +import type { Session } from 'next-auth' import { SessionProvider } from 'next-auth/react' import { appWithTranslation } from 'next-i18next' import { NextSeo } from 'next-seo' -import { AppProps } from 'next/app' -import { FC, useEffect, useMemo } from 'react' +import type { AppProps } from 'next/app' +import { type FC, useEffect, useMemo } from 'react' import { Toaster, toast } from 'sonner' import { SWRConfig } from 'swr' diff --git a/pages/about.tsx b/pages/about.tsx index 9a2d0ba..7f634fd 100644 --- a/pages/about.tsx +++ b/pages/about.tsx @@ -1,7 +1,7 @@ -import { GetStaticProps } from 'next' +import type { GetStaticProps } from 'next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { NextSeo } from 'next-seo' -import { FC } from 'react' +import type { FC } from 'react' /** * About page for YourKitchen, describing the project. diff --git a/pages/api/_recipeImage.ts b/pages/api/_recipeImage.ts index ad3bc41..8f41ffa 100644 --- a/pages/api/_recipeImage.ts +++ b/pages/api/_recipeImage.ts @@ -1,7 +1,7 @@ import { - ErrorResponse, - Photo, - PhotosWithTotalResults, + type ErrorResponse, + type Photo, + type PhotosWithTotalResults, createClient, } from 'pexels' diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts index 9a89841..cbc013e 100644 --- a/pages/api/auth/[...nextauth].ts +++ b/pages/api/auth/[...nextauth].ts @@ -1,7 +1,7 @@ import { PrismaAdapter } from '@auth/prisma-adapter' -import { PrismaClient, User } from '@prisma/client' +import { PrismaClient, type User } from '@prisma/client' import { JsonValue } from '@prisma/client/runtime/library' -import NextAuth, { AuthOptions, Session } from 'next-auth' +import NextAuth, { type AuthOptions, type Session } from 'next-auth' import AppleProvider from 'next-auth/providers/apple' import EmailProvider from 'next-auth/providers/email' import FacebookProvider from 'next-auth/providers/facebook' diff --git a/pages/api/cleanup.ts b/pages/api/cleanup.ts index b8a8f15..97c2640 100644 --- a/pages/api/cleanup.ts +++ b/pages/api/cleanup.ts @@ -1,5 +1,5 @@ import { DateTime } from 'luxon' -import { NextApiRequest, NextApiResponse } from 'next' +import type { NextApiRequest, NextApiResponse } from 'next' import prisma from './_base' const handler = async (req: NextApiRequest, res: NextApiResponse) => { diff --git a/pages/api/database/cuisine/index.ts b/pages/api/database/cuisine/index.ts index ddd028c..a8aac54 100644 --- a/pages/api/database/cuisine/index.ts +++ b/pages/api/database/cuisine/index.ts @@ -1,6 +1,6 @@ import prisma from '#pages/api/_base' import { authOptions } from '#pages/api/auth/[...nextauth]' -import { NextApiRequest, NextApiResponse } from 'next' +import type { NextApiRequest, NextApiResponse } from 'next' import { getServerSession } from 'next-auth' export const handler = async (req: NextApiRequest, res: NextApiResponse) => { diff --git a/pages/api/database/cuisine/search.ts b/pages/api/database/cuisine/search.ts index 81aa96e..acc75a3 100644 --- a/pages/api/database/cuisine/search.ts +++ b/pages/api/database/cuisine/search.ts @@ -1,4 +1,4 @@ -import { NextApiRequest, NextApiResponse } from 'next' +import type { NextApiRequest, NextApiResponse } from 'next' import prisma from '#pages/api/_base' export const handler = async (req: NextApiRequest, res: NextApiResponse) => { diff --git a/pages/api/database/fridge/index.tsx b/pages/api/database/fridge/index.tsx index ccfd0ef..7db6188 100644 --- a/pages/api/database/fridge/index.tsx +++ b/pages/api/database/fridge/index.tsx @@ -1,8 +1,8 @@ import prisma from '#pages/api/_base' import { authOptions } from '#pages/api/auth/[...nextauth]' -import { FridgeIngredient } from '@prisma/client' -import { NextApiRequest, NextApiResponse } from 'next' -import { Session, getServerSession } from 'next-auth' +import type { FridgeIngredient } from '@prisma/client' +import type { NextApiRequest, NextApiResponse } from 'next' +import { type Session, getServerSession } from 'next-auth' const handler = async (req: NextApiRequest, res: NextApiResponse) => { try { diff --git a/pages/api/database/ingredient/index.ts b/pages/api/database/ingredient/index.ts index 564b24a..36a2efd 100644 --- a/pages/api/database/ingredient/index.ts +++ b/pages/api/database/ingredient/index.ts @@ -1,5 +1,5 @@ -import { Ingredient, Recipe } from '@prisma/client' -import { NextApiRequest, NextApiResponse } from 'next' +import { type Ingredient, Recipe } from '@prisma/client' +import type { NextApiRequest, NextApiResponse } from 'next' import { getServerSession } from 'next-auth' import { ApiError } from 'next/dist/server/api-utils' import { getIngredientId } from 'src/utils' diff --git a/pages/api/database/ingredient/search.ts b/pages/api/database/ingredient/search.ts index 36eaee2..d2173f0 100644 --- a/pages/api/database/ingredient/search.ts +++ b/pages/api/database/ingredient/search.ts @@ -1,4 +1,4 @@ -import { NextApiRequest, NextApiResponse } from 'next' +import type { NextApiRequest, NextApiResponse } from 'next' import prisma from '#pages/api/_base' export const handler = async (req: NextApiRequest, res: NextApiResponse) => { diff --git a/pages/api/database/mealplan/[id].ts b/pages/api/database/mealplan/[id].ts index affc048..81d4af7 100644 --- a/pages/api/database/mealplan/[id].ts +++ b/pages/api/database/mealplan/[id].ts @@ -2,8 +2,8 @@ import prisma from '#pages/api/_base' import { authOptions } from '#pages/api/auth/[...nextauth]' import { updateMealplan } from '#utils/meaplanHelper' import { DateTime } from 'luxon' -import { NextApiRequest, NextApiResponse } from 'next' -import { Session, getServerSession } from 'next-auth' +import type { NextApiRequest, NextApiResponse } from 'next' +import { type Session, getServerSession } from 'next-auth' const handler = async (req: NextApiRequest, res: NextApiResponse) => { const session = await getServerSession(req, res, authOptions) diff --git a/pages/api/database/mealplan/index.ts b/pages/api/database/mealplan/index.ts index bee7598..63d5f9f 100644 --- a/pages/api/database/mealplan/index.ts +++ b/pages/api/database/mealplan/index.ts @@ -1,7 +1,7 @@ import prisma from '#pages/api/_base' import { authOptions } from '#pages/api/auth/[...nextauth]' -import { NextApiRequest, NextApiResponse } from 'next' -import { Session, getServerSession } from 'next-auth' +import type { NextApiRequest, NextApiResponse } from 'next' +import { type Session, getServerSession } from 'next-auth' const handler = async (req: NextApiRequest, res: NextApiResponse) => { const session = await getServerSession(req, res, authOptions) diff --git a/pages/api/database/mealplan/own.ts b/pages/api/database/mealplan/own.ts index 1e59381..2a5b06f 100644 --- a/pages/api/database/mealplan/own.ts +++ b/pages/api/database/mealplan/own.ts @@ -1,10 +1,10 @@ import prisma from '#pages/api/_base' import { authOptions } from '#pages/api/auth/[...nextauth]' import { sameDate, updateMealplan } from '#utils/meaplanHelper' -import { MealPlanRecipe } from '@prisma/client' +import type { MealPlanRecipe } from '@prisma/client' import { DateTime } from 'luxon' -import { NextApiRequest, NextApiResponse } from 'next' -import { Session, getServerSession } from 'next-auth' +import type { NextApiRequest, NextApiResponse } from 'next' +import { type Session, getServerSession } from 'next-auth' const handler = async (req: NextApiRequest, res: NextApiResponse) => { const session = await getServerSession(req, res, authOptions) diff --git a/pages/api/database/recipe/[id]/index.ts b/pages/api/database/recipe/[id]/index.ts index ead768a..0bec625 100644 --- a/pages/api/database/recipe/[id]/index.ts +++ b/pages/api/database/recipe/[id]/index.ts @@ -1,7 +1,7 @@ import prisma from '#pages/api/_base' import { authOptions } from '#pages/api/auth/[...nextauth]' -import { Recipe, RecipeImage } from '@prisma/client' -import { NextApiRequest, NextApiResponse } from 'next' +import type { Recipe, RecipeImage } from '@prisma/client' +import type { NextApiRequest, NextApiResponse } from 'next' import { getServerSession } from 'next-auth' const handler = async (req: NextApiRequest, res: NextApiResponse) => { diff --git a/pages/api/database/recipe/[id]/rating/index.ts b/pages/api/database/recipe/[id]/rating/index.ts index 5dc0816..28dda68 100644 --- a/pages/api/database/recipe/[id]/rating/index.ts +++ b/pages/api/database/recipe/[id]/rating/index.ts @@ -1,5 +1,5 @@ import prisma from '#pages/api/_base' -import { NextApiRequest, NextApiResponse } from 'next' +import type { NextApiRequest, NextApiResponse } from 'next' const handler = async (req: NextApiRequest, res: NextApiResponse) => { try { diff --git a/pages/api/database/recipe/[id]/rating/own.ts b/pages/api/database/recipe/[id]/rating/own.ts index 324f9e1..faaf366 100644 --- a/pages/api/database/recipe/[id]/rating/own.ts +++ b/pages/api/database/recipe/[id]/rating/own.ts @@ -1,8 +1,8 @@ import prisma from '#pages/api/_base' import { authOptions } from '#pages/api/auth/[...nextauth]' -import { Rating } from '@prisma/client' -import { NextApiRequest, NextApiResponse } from 'next' -import { Session, getServerSession } from 'next-auth' +import type { Rating } from '@prisma/client' +import type { NextApiRequest, NextApiResponse } from 'next' +import { type Session, getServerSession } from 'next-auth' const handler = async (req: NextApiRequest, res: NextApiResponse) => { try { diff --git a/pages/api/database/recipe/image.ts b/pages/api/database/recipe/image.ts index 70fe816..a1d9b31 100644 --- a/pages/api/database/recipe/image.ts +++ b/pages/api/database/recipe/image.ts @@ -1,7 +1,7 @@ import { authOptions } from '#pages/api/auth/[...nextauth]' import { put } from '@vercel/blob' -import { NextApiRequest, NextApiResponse } from 'next' -import { Session, getServerSession } from 'next-auth' +import type { NextApiRequest, NextApiResponse } from 'next' +import { type Session, getServerSession } from 'next-auth' const handler = async (req: NextApiRequest, res: NextApiResponse) => { try { diff --git a/pages/api/database/recipe/index.ts b/pages/api/database/recipe/index.ts index 34e4795..290c8cb 100644 --- a/pages/api/database/recipe/index.ts +++ b/pages/api/database/recipe/index.ts @@ -1,5 +1,10 @@ -import { MealType, Prisma, Recipe, RecipeImage } from '@prisma/client' -import { NextApiRequest, NextApiResponse } from 'next' +import { + type MealType, + Prisma, + type Recipe, + type RecipeImage, +} from '@prisma/client' +import type { NextApiRequest, NextApiResponse } from 'next' import { getServerSession } from 'next-auth' import { ApiError } from 'next/dist/server/api-utils' import { authOptions } from '#pages/api/auth/[...nextauth]' diff --git a/pages/api/database/recipe/popular.ts b/pages/api/database/recipe/popular.ts index 3cadd63..c73a77a 100644 --- a/pages/api/database/recipe/popular.ts +++ b/pages/api/database/recipe/popular.ts @@ -1,5 +1,5 @@ import { DateTime } from 'luxon' -import { NextApiRequest, NextApiResponse } from 'next' +import type { NextApiRequest, NextApiResponse } from 'next' import { NextRequest, NextResponse } from 'next/server' import prisma from '#pages/api/_base' diff --git a/pages/api/database/recipe/random.ts b/pages/api/database/recipe/random.ts index 54b7bfc..a3cd4ab 100644 --- a/pages/api/database/recipe/random.ts +++ b/pages/api/database/recipe/random.ts @@ -2,9 +2,9 @@ import { api } from '#network/index' import prisma from '#pages/api/_base' import { getRecipeImage } from '#pages/api/_recipeImage' import randomSchema from '#utils/random_schema.json' -import { RecipeImage } from '@prisma/client' +import type { RecipeImage } from '@prisma/client' import { put } from '@vercel/blob' -import { NextApiRequest, NextApiResponse } from 'next' +import type { NextApiRequest, NextApiResponse } from 'next' import { OpenAI } from 'openai' import { ValidationError, validateContent } from 'src/utils/validator' import { v4 } from 'uuid' diff --git a/pages/api/database/recipe/search/image.ts b/pages/api/database/recipe/search/image.ts index f39e990..c6fd44c 100644 --- a/pages/api/database/recipe/search/image.ts +++ b/pages/api/database/recipe/search/image.ts @@ -1,5 +1,5 @@ import { Cuisine, MealType } from '@prisma/client' -import { NextApiRequest, NextApiResponse } from 'next' +import type { NextApiRequest, NextApiResponse } from 'next' import prisma from '#pages/api/_base' import { getRecipeImage } from '#pages/api/_recipeImage' diff --git a/pages/api/database/recipe/search/index.ts b/pages/api/database/recipe/search/index.ts index c13edaf..3855d90 100644 --- a/pages/api/database/recipe/search/index.ts +++ b/pages/api/database/recipe/search/index.ts @@ -1,5 +1,5 @@ -import { Cuisine, MealType } from '@prisma/client' -import { NextApiRequest, NextApiResponse } from 'next' +import type { Cuisine, MealType } from '@prisma/client' +import type { NextApiRequest, NextApiResponse } from 'next' import prisma from '#pages/api/_base' export const handler = async (req: NextApiRequest, res: NextApiResponse) => { diff --git a/pages/api/database/recipe/structured-data.ts b/pages/api/database/recipe/structured-data.ts index 367632d..f320272 100644 --- a/pages/api/database/recipe/structured-data.ts +++ b/pages/api/database/recipe/structured-data.ts @@ -1,16 +1,16 @@ import { - MealType, - Recipe, - RecipeImage, + type MealType, + type Recipe, + type RecipeImage, RecipeIngredient, - RecipeType, + type RecipeType, } from '@prisma/client' import axios from 'axios' import { parseHTML } from 'html-recipe-parser' import { IRecipe } from 'html-recipe-parser/dist/interfaces' import { DateTime } from 'luxon' -import { NextApiRequest, NextApiResponse } from 'next' -import { Session, getServerSession } from 'next-auth' +import type { NextApiRequest, NextApiResponse } from 'next' +import { type Session, getServerSession } from 'next-auth' import { RecipeJsonLdProps } from 'next-seo' import { NextRequest, NextResponse } from 'next/server' import { v4 } from 'uuid' diff --git a/pages/api/database/user/[id]/follow.ts b/pages/api/database/user/[id]/follow.ts index 73dd898..cbb5613 100644 --- a/pages/api/database/user/[id]/follow.ts +++ b/pages/api/database/user/[id]/follow.ts @@ -1,7 +1,7 @@ import prisma from '#pages/api/_base' import { authOptions } from '#pages/api/auth/[...nextauth]' -import { NextApiRequest, NextApiResponse } from 'next' -import { Session, getServerSession } from 'next-auth' +import type { NextApiRequest, NextApiResponse } from 'next' +import { type Session, getServerSession } from 'next-auth' const handler = async (req: NextApiRequest, res: NextApiResponse) => { try { diff --git a/pages/api/database/user/[id]/index.ts b/pages/api/database/user/[id]/index.ts index b01485e..1e6d29d 100644 --- a/pages/api/database/user/[id]/index.ts +++ b/pages/api/database/user/[id]/index.ts @@ -1,5 +1,5 @@ import prisma from '#pages/api/_base' -import { NextApiRequest, NextApiResponse } from 'next' +import type { NextApiRequest, NextApiResponse } from 'next' const handler = async (req: NextApiRequest, res: NextApiResponse) => { try { diff --git a/pages/api/database/user/image.ts b/pages/api/database/user/image.ts index 1b935c4..e2fcd3f 100644 --- a/pages/api/database/user/image.ts +++ b/pages/api/database/user/image.ts @@ -1,6 +1,6 @@ import { put } from '@vercel/blob' -import { NextApiRequest, NextApiResponse } from 'next' -import { Session, getServerSession } from 'next-auth' +import type { NextApiRequest, NextApiResponse } from 'next' +import { type Session, getServerSession } from 'next-auth' import { authOptions } from '#pages/api/auth/[...nextauth]' const handler = async (req: NextApiRequest, res: NextApiResponse) => { diff --git a/pages/auth/signin.tsx b/pages/auth/signin.tsx index ecd3b07..e9748a9 100644 --- a/pages/auth/signin.tsx +++ b/pages/auth/signin.tsx @@ -1,12 +1,12 @@ import { Facebook, Google } from '@mui/icons-material' import { Box, Button, TextField, Typography } from '@mui/material' -import { GetStaticProps } from 'next' +import type { GetStaticProps } from 'next' import { signIn, useSession } from 'next-auth/react' import { useTranslation } from 'next-i18next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { NextSeo } from 'next-seo' import { useRouter as useNavigation, useSearchParams } from 'next/navigation' -import { FC, useEffect, useState } from 'react' +import { type FC, useEffect, useState } from 'react' import { toast } from 'sonner' export const SigninPage: FC = () => { diff --git a/pages/auth/signout.tsx b/pages/auth/signout.tsx index f0608b0..0469270 100644 --- a/pages/auth/signout.tsx +++ b/pages/auth/signout.tsx @@ -1,6 +1,6 @@ import { signOut } from 'next-auth/react' import { useRouter as useNavigation } from 'next/navigation' -import React, { FC, useEffect } from 'react' +import React, { type FC, useEffect } from 'react' import { toast } from 'sonner' const SignoutPage: FC = () => { diff --git a/pages/feed.tsx b/pages/feed.tsx index 4e006ea..247b658 100644 --- a/pages/feed.tsx +++ b/pages/feed.tsx @@ -1,4 +1,4 @@ -import { GetStaticProps } from 'next' +import type { GetStaticProps } from 'next' import { useSession } from 'next-auth/react' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import React from 'react' diff --git a/pages/fridge.tsx b/pages/fridge.tsx index 8a27daa..8b44c7c 100644 --- a/pages/fridge.tsx +++ b/pages/fridge.tsx @@ -1,10 +1,10 @@ import CreateIngredientDialog from '#components/Recipe/StepsTextField/CreateIngredientDialog' -import { YKResponse } from '#models/ykResponse' +import type { YKResponse } from '#models/ykResponse' import { api } from '#network/index' import { validUnits } from '#utils/validator' import { Autocomplete, - AutocompleteRenderInputParams, + type AutocompleteRenderInputParams, Box, Button, Dialog, @@ -21,9 +21,14 @@ import { Typography, debounce, } from '@mui/material' -import { Fridge, FridgeIngredient, Ingredient, Unit } from '@prisma/client' +import { + type Fridge, + type FridgeIngredient, + type Ingredient, + Unit, +} from '@prisma/client' import { useSession } from 'next-auth/react' -import React, { FC, useMemo, useState } from 'react' +import React, { type FC, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { toast } from 'sonner' import useSWR from 'swr' @@ -262,6 +267,7 @@ const FridgePage: FC = () => { const ingredient = fridgeIngredient.ingredient return ( { const ingredient = fridgeIngredient.ingredient return ( { const { t } = useTranslation('common') diff --git a/pages/meal-plan.tsx b/pages/meal-plan.tsx index 09d9e69..95e381a 100644 --- a/pages/meal-plan.tsx +++ b/pages/meal-plan.tsx @@ -1,7 +1,7 @@ import MealCell from '#components/MealPlan/MealCell' import MealPicker from '#components/MealPlan/MealPicker' import { WeekPicker } from '#components/MealPlan/WeekPicker' -import { Meal } from '#models/meal' +import type { Meal } from '#models/meal' import { sameDate } from '#utils/meaplanHelper' import { Box, @@ -12,14 +12,14 @@ import { Select, Typography, } from '@mui/material' -import { MealPlan, MealType, User } from '@prisma/client' +import { type MealPlan, MealType, type User } from '@prisma/client' import { DateTime } from 'luxon' -import { GetServerSideProps, InferGetServerSidePropsType } from 'next' +import type { GetServerSideProps, InferGetServerSidePropsType } from 'next' import { useSession } from 'next-auth/react' import { useTranslation } from 'next-i18next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { NextSeo } from 'next-seo' -import { FC, useCallback, useEffect, useMemo, useState } from 'react' +import { type FC, useCallback, useEffect, useMemo, useState } from 'react' import useSWR from 'swr' const daysOfWeek = [ @@ -32,86 +32,100 @@ const daysOfWeek = [ 'sunday', ] -const MealPlanPage: FC> = - () => { - // Translations - const { t } = useTranslation('common') +const MealPlanPage: FC< + InferGetServerSidePropsType +> = () => { + // Translations + const { t } = useTranslation('common') - useSession({ - required: true, - }) + useSession({ + required: true, + }) - // States - const [selectedMealPlanId, setSelectedMealPlanId] = useState('own') - const [selectedWeekDate, setSelectedWeekDate] = useState(DateTime.utc()) - const [editMealPosition, setEditMealPosition] = useState<{ - date: DateTime - meal: MealType - }>() + // States + const [selectedMealPlanId, setSelectedMealPlanId] = useState('own') + const [selectedWeekDate, setSelectedWeekDate] = useState(DateTime.utc()) + const [editMealPosition, setEditMealPosition] = useState<{ + date: DateTime + meal: MealType + }>() - // Data - const { data: allMealPlans } = - useSWR<(MealPlan & { owner: User })[]>('mealplan') - const { - data: selectedMealPlan, - mutate: updateMealPlan, - isLoading: mealPlanLoading, - } = useSWR< - MealPlan & { - // Not really meal, just matches the type. - // It merely contains a list of all the MealPlanRecipes in the meal plan. - recipes: Meal - } - >({ - url: `mealplan/${selectedMealPlanId}`, - weekDate: selectedWeekDate.toISO(), - }) + // Data + const { data: allMealPlans } = + useSWR<(MealPlan & { owner: User })[]>('mealplan') + const { + data: selectedMealPlan, + mutate: updateMealPlan, + isLoading: mealPlanLoading, + } = useSWR< + MealPlan & { + // Not really meal, just matches the type. + // It merely contains a list of all the MealPlanRecipes in the meal plan. + recipes: Meal + } + >({ + url: `mealplan/${selectedMealPlanId}`, + weekDate: selectedWeekDate.toISO(), + }) - useEffect(() => { - if (allMealPlans && allMealPlans.length > 0) { - setSelectedMealPlanId(allMealPlans[0].id) - } - }, [allMealPlans]) + useEffect(() => { + if (allMealPlans && allMealPlans.length > 0) { + setSelectedMealPlanId(allMealPlans[0].id) + } + }, [allMealPlans]) - const getMeal = useCallback( - (date: DateTime, meal: MealType): Meal => { - if (!selectedMealPlan) { - return [] - } - return selectedMealPlan.recipes - .filter( - (recipe) => - sameDate(date, DateTime.fromISO(recipe.date as any as string)) && - recipe.mealType === meal, - ) - .sort((recipe) => (recipe.recipeType === 'MAIN' ? -1 : 1)) - }, - [selectedMealPlan], - ) + const getMeal = useCallback( + (date: DateTime, meal: MealType): Meal => { + if (!selectedMealPlan) { + return [] + } + return selectedMealPlan.recipes + .filter( + (recipe) => + sameDate(date, DateTime.fromISO(recipe.date as any as string)) && + recipe.mealType === meal, + ) + .sort((recipe) => (recipe.recipeType === 'MAIN' ? -1 : 1)) + }, + [selectedMealPlan], + ) - const datesOfWeek = useMemo(() => { - let currentDateTime = selectedWeekDate.startOf('week') + const datesOfWeek = useMemo(() => { + let currentDateTime = selectedWeekDate.startOf('week') - const dates: DateTime[] = [] - for (let i = 0; i < 7; i++) { - dates.push(currentDateTime) + const dates: DateTime[] = [] + for (let i = 0; i < 7; i++) { + dates.push(currentDateTime) - currentDateTime = currentDateTime.plus({ - day: 1, - }) - } + currentDateTime = currentDateTime.plus({ + day: 1, + }) + } - return dates - }, [selectedWeekDate]) + return dates + }, [selectedWeekDate]) - return ( - - - {mealPlanLoading ? ( + return ( + + + {mealPlanLoading ? ( + + + + ) : ( + <> > = mx: 6, }} > - - - ) : ( - <> - + + setSelectedWeekDate(dateTime ?? DateTime.utc()) + } + buttonProps={{ + variant: 'contained', + }} + t={t} + /> + {/* Meal plan selection */} + - - - setSelectedWeekDate(dateTime ?? DateTime.utc()) - } - buttonProps={{ - variant: 'contained', - }} - t={t} - /> - {/* Meal plan selection */} - {`${t('select')} ${t( + 'meal_plan', + )}`} + setSelectedMealPlanId(e.target.value)} - labelId="select-meal-plan" - label={`${t('select')} ${t('meal_plan')}`} - > - - {t('my_meal_plan')} + + {t('my_meal_plan')} + + {allMealPlans?.map((mealPlan) => ( + + {mealPlan.owner.name} - {allMealPlans?.map((mealPlan) => ( - - {mealPlan.owner.name} - - ))} - - - + ))} + + + + + {/* Representation of meal plan (Calendar view for the week) */} - {/* Representation of meal plan (Calendar view for the week) */} - - {t('meal')} - - {[MealType.BREAKFAST, MealType.LUNCH, MealType.DINNER].map( - (mealType) => ( - - - {t(mealType.toLowerCase())} + {t('meal')} + + {[MealType.BREAKFAST, MealType.LUNCH, MealType.DINNER].map( + (mealType) => ( + + + {t(mealType.toLowerCase())} + + + ), + )} + {daysOfWeek.map((dayOfWeek, index) => { + const date = datesOfWeek[index] + + return ( + <> + + {date.toFormat('EEEE')} + + {date.toFormat('dd MMM')} - ), - )} - {daysOfWeek.map((_, index) => { - const date = datesOfWeek[index] - - return ( - <> - - {date.toFormat('EEEE')} - - {date.toFormat('dd MMM')} - - - {[MealType.BREAKFAST, MealType.LUNCH, MealType.DINNER].map( - (mealType) => ( - { - setEditMealPosition({ - date, - meal: mealType, - }) - }} - /> - ), - )} - - ) - })} - - - )} - - ) - } + {[MealType.BREAKFAST, MealType.LUNCH, MealType.DINNER].map( + (mealType) => ( + { + setEditMealPosition({ + date, + meal: mealType, + }) + }} + /> + ), + )} + + ) + })} + + + )} + + ) +} export const getServerSideProps: GetServerSideProps = async (context) => { const locale = context.locale diff --git a/pages/policies/privacy.tsx b/pages/policies/privacy.tsx index 0d7da43..7054da2 100644 --- a/pages/policies/privacy.tsx +++ b/pages/policies/privacy.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import type React from 'react' const PrivacyPage: React.FC = () => { return ( diff --git a/pages/policies/terms.tsx b/pages/policies/terms.tsx index cdecc0f..abe88ff 100644 --- a/pages/policies/terms.tsx +++ b/pages/policies/terms.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import type React from 'react' const TermsOfUsePage: React.FC = () => { return ( diff --git a/pages/recipe/[recipeId].tsx b/pages/recipe/[recipeId].tsx index 7b05409..7c258ab 100644 --- a/pages/recipe/[recipeId].tsx +++ b/pages/recipe/[recipeId].tsx @@ -1,10 +1,10 @@ import Link from '#components/Link' import RecipeRating from '#components/Recipe/RecipeRating' import YKChip from '#components/Recipe/YKChip' -import { YKResponse } from '#models/ykResponse' +import type { YKResponse } from '#models/ykResponse' import { api } from '#network/index' import { authOptions } from '#pages/api/auth/[...nextauth]' -import { PublicRecipe } from '#pages/recipes' +import type { PublicRecipe } from '#pages/recipes' import { ExpandLess, ExpandMore } from '@mui/icons-material' import { Box, @@ -14,21 +14,21 @@ import { ListItemText, Typography, } from '@mui/material' -import { +import type { AllergenType, Ingredient, RecipeIngredient, Unit, } from '@prisma/client' import { DateTime } from 'luxon' -import { GetServerSideProps } from 'next' -import { Session, getServerSession } from 'next-auth' -import { TFunction, useTranslation } from 'next-i18next' +import type { GetServerSideProps } from 'next' +import { type Session, getServerSession } from 'next-auth' +import { type TFunction, useTranslation } from 'next-i18next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { NextSeo, RecipeJsonLd } from 'next-seo' import Image from 'next/image' import { useRouter } from 'next/router' -import { FC, useMemo, useState } from 'react' +import { type FC, useCallback, useMemo, useState } from 'react' const SITE_URL = process.env.SITE_URL ?? 'https://yourkitchen.io' @@ -125,44 +125,45 @@ const RecipePage: FC = ({ recipe, user }) => { return allergenes.filter((allergen) => userAllergenes.includes(allergen)) }, [allergenes, user]) - const getIngredientsFromStep = ( - step: string | undefined, - ): Omit[] => { - const ingredients: Omit[] = [] + const getIngredientsFromStep = useCallback( + (step: string | undefined): Omit[] => { + const ingredients: Omit[] = [] - if (!step) { - return ingredients - } + if (!step) { + return ingredients + } - const stepSplit = step.split('!') + const stepSplit = step.split('!') - if (stepSplit.length < 2) { - // No ingredients, because there is no split - return ingredients - } + if (stepSplit.length < 2) { + // No ingredients, because there is no split + return ingredients + } - // We start at 1, because every odd number is an ingredient if formatted correctly. (Has been validated before uplaoded) - for (let i = 1; i < stepSplit.length; i += 2) { - const item = stepSplit[i] + // We start at 1, because every odd number is an ingredient if formatted correctly. (Has been validated before uplaoded) + for (let i = 1; i < stepSplit.length; i += 2) { + const item = stepSplit[i] - const colonSplit = item.split(':') + const colonSplit = item.split(':') - if (colonSplit.length !== 3) { - console.error(`Invalid split: ${item}`) - continue - } + if (colonSplit.length !== 3) { + console.error(`Invalid split: ${item}`) + continue + } - const [amount, unit, id] = colonSplit + const [amount, unit, id] = colonSplit - ingredients.push({ - amount: Number.parseFloat(amount), - unit: unit as Unit, - ingredientId: id, - }) - } + ingredients.push({ + amount: Number.parseFloat(amount), + unit: unit as Unit, + ingredientId: id, + }) + } - return ingredients - } + return ingredients + }, + [], + ) const ingredientsProgress = useMemo(() => { // Get what amount of the ingredients have been used. @@ -377,6 +378,7 @@ const RecipePage: FC = ({ recipe, user }) => { return ( {} diff --git a/pages/recipes.tsx b/pages/recipes.tsx index aeed3d1..1c8cffa 100644 --- a/pages/recipes.tsx +++ b/pages/recipes.tsx @@ -1,6 +1,6 @@ import ExploreRow from '#components/Explore/ExploreRow' import SearchResults from '#components/Explore/Search/SearchResults' -import { YKResponse } from '#models/ykResponse' +import type { YKResponse } from '#models/ykResponse' import { Box, MenuItem, @@ -10,14 +10,14 @@ import { debounce, } from '@mui/material' import { - Cuisine, + type Cuisine, MealType, - Rating, - Recipe, - RecipeImage, - User, + type Rating, + type Recipe, + type RecipeImage, + type User, } from '@prisma/client' -import { GetStaticProps } from 'next' +import type { GetStaticProps } from 'next' import { useTranslation } from 'next-i18next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { SiteLinksSearchBoxJsonLd } from 'next-seo' diff --git a/pages/settings.tsx b/pages/settings.tsx index a974423..06d66f2 100644 --- a/pages/settings.tsx +++ b/pages/settings.tsx @@ -1,16 +1,16 @@ import AccountUpdateBox from '#components/Account/AccountUpdateBox' import AccountTabPanel from '#components/Account/TabPanel' -import { YKResponse } from '#models/ykResponse' +import type { YKResponse } from '#models/ykResponse' import { api } from '#network/index' import { Box, CircularProgress, Tab, Tabs, Typography } from '@mui/material' -import { User } from '@prisma/client' -import { GetStaticProps } from 'next' +import type { User } from '@prisma/client' +import type { GetStaticProps } from 'next' import { useSession } from 'next-auth/react' import { useTranslation } from 'next-i18next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { NextSeo } from 'next-seo' import Image from 'next/image' -import { FC, useState } from 'react' +import { type FC, useState } from 'react' import { toast } from 'sonner' export enum SettingsTab { diff --git a/pages/user/[id].tsx b/pages/user/[id].tsx index 8ba1e01..d6f65c3 100644 --- a/pages/user/[id].tsx +++ b/pages/user/[id].tsx @@ -2,10 +2,10 @@ import Logo from '#assets/Logo-512x512.png' import TabPanel from '#components/Account/TabPanel' import Link from '#components/Link' import YKChip from '#components/Recipe/YKChip' -import { YKResponse } from '#models/ykResponse' +import type { YKResponse } from '#models/ykResponse' import { api } from '#network/index' import { authOptions } from '#pages/api/auth/[...nextauth]' -import { PublicRecipe } from '#pages/recipes' +import type { PublicRecipe } from '#pages/recipes' import { Box, Button, @@ -20,15 +20,15 @@ import { Tabs, Typography, } from '@mui/material' -import { FeedItem, Follows, Rating, User } from '@prisma/client' +import { type FeedItem, Follows, type Rating, type User } from '@prisma/client' import { DateTime } from 'luxon' -import { GetServerSideProps, InferGetServerSidePropsType } from 'next' -import { Session, getServerSession } from 'next-auth' +import type { GetServerSideProps, InferGetServerSidePropsType } from 'next' +import { type Session, getServerSession } from 'next-auth' import { useTranslation } from 'next-i18next' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' import { NextSeo, ProfilePageJsonLd } from 'next-seo' import Image from 'next/image' -import { FC, useCallback, useEffect, useMemo, useState } from 'react' +import { type FC, useCallback, useEffect, useMemo, useState } from 'react' import { toast } from 'sonner' type PublicUser = Pick @@ -200,6 +200,7 @@ const UserPage: FC> = ({ > {user.recipes.map((recipe) => ( {} diff --git a/scripts/translate-site.mts b/scripts/translate-site.mts index 613d467..d1a449e 100644 --- a/scripts/translate-site.mts +++ b/scripts/translate-site.mts @@ -1,8 +1,8 @@ -import { client } from '@gradio/client' -import { existsSync } from 'fs' -import { mkdir, readFile, readdir, writeFile } from 'fs/promises' -import { createRequire } from 'module' -import { dirname, resolve, sep } from 'path' +import { Client } from '@gradio/client' +import { existsSync } from 'node:fs' +import { mkdir, readFile, readdir, writeFile } from 'node:fs/promises' +import { createRequire } from 'node:module' +import { dirname, resolve, sep } from 'node:path' const require = createRequire(import.meta.url) global.EventSource = require('eventsource') @@ -28,7 +28,7 @@ const writeToFile = async (destinationPath: string, content: string) => { } const localizeTranslationFiles = async () => { - const app = await client( + const app = await Client.connect( 'https://gundeep-open-translate.hf.space/--replicas/7xrk4/', { hf_token: process.env.HF_TOKEN as `hf_${string}`, diff --git a/src/components/Account/AccountBox.tsx b/src/components/Account/AccountBox.tsx index 9bb5f25..b8e3d24 100644 --- a/src/components/Account/AccountBox.tsx +++ b/src/components/Account/AccountBox.tsx @@ -1,5 +1,5 @@ import { Box, Button, Typography } from '@mui/material' -import { FC, PropsWithChildren } from 'react' +import type { FC, PropsWithChildren } from 'react' interface AccountBoxInterface { label: string diff --git a/src/components/Account/AccountUpdateBox.tsx b/src/components/Account/AccountUpdateBox.tsx index 801e39b..eaf53f8 100644 --- a/src/components/Account/AccountUpdateBox.tsx +++ b/src/components/Account/AccountUpdateBox.tsx @@ -9,8 +9,8 @@ import { Typography, } from '@mui/material' import { AllergenType } from '@prisma/client' -import { TFunction } from 'next-i18next' -import { FC, useEffect, useMemo, useState } from 'react' +import type { TFunction } from 'next-i18next' +import { type FC, useEffect, useMemo, useState } from 'react' import { toast } from 'sonner' import { allAllergenes } from '#models/allergenes' import AccountBox from './AccountBox' diff --git a/src/components/Account/TabPanel.tsx b/src/components/Account/TabPanel.tsx index cf3b420..f19ca98 100644 --- a/src/components/Account/TabPanel.tsx +++ b/src/components/Account/TabPanel.tsx @@ -1,5 +1,5 @@ import { Box } from '@mui/material' -import React from 'react' +import type React from 'react' interface TabPanelProps { children?: React.ReactNode diff --git a/src/components/AnalyticsWrapper.tsx b/src/components/AnalyticsWrapper.tsx index c6072af..ed28204 100644 --- a/src/components/AnalyticsWrapper.tsx +++ b/src/components/AnalyticsWrapper.tsx @@ -1,6 +1,6 @@ import { setPerson } from 'green-analytics-js' import { useSession } from 'next-auth/react' -import { FC, PropsWithChildren, useEffect } from 'react' +import { type FC, type PropsWithChildren, useEffect } from 'react' const AnalyticsWrapper: FC = ({ children }) => { const { data: session, status } = useSession() diff --git a/src/components/Explore/ExploreRow.tsx b/src/components/Explore/ExploreRow.tsx index 6b10301..3a69210 100644 --- a/src/components/Explore/ExploreRow.tsx +++ b/src/components/Explore/ExploreRow.tsx @@ -1,6 +1,6 @@ import { Box } from '@mui/material' -import React, { FC } from 'react' -import { PublicRecipe } from '#pages/recipes' +import React, { type FC } from 'react' +import type { PublicRecipe } from '#pages/recipes' import RecipeBox from './RecipeBox' import SkeletonRecipeBox from './SkeletonRecipeBox' diff --git a/src/components/Explore/RecipeBox.tsx b/src/components/Explore/RecipeBox.tsx index 2de9b42..0dccee4 100644 --- a/src/components/Explore/RecipeBox.tsx +++ b/src/components/Explore/RecipeBox.tsx @@ -2,9 +2,9 @@ import { Circle, HorizontalRule, ThumbDown, ThumbUp } from '@mui/icons-material' import { Box, Chip, Typography } from '@mui/material' import { Recipe, RecipeImage } from '@prisma/client' import Image from 'next/image' -import React, { FC, useMemo } from 'react' +import React, { type FC, useMemo } from 'react' import Link from '#components/Link' -import { PublicRecipe } from '#pages/recipes' +import type { PublicRecipe } from '#pages/recipes' interface RecipeBoxProps { recipe: PublicRecipe diff --git a/src/components/Explore/Search/GridSkeletonBox.tsx b/src/components/Explore/Search/GridSkeletonBox.tsx index 1d53efa..7626496 100644 --- a/src/components/Explore/Search/GridSkeletonBox.tsx +++ b/src/components/Explore/Search/GridSkeletonBox.tsx @@ -2,7 +2,7 @@ import { Circle, HorizontalRule, ThumbDown, ThumbUp } from '@mui/icons-material' import { Box, Chip, Skeleton, Typography } from '@mui/material' import { Recipe, RecipeImage } from '@prisma/client' import Image from 'next/image' -import React, { FC, useMemo } from 'react' +import React, { type FC, useMemo } from 'react' import Link from '#components/Link' import { PublicRecipe } from '#pages/recipes' diff --git a/src/components/Explore/Search/SearchResults.tsx b/src/components/Explore/Search/SearchResults.tsx index 14a8839..d2cb526 100644 --- a/src/components/Explore/Search/SearchResults.tsx +++ b/src/components/Explore/Search/SearchResults.tsx @@ -11,18 +11,18 @@ import { Slider, debounce, } from '@mui/material' -import { Cuisine, MealType } from '@prisma/client' +import { type Cuisine, MealType } from '@prisma/client' import { useTranslation } from 'next-i18next' import React, { - FC, - MouseEvent, - PropsWithChildren, + type FC, + type MouseEvent, + type PropsWithChildren, useMemo, useState, } from 'react' import useSWR from 'swr' -import { YKResponse } from '#models/ykResponse' -import { PublicRecipe } from '#pages/recipes' +import type { YKResponse } from '#models/ykResponse' +import type { PublicRecipe } from '#pages/recipes' import RecipeBox from '../RecipeBox' import GridSkeletonRecipeBox from './GridSkeletonBox' @@ -89,6 +89,7 @@ const FilterPopper: FC> = ({ {values.map((value) => ( { handleClose() onValueSelected?.(value.value) @@ -202,6 +203,7 @@ const SearchResults: FC = ({ value, cuisines }) => { {skeletonData.map((data, index) => ( = ({ value, cuisines }) => { {searchRecipes?.data.map((recipe) => ( = (props) => { return ( diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx index 2e771be..80ea413 100644 --- a/src/components/Header/index.tsx +++ b/src/components/Header/index.tsx @@ -20,7 +20,8 @@ import { useTranslation } from 'next-i18next' import Image from 'next/image' import { useRouter as useNavigation } from 'next/navigation' import { useRouter } from 'next/router' -import React, { useCallback, useEffect, useMemo, useState } from 'react' +import type React from 'react' +import { useCallback, useEffect, useMemo, useState } from 'react' import Link from '../Link' interface Page { diff --git a/src/components/Link.tsx b/src/components/Link.tsx index f20a302..e299fbb 100644 --- a/src/components/Link.tsx +++ b/src/components/Link.tsx @@ -1,7 +1,7 @@ -import MuiLink, { LinkProps as MuiLinkProps } from '@mui/material/Link' +import MuiLink, { type LinkProps as MuiLinkProps } from '@mui/material/Link' import { styled } from '@mui/material/styles' import { clsx } from 'clsx' -import NextLink, { LinkProps as NextLinkProps } from 'next/link' +import NextLink, { type LinkProps as NextLinkProps } from 'next/link' import { useRouter } from 'next/router' import * as React from 'react' import { forwardRef } from 'react' diff --git a/src/components/MealPlan/MealCell.tsx b/src/components/MealPlan/MealCell.tsx index 55fbfb2..b2bf3a2 100644 --- a/src/components/MealPlan/MealCell.tsx +++ b/src/components/MealPlan/MealCell.tsx @@ -1,9 +1,9 @@ import { Box, Button, Typography, Rating } from '@mui/material' -import { TFunction } from 'i18next' +import type { TFunction } from 'i18next' import { Edit } from '@mui/icons-material' -import { FC } from 'react' +import type { FC } from 'react' import { YKResponse } from '#models/ykResponse' -import { Meal } from '#models/meal' +import type { Meal } from '#models/meal' import { Recipe, RecipeImage, Rating as PrismaRating } from '@prisma/client' import useSWR from 'swr' import Image from 'next/image' @@ -44,6 +44,7 @@ export const MealCell: FC = ({ t, meal, editMealRecipe }) => { )} {meal.map((mealRecipe) => ( = ({ const { data: popularRecipes, isLoading: popularLoading } = useSWR>('recipe/popular') - const updateMeal = (newRecipe: Recipe) => { - // Check that we have an update position - if (!editMealPosition) { - toast.error('No meal position defined') - return - } + const updateMeal = useCallback( + (newRecipe: Recipe) => { + // Check that we have an update position + if (!editMealPosition) { + toast.error('No meal position defined') + return + } - // Update the meal plan - toast.promise( - api.put>( - 'database/mealplan/own', - { - recipe: { - date: editMealPosition.date.toJSDate(), - mealType: editMealPosition.meal, - recipeId: newRecipe.id, - recipeType: newRecipe.recipeType, + // Update the meal plan + toast.promise( + api.put>( + 'database/mealplan/own', + { + recipe: { + date: editMealPosition.date.toJSDate(), + mealType: editMealPosition.meal, + recipeId: newRecipe.id, + recipeType: newRecipe.recipeType, + }, }, - }, - ), - { - loading: `${t('updating')} ${t('meal_plan')}`, - error: (err) => err.message ?? err, - success: (response) => { - const data = response.data.data - // Update local meal plan. + ), + { + loading: `${t('updating')} ${t('meal_plan')}`, + error: (err) => err.message ?? err, + success: (response) => { + const data = response.data.data + // Update local meal plan. - updateMealPlan(data) + updateMealPlan(data) - return `${t('succesfully')} ${t('updated')} ${t('meal_plan')}` + return `${t('succesfully')} ${t('updated')} ${t('meal_plan')}` + }, }, - }, - ) + ) - setEditMealPosition(undefined) - } + setEditMealPosition(undefined) + }, + [editMealPosition, t, setEditMealPosition, updateMealPlan], + ) const RecipeRows = useMemo(() => { if (searchRecipesLoading || popularLoading) { @@ -187,12 +197,12 @@ const MealPicker: FC = ({ // If value length is less than 2, show the popular recipes instead if (value.length < 2) { return popularRecipes?.data.map((recipe) => ( - + )) } return searchRecipes?.data.map((recipe) => ( - + )) }, [ value, diff --git a/src/components/MealPlan/WeekPicker.tsx b/src/components/MealPlan/WeekPicker.tsx index 54e7781..05eb3de 100644 --- a/src/components/MealPlan/WeekPicker.tsx +++ b/src/components/MealPlan/WeekPicker.tsx @@ -1,16 +1,16 @@ -import { Button, ButtonProps, Popper } from '@mui/material' +import { Button, type ButtonProps, Popper } from '@mui/material' import { styled } from '@mui/material/styles' import { DateCalendar, - DateCalendarProps, - PickersDayProps, + type DateCalendarProps, + type PickersDayProps, } from '@mui/x-date-pickers' import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon' import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider' import { PickersDay } from '@mui/x-date-pickers/PickersDay' import { DateTime } from 'luxon' -import { TFunction } from 'next-i18next' -import { FC, MouseEventHandler, useState } from 'react' +import type { TFunction } from 'next-i18next' +import { type FC, type MouseEventHandler, useState } from 'react' const CustomPickersDay = styled(PickersDay, { shouldForwardProp: (prop) => prop !== 'isSelected' && prop !== 'isHovered', diff --git a/src/components/Recipe/CuisineAutocomplete/index.tsx b/src/components/Recipe/CuisineAutocomplete/index.tsx index f8184e8..6d2e720 100644 --- a/src/components/Recipe/CuisineAutocomplete/index.tsx +++ b/src/components/Recipe/CuisineAutocomplete/index.tsx @@ -1,8 +1,8 @@ -import { YKResponse } from '#models/ykResponse' +import type { YKResponse } from '#models/ykResponse' import { api } from '#network/index' import { Autocomplete, - AutocompleteRenderInputParams, + type AutocompleteRenderInputParams, Button, Dialog, DialogActions, @@ -11,10 +11,10 @@ import { TextField, } from '@mui/material' import { debounce } from '@mui/material/utils' -import { Cuisine } from '@prisma/client' +import type { Cuisine } from '@prisma/client' import { useSession } from 'next-auth/react' -import { TFunction } from 'next-i18next' -import { FC, useMemo, useState } from 'react' +import type { TFunction } from 'next-i18next' +import { type FC, useMemo, useState } from 'react' import { toast } from 'sonner' import useSWR from 'swr' diff --git a/src/components/Recipe/ImageSelect/index.tsx b/src/components/Recipe/ImageSelect/index.tsx index 8194185..fd0adc1 100644 --- a/src/components/Recipe/ImageSelect/index.tsx +++ b/src/components/Recipe/ImageSelect/index.tsx @@ -1,4 +1,4 @@ -import { YKResponse } from '#models/ykResponse' +import type { YKResponse } from '#models/ykResponse' import { api } from '#network/index' import { CheckCircle, Delete } from '@mui/icons-material' import { @@ -16,12 +16,12 @@ import { Typography, debounce, } from '@mui/material' -import { RecipeImage } from '@prisma/client' +import type { RecipeImage } from '@prisma/client' import axios from 'axios' import { useSession } from 'next-auth/react' -import { TFunction } from 'next-i18next' -import { Photo } from 'pexels' -import { FC, useCallback, useEffect, useMemo, useState } from 'react' +import type { TFunction } from 'next-i18next' +import type { Photo } from 'pexels' +import { type FC, useCallback, useEffect, useMemo, useState } from 'react' import { toast } from 'sonner' import useSWR from 'swr' import { v4 } from 'uuid' diff --git a/src/components/Recipe/MealTypeSelect/index.tsx b/src/components/Recipe/MealTypeSelect/index.tsx index 18c017e..e4dc6be 100644 --- a/src/components/Recipe/MealTypeSelect/index.tsx +++ b/src/components/Recipe/MealTypeSelect/index.tsx @@ -1,8 +1,8 @@ import { FormControl, InputLabel, MenuItem, Select } from '@mui/material' import { MealType } from '@prisma/client' import { t } from 'i18next' -import { TFunction } from 'next-i18next' -import React, { FC } from 'react' +import type { TFunction } from 'next-i18next' +import React, { type FC } from 'react' interface MealTypeSelectProps { t: TFunction diff --git a/src/components/Recipe/PreparationTimePicker/index.tsx b/src/components/Recipe/PreparationTimePicker/index.tsx index bbcaee9..85a6edd 100644 --- a/src/components/Recipe/PreparationTimePicker/index.tsx +++ b/src/components/Recipe/PreparationTimePicker/index.tsx @@ -2,8 +2,8 @@ import { LocalizationProvider, TimePicker } from '@mui/x-date-pickers' import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon' import { t } from 'i18next' import { DateTime } from 'luxon' -import { TFunction } from 'next-i18next' -import React, { FC, useMemo } from 'react' +import type { TFunction } from 'next-i18next' +import React, { type FC, useMemo } from 'react' interface PreparationTimePickerProps { t: TFunction diff --git a/src/components/Recipe/RecipeRating/index.tsx b/src/components/Recipe/RecipeRating/index.tsx index 2fef67a..b73a9c4 100644 --- a/src/components/Recipe/RecipeRating/index.tsx +++ b/src/components/Recipe/RecipeRating/index.tsx @@ -12,12 +12,12 @@ import { Rating as MuiRating, TextField, } from '@mui/material' -import { Rating, Recipe } from '@prisma/client' +import type { Rating, Recipe } from '@prisma/client' import { useSession } from 'next-auth/react' -import { TFunction } from 'next-i18next' +import type { TFunction } from 'next-i18next' import { useRouter as useNavigation } from 'next/navigation' import { useRouter } from 'next/router' -import { FC, useEffect, useState } from 'react' +import { type FC, useEffect, useState } from 'react' import { toast } from 'sonner' import useSWR from 'swr' diff --git a/src/components/Recipe/RecipeTypeSelect/index.tsx b/src/components/Recipe/RecipeTypeSelect/index.tsx index e282529..6fb7306 100644 --- a/src/components/Recipe/RecipeTypeSelect/index.tsx +++ b/src/components/Recipe/RecipeTypeSelect/index.tsx @@ -1,8 +1,8 @@ import { FormControl, InputLabel, MenuItem, Select } from '@mui/material' import { RecipeType } from '@prisma/client' import { t } from 'i18next' -import { TFunction } from 'next-i18next' -import React, { FC } from 'react' +import type { TFunction } from 'next-i18next' +import React, { type FC } from 'react' interface RecipeTypeSelectProps { t: TFunction diff --git a/src/components/Recipe/StepsTextField/CreateIngredientDialog.tsx b/src/components/Recipe/StepsTextField/CreateIngredientDialog.tsx index 08e2a5c..fdee867 100644 --- a/src/components/Recipe/StepsTextField/CreateIngredientDialog.tsx +++ b/src/components/Recipe/StepsTextField/CreateIngredientDialog.tsx @@ -10,12 +10,12 @@ import { Select, TextField, } from '@mui/material' -import { AllergenType, Ingredient } from '@prisma/client' -import { TFunction } from 'next-i18next' -import React, { FC, useState } from 'react' +import type { AllergenType, Ingredient } from '@prisma/client' +import type { TFunction } from 'next-i18next' +import React, { type FC, useState } from 'react' import { toast } from 'sonner' import { allAllergenes } from '#models/allergenes' -import { YKResponse } from '#models/ykResponse' +import type { YKResponse } from '#models/ykResponse' import { api } from '#network/index' interface CreateIngredientDialogProps { diff --git a/src/components/Recipe/StepsTextField/FullSearchDialog.tsx b/src/components/Recipe/StepsTextField/FullSearchDialog.tsx index e069569..9950358 100644 --- a/src/components/Recipe/StepsTextField/FullSearchDialog.tsx +++ b/src/components/Recipe/StepsTextField/FullSearchDialog.tsx @@ -1,6 +1,6 @@ import { Autocomplete, - AutocompleteRenderInputParams, + type AutocompleteRenderInputParams, Button, Dialog, DialogActions, @@ -9,14 +9,14 @@ import { TextField, debounce, } from '@mui/material' -import { Ingredient } from '@prisma/client' +import type { Ingredient } from '@prisma/client' import { t } from 'i18next' import { useSession } from 'next-auth/react' -import { TFunction } from 'next-i18next' -import React, { FC, useMemo, useState } from 'react' +import type { TFunction } from 'next-i18next' +import React, { type FC, useMemo, useState } from 'react' import { toast } from 'sonner' import useSWR from 'swr' -import { YKResponse } from '#models/ykResponse' +import type { YKResponse } from '#models/ykResponse' interface FullSearchDialogProps { t: TFunction diff --git a/src/components/Recipe/StepsTextField/UnitDialog.tsx b/src/components/Recipe/StepsTextField/UnitDialog.tsx index 31f781d..73bb571 100644 --- a/src/components/Recipe/StepsTextField/UnitDialog.tsx +++ b/src/components/Recipe/StepsTextField/UnitDialog.tsx @@ -1,4 +1,4 @@ -import React, { FC } from 'react' +import React, { type FC } from 'react' const UnitDialog: FC = () => { return
UnitDialog
diff --git a/src/components/Recipe/StepsTextField/index.tsx b/src/components/Recipe/StepsTextField/index.tsx index 82f9b90..034e41d 100644 --- a/src/components/Recipe/StepsTextField/index.tsx +++ b/src/components/Recipe/StepsTextField/index.tsx @@ -1,5 +1,5 @@ import { allUnits } from '#models/units' -import { YKResponse } from '#models/ykResponse' +import type { YKResponse } from '#models/ykResponse' import { ArrowForward, Delete, Search } from '@mui/icons-material' import { Box, @@ -14,9 +14,10 @@ import { } from '@mui/material' import Chip from '@mui/material/Chip' import TextField from '@mui/material/TextField' -import { Ingredient, RecipeIngredient, Unit } from '@prisma/client' -import { TFunction } from 'next-i18next' -import React, { FC, useMemo, useRef, useState } from 'react' +import type { Ingredient, RecipeIngredient, Unit } from '@prisma/client' +import type { TFunction } from 'next-i18next' +import type React from 'react' +import { type FC, useMemo, useRef, useState } from 'react' import { toast } from 'sonner' import { getIngredientId } from 'src/utils' import useSWR from 'swr' diff --git a/src/components/Recipe/YKChip.tsx b/src/components/Recipe/YKChip.tsx index aa2367e..8bee759 100644 --- a/src/components/Recipe/YKChip.tsx +++ b/src/components/Recipe/YKChip.tsx @@ -1,5 +1,5 @@ -import { Chip, ChipProps } from '@mui/material' -import React, { FC } from 'react' +import { Chip, type ChipProps } from '@mui/material' +import React, { type FC } from 'react' const YKChip: FC = (props) => { return diff --git a/src/misc/createEmotionCache.ts b/src/misc/createEmotionCache.ts index ab6eceb..0ca3acd 100644 --- a/src/misc/createEmotionCache.ts +++ b/src/misc/createEmotionCache.ts @@ -1,4 +1,4 @@ -import createCache, { EmotionCache } from '@emotion/cache' +import createCache, { type EmotionCache } from '@emotion/cache' const isBrowser = typeof document !== 'undefined' diff --git a/src/misc/theme.ts b/src/misc/theme.ts index 2194f99..e55bc65 100644 --- a/src/misc/theme.ts +++ b/src/misc/theme.ts @@ -1,5 +1,5 @@ import { red } from '@mui/material/colors' -import { ThemeOptions, createTheme } from '@mui/material/styles' +import { type ThemeOptions, createTheme } from '@mui/material/styles' import { Cabin } from 'next/font/google' export const roboto = Cabin({ diff --git a/src/models/meal.ts b/src/models/meal.ts index 1bc63d5..ef21746 100644 --- a/src/models/meal.ts +++ b/src/models/meal.ts @@ -1,4 +1,4 @@ -import { +import type { MealPlanRecipe, Recipe, RecipeImage, diff --git a/src/utils/index.ts b/src/utils/index.ts index 80d214f..c83e093 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,4 +1,4 @@ -import { RecipeIngredient, Unit } from '@prisma/client' +import type { RecipeIngredient, Unit } from '@prisma/client' export const toTitleCase = () => {} diff --git a/src/utils/meaplanHelper.ts b/src/utils/meaplanHelper.ts index 96c2199..83a5da6 100644 --- a/src/utils/meaplanHelper.ts +++ b/src/utils/meaplanHelper.ts @@ -1,13 +1,13 @@ import prisma from '#pages/api/_base' import { - MealPlan, - MealPlanRecipe, + type MealPlan, + type MealPlanRecipe, MealType, - Rating, - Recipe, - RecipeImage, + type Rating, + type Recipe, + type RecipeImage, RecipeType, - User, + type User, } from '@prisma/client' import { DateTime } from 'luxon' import { v4 } from 'uuid' diff --git a/src/utils/validator.ts b/src/utils/validator.ts index 2f34322..886076b 100644 --- a/src/utils/validator.ts +++ b/src/utils/validator.ts @@ -1,4 +1,4 @@ -import { AllergenType, Recipe, RecipeType, Unit } from '@prisma/client' +import type { AllergenType, Recipe, RecipeType, Unit } from '@prisma/client' import { getIngredientId } from '.' import { extract, token_set_ratio } from 'fuzzball' diff --git a/tsconfig.json b/tsconfig.json index 3a22f62..941985b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,11 +2,7 @@ "compilerOptions": { "baseUrl": ".", "target": "es2022", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], + "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "strict": true, @@ -21,30 +17,14 @@ "jsx": "preserve", "incremental": true, "paths": { - "#assets/*": [ - "./src/assets/*" - ], - "#components/*": [ - "./src/components/*" - ], - "#pages/*": [ - "./pages/*" - ], - "#models/*": [ - "./src/models/*" - ], - "#contexts/*": [ - "./src/contexts/*" - ], - "#network/*": [ - "./src/network/*" - ], - "#utils/*": [ - "./src/utils/*" - ], - "#misc/*": [ - "./src/misc/*" - ] + "#assets/*": ["./src/assets/*"], + "#components/*": ["./src/components/*"], + "#pages/*": ["./pages/*"], + "#models/*": ["./src/models/*"], + "#contexts/*": ["./src/contexts/*"], + "#network/*": ["./src/network/*"], + "#utils/*": ["./src/utils/*"], + "#misc/*": ["./src/misc/*"] } }, "include": [ @@ -53,7 +33,5 @@ "**/*.tsx", "scripts/translate-site.mts" ], - "exclude": [ - "node_modules" - ] -} \ No newline at end of file + "exclude": ["node_modules"] +} diff --git a/types/next-auth.d.ts b/types/next-auth.d.ts index 75c5cc5..3d40811 100644 --- a/types/next-auth.d.ts +++ b/types/next-auth.d.ts @@ -1,4 +1,4 @@ -import { User } from '@prisma/client' +import type { User } from '@prisma/client' import NextAuth, { DefaultSession } from 'next-auth' declare module 'next-auth' { diff --git a/types/next-seo.d.ts b/types/next-seo.d.ts index 4713c00..27b823c 100644 --- a/types/next-seo.d.ts +++ b/types/next-seo.d.ts @@ -1,5 +1,5 @@ -import { BreadCrumbJsonLdProps } from 'next-seo' -import { JsonLdProps } from 'next-seo/lib/jsonld/jsonld' +import type { BreadCrumbJsonLdProps } from 'next-seo' +import type { JsonLdProps } from 'next-seo/lib/jsonld/jsonld' declare module 'next-seo' { type Part = any