]> git.r.bdr.sh - rbdr/forum/blobdiff - src/lib/stores/posts.ts
Don't remember what this WIP was about
[rbdr/forum] / src / lib / stores / posts.ts
index 0d3dec305c9356cae33cba2a802cb8030ac0dbb3..388eed3aef9bbbecfe2591474966b704279ed8cc 100644 (file)
@@ -1,4 +1,24 @@
-import { store } from './apollo';
-import { GET_POST } from '$lib/data/queries';
+import { createClient } from '@supabase/supabase-js';
+import { single } from './supabase';
+import { supabase } from '$lib/config/config';
 
-export const getPost = (id: string) => store({ key: 'post', query: GET_POST, variables: { id } });
+import type { Post } from '$lib/data/types';
+
+const client = createClient(supabase.url, supabase.key);
+
+export const post = (id: string, withTopic = false) =>
+       single<Post>(
+               client
+                       .from('posts')
+                       .select(
+                               withTopic
+                                       ? `*, 
+    topic:topic_id (
+      *
+    )
+  `
+                                       : '*'
+                       )
+                       .eq('id', id),
+               null
+       );