]> git.r.bdr.sh - rbdr/forum/blob - src/lib/stores/topics.ts
Don't remember what this WIP was about
[rbdr/forum] / src / lib / stores / topics.ts
1 import { createClient } from '@supabase/supabase-js';
2 import { single, collection } from './supabase';
3 import { supabase } from '$lib/config/config';
4
5 import type { Topic } from '$lib/data/types';
6
7 const client = createClient(supabase.url, supabase.key);
8
9 export const topic = (id: string, withPosts = false) =>
10 single<Topic>(
11 client
12 .from('topics')
13 .select(
14 withPosts
15 ? `*,
16 forum: forums (*),
17 tags: topic_tags (*),
18 posts (
19 *,
20 author:author_id (*)
21 )
22 `
23 : '*'
24 )
25 .eq('id', id),
26 null
27 );
28 export const topicsForTag = (id: string) =>
29 collection<Topic>(
30 client
31 .from('topics')
32 .select(
33 `
34 *,tags!inner(*)
35 `
36 )
37 .eq('tags.tag', id),
38 []
39 );