From 3430184f1e3d41243db5c5f1ec259a49974e20d2 Mon Sep 17 00:00:00 2001 From: Goostaf Date: Mon, 26 Aug 2024 23:56:38 +0200 Subject: [PATCH 01/16] Add schema and service --- prisma/schema.prisma | 19 ++++++++ src/services/navService.ts | 93 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 src/services/navService.ts diff --git a/prisma/schema.prisma b/prisma/schema.prisma index fc18af50..53c685d8 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -145,3 +145,22 @@ enum SponsorType { PARTNER MAIN_PARTNER } + +model NavbarCategory { + id Int @id @default(autoincrement()) + priority Int @default(0) + nameSv String + nameEn String + url String + NavbarItem NavbarItem[] +} + +model NavbarItem { + id Int @id @default(autoincrement()) + priority Int @default(0) + nameSv String + nameEn String + url String + category NavbarCategory @relation(fields: [categoryId], references: [id]) + categoryId Int +} diff --git a/src/services/navService.ts b/src/services/navService.ts new file mode 100644 index 00000000..ad5faea2 --- /dev/null +++ b/src/services/navService.ts @@ -0,0 +1,93 @@ +import prisma from '@/prisma'; + +export default class NavService { + static async get() { + return await prisma.navbarCategory.findMany({ + include: { + NavbarItem: true + } + }); + } + + static async addCategory(nameEn: string, nameSv: string, priority?: number) { + return await prisma.navbarCategory.create({ + data: { + nameEn, + nameSv, + priority + } + }); + } + + static async addItem( + categoryId: number, + nameEn: string, + nameSv: string, + url: string, + priority?: number + ) { + return await prisma.navbarItem.create({ + data: { + nameEn, + nameSv, + url, + priority, + categoryId + } + }); + } + + static async removeCategory(id: number) { + return await prisma.navbarCategory.delete({ + where: { + id + } + }); + } + + static async removeItem(id: number) { + return await prisma.navbarItem.delete({ + where: { + id + } + }); + } + + static async updateCategory( + id: number, + nameEn: string, + nameSv: string, + priority?: number + ) { + return await prisma.navbarCategory.update({ + where: { + id + }, + data: { + nameEn, + nameSv, + priority + } + }); + } + + static async updateItem( + id: number, + nameEn: string, + nameSv: string, + url: string, + priority?: number + ) { + return await prisma.navbarItem.update({ + where: { + id + }, + data: { + nameEn, + nameSv, + url, + priority + } + }); + } +} From 3ecfe35f2c0f6d120e71e21499bff978619a5006 Mon Sep 17 00:00:00 2001 From: Goostaf Date: Tue, 27 Aug 2024 00:10:35 +0200 Subject: [PATCH 02/16] Render nav URLs from database --- src/components/Header/Header.tsx | 5 +++- .../Header/Navigation/Navigation.tsx | 28 ++++++++++++++++++- .../Header/SearchSwitcher/SearchSwitcher.tsx | 7 ++--- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 956c971c..0fc73e91 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -18,7 +18,10 @@ const Header = ({ locale }: { locale: string }) => {
- + } + > diff --git a/src/components/Header/Navigation/Navigation.tsx b/src/components/Header/Navigation/Navigation.tsx index 2c2ecfd1..24b11895 100644 --- a/src/components/Header/Navigation/Navigation.tsx +++ b/src/components/Header/Navigation/Navigation.tsx @@ -3,6 +3,7 @@ import styles from './Navigation.module.scss'; import Link from 'next/link'; import DropdownLink from './DropdownLink/DropdownLink'; import i18nService from '@/services/i18nService'; +import NavService from '@/services/navService'; const playfair = Playfair_Display({ subsets: ['latin'], weight: '800' }); @@ -11,13 +12,38 @@ type Props = { desktop?: boolean; }; -const Navigation = ({ locale, desktop }: Props) => { +const Navigation = async ({ locale, desktop }: Props) => { const l = i18nService.getLocale(locale); const c = desktop ? styles.desktopDropdown : undefined; const navStyle = desktop ? styles.nav : `${styles.nav} ${styles.navMobile}`; + const items = await NavService.get(); return (