From d1e507f1675aa05ff8bae245a21e9b33e49fe9a3 Mon Sep 17 00:00:00 2001 From: Linzo99 Date: Wed, 6 Mar 2024 00:41:01 +0000 Subject: [PATCH 1/3] moving backend to supabase --- .vscode/settings.json | 4 - actions/api/client.ts | 262 + actions/api/index.ts | 128 + .../{AudioDashboard.tsx => Dashboard.tsx} | 2 +- .../AudioForm.tsx | 79 +- .../index.tsx => _components/Modal.tsx} | 0 .../ReciterSelect.tsx | 10 +- .../SelectInputCommand.tsx | 20 +- .../XassidaSelect.tsx | 10 +- app/(admin)/dashboard/page.tsx | 4 +- .../{ReciterDashboard.tsx => Dashboard.tsx} | 2 +- .../index.tsx => _components/Modal.tsx} | 2 - .../ReciterForm.tsx | 76 +- .../TarihaSelect.tsx | 0 .../dashboard/reciters/components/SideNav.tsx | 44 - app/(auth)/auth/callback/route.ts | 18 + app/(auth)/login/_components/AuthForm.tsx | 102 + app/(auth)/login/components/AuthFormsTab.tsx | 50 - app/(auth)/login/components/UserAuthForm.tsx | 118 - .../login/components/UserRegistrationForm.tsx | 177 - app/(auth)/login/page.tsx | 42 +- app/layout.tsx | 21 +- app/page.tsx | 2 - app/provider.tsx | 11 - app/xassida/[id]/page.tsx | 9 +- app/xassida/components/Chapter/index.tsx | 20 +- app/xassida/components/ChapterSelect.tsx | 2 +- app/xassida/components/Reader.tsx | 33 +- .../components/Verses/VerseAndTranslation.tsx | 6 +- app/xassida/components/Verses/VerseText.tsx | 17 +- components/AudioList/AudioCard.tsx | 18 +- components/AudioList/AudioCardMenu.tsx | 36 +- .../AudioPlayerBody/Buttons/MoreButton.tsx | 19 +- components/AuthorList/AuthorCard.tsx | 3 +- components/Command.tsx | 14 +- components/HomePage/Tabs/AudioTab.tsx | 2 +- components/HomePage/Tabs/MultiFilter.tsx | 26 +- components/HomePage/Tabs/XassidaTab.tsx | 16 +- components/InfiniteList.tsx | 36 +- components/Navbar/UserAccount.tsx | 11 +- components/Navbar/index.tsx | 22 +- components/ReciterList/AudioListSheet.tsx | 40 +- components/ReciterList/ReciterCard.tsx | 7 +- components/XassidaList/Xassida.tsx | 8 +- components/ui/drawer.tsx | 118 + lib/constants.ts | 6 + lib/utils.ts | 11 +- middleware.ts | 56 +- next.config.mjs | 11 +- package-lock.json | 1512 +++- package.json | 13 +- pnpm-lock.yaml | 7780 +++++++++++++++++ public/sw.js | 2 +- public/sw.js.map | 2 +- ...orkbox-d5a6b829.js => workbox-1b1de004.js} | 4 +- public/workbox-1b1de004.js.map | 1 + public/workbox-d5a6b829.js.map | 1 - tailwind.config.js | 28 +- tsconfig.tsbuildinfo | 1 - types/player.ts | 2 +- types/supabase.ts | 410 + zustand/playerStore.ts | 8 +- zustand/store.js | 6 +- 63 files changed, 10209 insertions(+), 1292 deletions(-) delete mode 100644 .vscode/settings.json create mode 100644 actions/api/client.ts create mode 100644 actions/api/index.ts rename app/(admin)/dashboard/audios/{AudioDashboard.tsx => Dashboard.tsx} (93%) rename app/(admin)/dashboard/audios/{components/AudioModalForm => _components}/AudioForm.tsx (58%) rename app/(admin)/dashboard/audios/{components/AudioModalForm/index.tsx => _components/Modal.tsx} (100%) rename app/(admin)/dashboard/audios/{components/AudioModalForm => _components}/ReciterSelect.tsx (83%) rename app/(admin)/dashboard/audios/{components/AudioModalForm => _components}/SelectInputCommand.tsx (84%) rename app/(admin)/dashboard/audios/{components/AudioModalForm => _components}/XassidaSelect.tsx (83%) rename app/(admin)/dashboard/reciters/{ReciterDashboard.tsx => Dashboard.tsx} (93%) rename app/(admin)/dashboard/reciters/{components/RecitateurModalForm/index.tsx => _components/Modal.tsx} (91%) rename app/(admin)/dashboard/reciters/{components/RecitateurModalForm => _components}/ReciterForm.tsx (57%) rename app/(admin)/dashboard/reciters/{components/RecitateurModalForm => _components}/TarihaSelect.tsx (100%) delete mode 100644 app/(admin)/dashboard/reciters/components/SideNav.tsx create mode 100644 app/(auth)/auth/callback/route.ts create mode 100644 app/(auth)/login/_components/AuthForm.tsx delete mode 100644 app/(auth)/login/components/AuthFormsTab.tsx delete mode 100644 app/(auth)/login/components/UserAuthForm.tsx delete mode 100644 app/(auth)/login/components/UserRegistrationForm.tsx delete mode 100644 app/provider.tsx create mode 100644 components/ui/drawer.tsx create mode 100644 pnpm-lock.yaml rename public/{workbox-d5a6b829.js => workbox-1b1de004.js} (99%) create mode 100644 public/workbox-1b1de004.js.map delete mode 100644 public/workbox-d5a6b829.js.map delete mode 100644 tsconfig.tsbuildinfo create mode 100644 types/supabase.ts diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index fae8e3d..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "typescript.tsdk": "node_modules/typescript/lib", - "typescript.enablePromptUseWorkspaceTsdk": true -} diff --git a/actions/api/client.ts b/actions/api/client.ts new file mode 100644 index 0000000..7c3a153 --- /dev/null +++ b/actions/api/client.ts @@ -0,0 +1,262 @@ +"use server" + +import { cookies } from "next/headers" +import { createServerActionClient } from "@supabase/auth-helpers-nextjs" + +import { + Audio, + Author, + Database, + Reciter, + TablesInsert, + TablesUpdate, + Verse, + Xassida, +} from "@/types/supabase" + +//const supabase = createClientComponentClient({}) +const supabase = createServerActionClient({ + cookies, +}) + +const signInWithEmail = async (values: { email: string; password: string }) => { + const { error } = await supabase.auth.signInWithPassword(values) + if (error) throw Error + + return true +} + +const signOut = async () => await supabase.auth.signOut() + +const searchXassida = async (search: string): Promise => { + const { data, error } = await supabase + .from("xassida") + .select("*, author(name, tariha)") + .like("name", `%${search}%`) + .limit(10) + if (error) throw error + + return data as any +} + +const searchReciter = async (search: string): Promise => { + const { data, error } = await supabase + .from("reciter") + .select("*") + .like("name", `%${search}%`) + .limit(10) + if (error) throw error + + return data as any +} + +const getXassidas = async ( + filters = {}, + offset = 0, + page_size = 15 +): Promise => { + const from = offset * page_size + const to = from + page_size - 1 + let query = supabase + .from("xassida") + .select("*, author!inner(*)") + .order("name") + // apply filters + Object.entries(filters).forEach(([k, v]) => { + if (v) query = query.filter(k, "eq", v) + }) + const { data, error } = await query.range(from, to) + if (error) throw error + + return data as any +} + +const getXassidaById = async (id: number): Promise => { + const { data, error } = await supabase + .from("xassida") + .select("*, chapter(id, number), author(*), reciter(id, name)") + .eq("id", id) + .single() + if (error) throw error + + return data as any +} + +const getVersesByChapterId = async ( + id: number, + offset = 1, + page_size = 20 +): Promise => { + const from = offset * page_size + const to = from + page_size - 1 + const { data, error } = await supabase + .from("verse") + .select("*, translations:verse_translation(*)") + .eq("chapter_id", id) + .order("number") + .range(from, to) + if (error) throw error + + return data as any +} + +const getAuthors = async ( + filters = {}, + offset = 0, + page_size = 15 +): Promise => { + const from = offset * page_size + const to = from + page_size - 1 + let query = supabase.from("author").select().order("name") + // apply filters + Object.entries(filters).forEach(([k, v]) => { + if (v) query = query.filter(k, "eq", v) + }) + const { data, error } = await query.range(from, to) + if (error) throw error + + return data +} + +const getAuthorById = async (id: number): Promise => { + const { data, error } = await supabase + .from("author") + .select() + .eq("id", id) + .single() + if (error) throw error + + return data +} + +const getReciters = async ( + filters = {}, + offset = 0, + page_size = 15 +): Promise => { + const from = offset * page_size + const to = from + page_size - 1 + let query = supabase.from("reciter").select().order("name") + // apply filters + Object.entries(filters).forEach(([k, v]) => { + if (v) query = query.filter(k, "eq", v) + }) + const { data, error } = await query.range(from, to) + if (error) throw error + + return data +} + +const getReciterById = async (id: number): Promise => { + const { data, error } = await supabase + .from("author") + .select() + .eq("id", id) + .single() + if (error) throw error + + return data +} + +const createReciter = async ( + values: TablesInsert<"reciter"> +): Promise => { + const { data, error } = await supabase.from("reciter").insert(values).select() + + if (error) throw error + + return data as any +} + +const updateReciter = async (id: number, values: TablesUpdate<"reciter">) => { + const { data, error } = await supabase + .from("reciter") + .update(values) + .eq("id", id) + .select() + + if (error) throw error + + return data as any +} + +const getAudios = async ( + filters = {}, + offset = 0, + page_size = 15 +): Promise => { + const from = offset * page_size + const to = from + page_size - 1 + let query = supabase + .from("audio") + .select("*, reciter(*), xassida(id, name, reciter(id, name))") + .order("id") + // apply filters + Object.entries(filters).forEach(([k, v]) => { + if (v) query = query.filter(k, "eq", v) + }) + const { data, error } = await query.range(from, to) + if (error) throw error + + return data as any +} + +const getAudioById = async (id: number): Promise