diff --git a/src/app/api/footerlinks/route.ts b/src/app/api/footerlinks/route.ts index 6edde635..8730c501 100644 --- a/src/app/api/footerlinks/route.ts +++ b/src/app/api/footerlinks/route.ts @@ -7,9 +7,9 @@ export async function GET(req: NextRequest) { const hubId = req.nextUrl.searchParams.get("hubId"); try { let items; - if (hubId && !Number.isNaN(hubId)) { + if (hubId) { items = await db.query.footerLinks.findMany({ - where: eq(footerLinks.hubId, Number(hubId)), + where: eq(footerLinks.hubId, hubId), }); } else { items = await db.query.footerLinks.findMany(); diff --git a/src/app/api/hubs/route.ts b/src/app/api/hubs/route.ts index 7cbc93b1..ca5225e2 100644 --- a/src/app/api/hubs/route.ts +++ b/src/app/api/hubs/route.ts @@ -7,9 +7,9 @@ export async function GET(req: NextRequest) { const hubId = req.nextUrl.searchParams.get("hubId"); try { let items; - if (hubId && !Number.isNaN(hubId)) { + if (hubId) { items = await db.query.hubs.findFirst({ - where: eq(hubs.id, Number(hubId)), + where: eq(hubs.id, hubId), }); } return NextResponse.json(items); diff --git a/src/app/api/hubspaces/[id]/route.ts b/src/app/api/hubspaces/[id]/route.ts index cb270bac..496e6145 100644 --- a/src/app/api/hubspaces/[id]/route.ts +++ b/src/app/api/hubspaces/[id]/route.ts @@ -3,20 +3,6 @@ import { hubSpaces } from "@/lib/schema/app"; import { eq } from "drizzle-orm"; import { NextRequest, NextResponse } from "next/server"; -// export async function GET( -// req: NextRequest, -// context: { params: { id: string } } -// ) { -// try { -// const item = await db.query.hubs.findFirst({ -// where: eq(hubs.id, Number(context.params.id)), -// }); -// return NextResponse.json(item); -// } catch (error) { -// return NextResponse.json({ error }); -// } -// } - export async function PATCH( req: NextRequest, context: { params: { id: string } } @@ -26,7 +12,7 @@ export async function PATCH( const item = await db .update(hubSpaces) .set(body) - .where(eq(hubSpaces.id, Number(context.params.id))); + .where(eq(hubSpaces.id, context.params.id)); return NextResponse.json(item); } catch (error) { return NextResponse.json({ error }); @@ -40,7 +26,7 @@ export async function DELETE( try { const item = await db .delete(hubSpaces) - .where(eq(hubSpaces.id, Number(context.params.id))); + .where(eq(hubSpaces.id, context.params.id)); return NextResponse.json(item); } catch (error) { return NextResponse.json({ error }); diff --git a/src/app/api/linkgroups/route.ts b/src/app/api/linkgroups/route.ts index 7f8967d0..8693c902 100644 --- a/src/app/api/linkgroups/route.ts +++ b/src/app/api/linkgroups/route.ts @@ -7,9 +7,9 @@ export async function GET(req: NextRequest) { const hubId = req.nextUrl.searchParams.get("hubId"); try { let items; - if (hubId && !Number.isNaN(hubId)) { + if (hubId) { items = await db.query.linkGroups.findMany({ - where: eq(linkGroups.hubId, Number(hubId)), + where: eq(linkGroups.hubId, hubId), }); } else { items = await db.query.linkGroups.findMany(); diff --git a/src/app/api/links/route.ts b/src/app/api/links/route.ts index e233e2da..51f9035c 100644 --- a/src/app/api/links/route.ts +++ b/src/app/api/links/route.ts @@ -7,9 +7,9 @@ export async function GET(req: NextRequest) { const hubId = req.nextUrl.searchParams.get("hubId"); try { let items; - if (hubId && !Number.isNaN(hubId)) { + if (hubId) { items = await db.query.links.findMany({ - where: eq(links.hubId, Number(hubId)), + where: eq(links.hubId, hubId), }); } else { items = await db.query.links.findMany(); diff --git a/src/components/app/link-add-card/link-add-card.tsx b/src/components/app/link-add-card/link-add-card.tsx index 2aa74fa2..88996cb1 100644 --- a/src/components/app/link-add-card/link-add-card.tsx +++ b/src/components/app/link-add-card/link-add-card.tsx @@ -11,7 +11,7 @@ export function LinkAddCard({ hubId, linkGroupId, }: { - hubId: number; + hubId: string; linkGroupId: number; }) { const [opened, setOpened] = useState(false); diff --git a/src/components/app/link-group-add-card/link-group-add-card.tsx b/src/components/app/link-group-add-card/link-group-add-card.tsx index ed087aa8..6e619364 100644 --- a/src/components/app/link-group-add-card/link-group-add-card.tsx +++ b/src/components/app/link-group-add-card/link-group-add-card.tsx @@ -6,7 +6,7 @@ import { IconPlus } from "@tabler/icons-react"; import { motion } from "framer-motion"; import { useState } from "react"; -export function LinkGroupAddCard({ hubId }: { hubId: number }) { +export function LinkGroupAddCard({ hubId }: { hubId: string }) { const [opened, setOpened] = useState(false); return ( diff --git a/src/lib/Store/index.ts b/src/lib/Store/index.ts index d653908a..0a55107b 100644 --- a/src/lib/Store/index.ts +++ b/src/lib/Store/index.ts @@ -3,14 +3,14 @@ import { create } from "zustand"; type Settings = { editMode: boolean; compactMode: boolean; - hubId: number | null; - hubSpaceId: number | null; + hubId: string | null; + hubSpaceId: string | null; createModalOpened: boolean; }; type Actions = { setEditMode: (editMode: boolean) => void; setCompactMode: (compactMode: boolean) => void; - setHubId: (hubId: number) => void; + setHubId: (hubId: string) => void; setCreateModalOpened: (createModalOpened: boolean) => void; }; export const useHubOneStore = create((set) => ({ diff --git a/src/lib/schema/app.ts b/src/lib/schema/app.ts index 1260562e..cf28ea0c 100644 --- a/src/lib/schema/app.ts +++ b/src/lib/schema/app.ts @@ -66,20 +66,20 @@ export const links = mysqlTable("links", { link: varchar("link", { length: 256 }).notNull(), isInternal: boolean("is_internal").default(false).notNull(), linkGroupId: int("link_group_id"), - hubId: int("hub_id").notNull(), + hubId: varchar("hub_id", { length: 128 }).notNull(), }); export const footerLinks = mysqlTable("footer_links", { id: serial("id").primaryKey().notNull(), title: varchar("title", { length: 256 }).notNull(), link: varchar("link", { length: 256 }).notNull(), - hubId: int("hub_id").notNull(), + hubId: varchar("hub_id", { length: 128 }).notNull(), }); export const linkGroups = mysqlTable("link_groups", { id: serial("id").primaryKey().notNull(), title: varchar("title", { length: 256 }).notNull(), - hubId: int("hub_id").notNull(), + hubId: varchar("hub_id", { length: 128 }).notNull(), }); export const hubsRelations = relations(hubs, ({ one, many }) => ({ diff --git a/src/lib/useQueries.ts b/src/lib/useQueries.ts index dfd494df..4b1df501 100644 --- a/src/lib/useQueries.ts +++ b/src/lib/useQueries.ts @@ -7,7 +7,7 @@ export const API_URL = `${process.env.NEXT_PUBLIC_SERVER_BASE_URL || ""}/api/`; async function simpleFetchByHubId( QUERY_NAME: string, - hubId: number + hubId: string ): Promise { const res = await fetch(`${API_URL}${QUERY_NAME}?hubId=${hubId}`, { headers: { @@ -24,7 +24,7 @@ async function simpleFetchByHubId( export function useFetchByHubId( QUERY_NAME: string, - hubId: number, + hubId: string, config?: Partial<{ enabled: boolean; onSuccess: (data: T[]) => void; @@ -40,7 +40,7 @@ export function useFetchByHubId( export function useFetchItem( QUERY_NAME: string, - itemId: number, + itemId: number | string, config?: Partial<{ onSuccess: (data: T) => void; initialData: T }> ) { return useQuery( @@ -128,7 +128,9 @@ export function usePost(QUERY_NAME: string) { return mutate; } -export function useUpdate(QUERY_NAME: string) { +export function useUpdate( + QUERY_NAME: string +) { const queryClient = useQueryClient(); const { mutate } = useMutation( (newItem: T) => diff --git a/src/modals/hub-modals/hub-create-modal/hub-create-modal.tsx b/src/modals/hub-modals/hub-create-modal/hub-create-modal.tsx index 5880c906..f118e91c 100644 --- a/src/modals/hub-modals/hub-create-modal/hub-create-modal.tsx +++ b/src/modals/hub-modals/hub-create-modal/hub-create-modal.tsx @@ -21,7 +21,7 @@ export function HubCreateModal({ description: "Tired of keeping track of new websites? Tired of having to update your bookmarks every few weeks? Access all sites from this one page. Everything is up to date. No need to clutter your life anymore!", hubSpaceId, - } as Hub, + } as unknown as Hub, }); const mutate = usePost("hubs"); diff --git a/src/modals/hub-modals/hub-edit-modal/footer-link-add-card.tsx b/src/modals/hub-modals/hub-edit-modal/footer-link-add-card.tsx index cd58bbc2..8ce166d5 100644 --- a/src/modals/hub-modals/hub-edit-modal/footer-link-add-card.tsx +++ b/src/modals/hub-modals/hub-edit-modal/footer-link-add-card.tsx @@ -7,7 +7,7 @@ import { IconPlus } from "@tabler/icons-react"; import { motion } from "framer-motion"; import classes from "./footer-link-add-card.module.css"; -export function FooterLinkAddCard({ hubId }: { hubId: number }) { +export function FooterLinkAddCard({ hubId }: { hubId: string }) { const mutate = usePost("footerlinks"); const handleSubmit = () => { mutate({ hubId, title: "change me", link: "/" } as FooterLink); diff --git a/src/modals/hub-modals/hub-edit-modal/hub-edit-modal.tsx b/src/modals/hub-modals/hub-edit-modal/hub-edit-modal.tsx index 90e23ee3..7f891163 100644 --- a/src/modals/hub-modals/hub-edit-modal/hub-edit-modal.tsx +++ b/src/modals/hub-modals/hub-edit-modal/hub-edit-modal.tsx @@ -81,7 +81,7 @@ export function HubEditModal({ hubId={footerLink.hubId} /> ))} - + diff --git a/src/modals/link-group-modal/link-group-add-modal.tsx b/src/modals/link-group-modal/link-group-add-modal.tsx index 29ca8194..5245ed6a 100644 --- a/src/modals/link-group-modal/link-group-add-modal.tsx +++ b/src/modals/link-group-modal/link-group-add-modal.tsx @@ -13,13 +13,13 @@ export function AddLinkGroupModal({ }: { opened: boolean; setOpened: (open: boolean) => void; - hubId: number; + hubId: string; }) { const form = useForm({ initialValues: { title: "", hubId, - } as LinkGroup, + } as unknown as LinkGroup, }); const mutate = usePost("linkgroups"); const handleSubmit = (values: LinkGroup) => { diff --git a/src/sections/app/link-section/link-group-grid/link-group-grid.tsx b/src/sections/app/link-section/link-group-grid/link-group-grid.tsx index 3bc1d593..541f1ffb 100644 --- a/src/sections/app/link-section/link-group-grid/link-group-grid.tsx +++ b/src/sections/app/link-section/link-group-grid/link-group-grid.tsx @@ -16,7 +16,7 @@ export function LinkGroupGrid({ linkGroupId, }: { links: Link[]; - hubId: number; + hubId: string; linkGroupId: number; }) { const editMode = useHubOneStore((state) => state.editMode);