From e67e86b63e5c5fa07b04a625f94563d0382272e8 Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Tue, 19 Nov 2024 18:36:50 +0000 Subject: [PATCH] Got the PgProvider working --- apps/webapp/app/pglite/usePglite.tsx | 35 ----- .../route.tsx | 121 ++++++++++++------ 2 files changed, 80 insertions(+), 76 deletions(-) delete mode 100644 apps/webapp/app/pglite/usePglite.tsx diff --git a/apps/webapp/app/pglite/usePglite.tsx b/apps/webapp/app/pglite/usePglite.tsx deleted file mode 100644 index 837175fd4..000000000 --- a/apps/webapp/app/pglite/usePglite.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import { PGlite } from "@electric-sql/pglite"; -import { createClient } from "."; -import { useState, useEffect, useRef } from "react"; -import { LiveNamespace } from "@electric-sql/pglite/live"; - -type Client = PGlite & { - live: LiveNamespace; -}; - -export function usePglite() { - const clientRef = useRef(null); - const [isLoading, setIsLoading] = useState(!clientRef.current); - - useEffect(() => { - if (typeof window === "undefined") return; - - if (clientRef.current) { - setIsLoading(false); - return; - } - - // Otherwise, create a new client - createClient() - .then((newClient) => { - clientRef.current = newClient; - setIsLoading(false); - }) - .catch((error) => { - console.error("Failed to initialize database:", error); - setIsLoading(false); - }); - }, []); - - return { client: clientRef.current, isLoading }; -} diff --git a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.runs.electric._index/route.tsx b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.runs.electric._index/route.tsx index 91bbb2d39..ab0addc7b 100644 --- a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.runs.electric._index/route.tsx +++ b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.runs.electric._index/route.tsx @@ -1,10 +1,12 @@ import { ArrowPathIcon, StopCircleIcon } from "@heroicons/react/20/solid"; import { BeakerIcon, BookOpenIcon } from "@heroicons/react/24/solid"; import { Form, useNavigation } from "@remix-run/react"; +import { LoaderFunctionArgs } from "@remix-run/server-runtime"; import { IconCircleX } from "@tabler/icons-react"; import { AnimatePresence, motion } from "framer-motion"; import { ListChecks, ListX } from "lucide-react"; import { Suspense, useState } from "react"; +import { TypedAwait, typeddefer, useTypedLoaderData } from "remix-typedjson"; import { TaskIcon } from "~/assets/icons/TaskIcon"; import { StepContentContainer } from "~/components/StepContentContainer"; import { MainCenteredContainer, PageBody } from "~/components/layout/AppLayout"; @@ -28,19 +30,56 @@ import { import { Spinner } from "~/components/primitives/Spinner"; import { StepNumber } from "~/components/primitives/StepNumber"; import { TextLink } from "~/components/primitives/TextLink"; +import { RunsFilters, TaskRunListSearchFilters } from "~/components/runs/v3/RunFilters"; +import { TaskRunsTable } from "~/components/runs/v3/TaskRunsTable"; import { BULK_ACTION_RUN_LIMIT } from "~/consts"; import { useOrganization } from "~/hooks/useOrganizations"; import { useProject } from "~/hooks/useProject"; -import { usePglite } from "~/pglite/usePglite"; +import { useUser } from "~/hooks/useUser"; +import { findProjectBySlug } from "~/models/project.server"; +import { RunListPresenter } from "~/presenters/v3/RunListPresenter.server"; +import { requireUserId } from "~/services/session.server"; import { cn } from "~/utils/cn"; -import { docsPath, v3ProjectPath, v3RunsPath, v3TestPath } from "~/utils/pathBuilder"; +import { + docsPath, + ProjectParamSchema, + v3ProjectPath, + v3RunsPath, + v3TestPath, +} from "~/utils/pathBuilder"; +import { ListPagination } from "../../components/ListPagination"; +import { useEffect } from "react"; +import { PGliteWorker } from "@electric-sql/pglite/worker"; +import { PgProvider } from "~/pglite/provider"; +import { useLiveQuery } from "@electric-sql/pglite-react"; +import type { TaskRun } from "@trigger.dev/database"; export default function Page() { + return ( + + + + ); +} + +function Content() { const project = useProject(); - const { client, isLoading } = usePglite(); + const items = useLiveQuery(`SELECT * FROM "TaskRun";`); - console.log("PG", { isLoading, client }); + console.log(items); + + if (!items) return
Loading...
; + + return ( +
+ {items.rows.map((row) => ( +
+ {row.id} - {row.taskIdentifier} - {row.status} +
+ ))} +
+ ); return ( <> @@ -79,45 +118,45 @@ export default function Page() { } > {/* - {(list) => ( - <> - {list.runs.length === 0 && !list.hasFilters ? ( - list.possibleTasks.length === 0 ? ( - - ) : ( - - ) - ) : ( -
-
- -
- -
-
- - -
+ {(list) => ( + <> + {list.runs.length === 0 && !list.hasFilters ? ( + list.possibleTasks.length === 0 ? ( + + ) : ( + + ) + ) : ( +
+ > +
+ +
+ +
+
+ + +
)} -
*/} + + )} + */}