diff --git a/next.config.mjs b/next.config.mjs index 6c84806..a0affe9 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -8,7 +8,7 @@ const nextConfig = { reactCompiler: true, ppr: "incremental", }, - serverExternalPackages: ["typeorm", "better-sqlite3"], + serverExternalPackages: ["better-sqlite3"], reactStrictMode: true, output: "standalone", images: { diff --git a/src/app/(root)/manage/page.tsx b/src/app/(root)/manage/page.tsx new file mode 100644 index 0000000..bd635c1 --- /dev/null +++ b/src/app/(root)/manage/page.tsx @@ -0,0 +1,14 @@ +import { TRPCProvider } from "@/trpc/client"; +import RefreshImageDb from "@/components/refresh-image-db"; +import { trpc } from "@/trpc/server"; + +export default async function Photos(): Promise { + const imageCount = await trpc.photos.count(); + return ( +
+ + + +
+ ); +} diff --git a/src/app/(root)/photos/page.tsx b/src/app/(root)/photos/page.tsx index 81101cf..15bcc59 100644 --- a/src/app/(root)/photos/page.tsx +++ b/src/app/(root)/photos/page.tsx @@ -9,22 +9,7 @@ export default async function Photos(): Promise { return (
- - {images.map((image) => ( - {image.src} - ))} - +
); diff --git a/src/components/footer.tsx b/src/components/footer.tsx index 5bed3ba..79f3e36 100644 --- a/src/components/footer.tsx +++ b/src/components/footer.tsx @@ -3,7 +3,7 @@ export default function NavBar(): React.JSX.Element {
- © Joe Monk 2024 + © Joe Monk 2025
diff --git a/src/components/lightbox.tsx b/src/components/lightbox.tsx index df96c4b..fa46324 100644 --- a/src/components/lightbox.tsx +++ b/src/components/lightbox.tsx @@ -129,15 +129,15 @@ interface UsernameFormElement extends HTMLFormElement { export default function FilteredLightbox(props: { imageData: ImageData[]; - children: React.JSX.Element[]; }): React.JSX.Element { - //const [imageData, setImageData] = useState(props.imageData); - const [imageData] = useState(props.imageData); const photoQuery = trpc.photos.list.useInfiniteQuery( { limit: 1, }, { + refetchOnMount: false, + refetchOnReconnect: false, + refetchOnWindowFocus: false, initialData: { pages: [ { @@ -151,24 +151,30 @@ export default function FilteredLightbox(props: { } ); - const refreshQuery = trpc.photos.update.useQuery(undefined, { - enabled: false, - retry: false, - }); + // Call from observable + function loadNextPage(): void { + console.log(photoQuery.isFetchingNextPage); + console.log(photoQuery.hasNextPage); + if (!photoQuery.isFetchingNextPage) { + void photoQuery.fetchNextPage(); + } + } function handleSubmit(event: React.FormEvent): void { event.preventDefault(); - // const imageData = props.imageData; - // setImageData( + // Set filters, then action in the re-render on the data, or pass to photo query? + // setFilters( // imageData.filter( // (data) => data.src === event.currentTarget.elements.src.value // ) // ); - void photoQuery.fetchNextPage(); } - const children = photoQuery.data.pages + const imageData = photoQuery.data.pages .flatMap((data) => data.data) + .filter((data) => !!data); + + const images = imageData .map((data) => ( - )) - .filter((data) => !!data); + )); return ( <> @@ -194,16 +199,7 @@ export default function FilteredLightbox(props: { - - {refreshQuery.data ? JSON.stringify(refreshQuery.data) : "\nNot"} - {refreshQuery.error ? JSON.stringify(refreshQuery.error) : "\nNo Error"} - {...children} + {...images} ); } diff --git a/src/components/refresh-image-db.tsx b/src/components/refresh-image-db.tsx new file mode 100644 index 0000000..dbe3707 --- /dev/null +++ b/src/components/refresh-image-db.tsx @@ -0,0 +1,30 @@ +"use client"; + +import React from "react"; +import { trpc } from "@/trpc/client"; + +export default function RefreshImageDb({count}: {count: number}): React.JSX.Element { + const countQuery = trpc.photos.count.useQuery(undefined, { + refetchOnMount: false, + refetchOnReconnect: false, + refetchOnWindowFocus: false, + initialData: count + }); + const refreshQuery = trpc.photos.update.useQuery(undefined, { + enabled: false, + retry: false, + }); + + + + return ( + <> + {countQuery.data} + + {refreshQuery.data ? JSON.stringify(refreshQuery.data) : "\nNot"} + {refreshQuery.error ? JSON.stringify(refreshQuery.error) : "\nNo Error"} + + ); +} \ No newline at end of file diff --git a/src/trpc/routers/photos.ts b/src/trpc/routers/photos.ts index e882a27..dbc58fc 100644 --- a/src/trpc/routers/photos.ts +++ b/src/trpc/routers/photos.ts @@ -3,6 +3,7 @@ import { createTRPCRouter, privateProcedure, publicProcedure } from '../init'; import { list } from './photos/list'; import { update } from './photos/update'; +import { count } from './photos/count'; export const photosRouter = createTRPCRouter({ list: publicProcedure @@ -31,5 +32,6 @@ export const photosRouter = createTRPCRouter({ next }; }), + count: publicProcedure.query(count), update: privateProcedure.query(update) }); \ No newline at end of file diff --git a/src/trpc/routers/photos/count/index.ts b/src/trpc/routers/photos/count/index.ts new file mode 100644 index 0000000..967c5ad --- /dev/null +++ b/src/trpc/routers/photos/count/index.ts @@ -0,0 +1,7 @@ +import db from "@/db/db"; +import { photosTable } from "@/db/schema/photo"; + +export async function count(): Promise { + const count = await db.$count(photosTable); + return count; +} \ No newline at end of file