X-Git-Url: https://git.r.bdr.sh/rbdr/forum/blobdiff_plain/c1bc5993a694f6fd047a3881351827058042483b..fcbbc49687afeeecdc9388b367b1d7f2d0c76214:/src/stores/forums.js diff --git a/src/stores/forums.js b/src/stores/forums.js index ade01a7..2c03a05 100644 --- a/src/stores/forums.js +++ b/src/stores/forums.js @@ -1,36 +1,5 @@ -import { ApolloError } from '@apollo/client/core'; -import { readable } from 'svelte/store'; -import { client } from '$config/apollo'; -import { GET_FORUMS } from '$data/queries'; +import { store } from './apollo'; +import { GET_FORUM, GET_FORUMS } from '$/data/queries'; -const internals = { - - // The exported data structure - - initialValue: { - loading: true, - data: [], - error: undefined - } -}; - -export const forums = readable(internals.initialValue, (set) => { - - client.watchQuery({ query: GET_FORUMS }).subscribe((result) => { - - if (result.errors) { - const error = new ApolloError({ graphQLErrors: result.errors }); - return set({ - loading: false, - data: [], - error - }); - } - - set({ - loading: false, - data: result.data.forums, - error: undefined - }); - }); -}); +export const getForum = (id) => store({ key: 'forum', query: GET_FORUM, variables: { id } }); +export const getForums = () => store({ key: 'forums', query: GET_FORUMS, initialValue: [] });