From 9f0fb14d56fcbd9280aee2bdd83d55e8fabbe7d2 Mon Sep 17 00:00:00 2001 From: Dhravya Date: Fri, 14 Jun 2024 23:35:19 -0500 Subject: [MIGRATION REQUIRED]Data fetchers and other server actions, spaces creation and database migrations --- apps/web/app/(dash)/actions.ts | 48 --------- apps/web/app/(dash)/dynamicisland.tsx | 109 +++++++++++++++---- apps/web/app/(dash)/home/page.tsx | 11 +- apps/web/app/(dash)/home/queryinput.tsx | 21 ++-- apps/web/app/(dash)/layout.tsx | 7 +- apps/web/app/actions/doers.ts | 43 ++++++++ apps/web/app/actions/fetchers.ts | 25 +++++ apps/web/app/actions/types.ts | 10 ++ apps/web/app/helpers/server/auth.ts | 25 +++-- apps/web/app/helpers/server/db/schema.ts | 99 +++++++++-------- apps/web/migrations/000_setup.sql | 55 ++++++---- apps/web/migrations/meta/0000_snapshot.json | 158 +++++++++++++++++---------- apps/web/migrations/meta/_journal.json | 4 +- apps/web/package.json | 3 +- package.json | 4 +- packages/ui/shadcn/select.tsx | 160 ++++++++++++++++++++++++++++ packages/ui/shadcn/sonner.tsx | 31 ++++++ 17 files changed, 599 insertions(+), 214 deletions(-) delete mode 100644 apps/web/app/(dash)/actions.ts create mode 100644 apps/web/app/actions/doers.ts create mode 100644 apps/web/app/actions/fetchers.ts create mode 100644 apps/web/app/actions/types.ts create mode 100644 packages/ui/shadcn/select.tsx create mode 100644 packages/ui/shadcn/sonner.tsx diff --git a/apps/web/app/(dash)/actions.ts b/apps/web/app/(dash)/actions.ts deleted file mode 100644 index 70c2a567..00000000 --- a/apps/web/app/(dash)/actions.ts +++ /dev/null @@ -1,48 +0,0 @@ -"use server"; - -import { cookies, headers } from "next/headers"; -import { db } from "../helpers/server/db"; -import { sessions, users, space } from "../helpers/server/db/schema"; -import { eq } from "drizzle-orm"; -import { redirect } from "next/navigation"; - -export async function ensureAuth() { - const token = - cookies().get("next-auth.session-token")?.value ?? - cookies().get("__Secure-authjs.session-token")?.value ?? - cookies().get("authjs.session-token")?.value ?? - headers().get("Authorization")?.replace("Bearer ", ""); - - if (!token) { - return undefined; - } - - const sessionData = await db - .select() - .from(sessions) - .innerJoin(users, eq(users.id, sessions.userId)) - .where(eq(sessions.sessionToken, token)); - - if (!sessionData || sessionData.length < 0) { - return undefined; - } - - return { - user: sessionData[0]!.user, - session: sessionData[0]!, - }; -} - -export async function getSpaces() { - const data = await ensureAuth(); - if (!data) { - redirect("/signin"); - } - - const sp = await db - .select() - .from(space) - .where(eq(space.user, data.user.email)); - - return sp; -} diff --git a/apps/web/app/(dash)/dynamicisland.tsx b/apps/web/app/(dash)/dynamicisland.tsx index b703d55a..31f76fda 100644 --- a/apps/web/app/(dash)/dynamicisland.tsx +++ b/apps/web/app/(dash)/dynamicisland.tsx @@ -9,6 +9,17 @@ import { motion } from "framer-motion"; import { Label } from "@repo/ui/shadcn/label"; import { Input } from "@repo/ui/shadcn/input"; import { Textarea } from "@repo/ui/shadcn/textarea"; +import { createSpace } from "../actions/doers"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@repo/ui/shadcn/select"; +import { Space } from "../actions/types"; +import { getSpaces } from "../actions/fetchers"; +import { toast } from "sonner"; export function DynamicIsland() { const { scrollYProgress } = useScroll(); @@ -80,7 +91,7 @@ function DynamicIslandContent() { {show ? (
setshow(!show)} - className="bg-[#1F2428] px-3 w-[2.23rem] overflow-hidden hover:w-[9.2rem] whitespace-nowrap py-2 rounded-3xl transition-[width] cursor-pointer" + className="bg-secondary px-3 w-[2.23rem] overflow-hidden hover:w-[9.2rem] whitespace-nowrap py-2 rounded-3xl transition-[width] cursor-pointer" >
Add icon @@ -99,7 +110,25 @@ function DynamicIslandContent() { const fakeitems = ["spaces", "page", "note"]; function ToolBar({ cancelfn }: { cancelfn: () => void }) { + const [spaces, setSpaces] = useState([]); + const [index, setIndex] = useState(0); + + useEffect(() => { + (async () => { + let spaces = await getSpaces(); + + if (!spaces.success || !spaces.data) { + toast.warning("Unable to get spaces", { + richColors: true, + }); + setSpaces([]); + return; + } + setSpaces(spaces.data); + })(); + }, []); + return ( void }) { }} className="flex flex-col items-center" > -
+
void }) { {index === 0 ? ( ) : index === 1 ? ( - + ) : ( - + )} @@ -182,7 +211,10 @@ export const HoverEffect = ({ function SpaceForm({ cancelfn }: { cancelfn: () => void }) { return ( -
+
pull from store -
cancel -
+
*/} +
-
+ ); } -function PageForm({ cancelfn }: { cancelfn: () => void }) { +function PageForm({ + cancelfn, + spaces, +}: { + cancelfn: () => void; + spaces: Space[]; +}) { return ( -
+
-