graphql-fix
This commit is contained in:
parent
81ed60a52f
commit
142c5bfb41
|
@ -7,7 +7,6 @@ import { Loading } from './components/_shared/Loading'
|
||||||
import { AuthorsProvider } from './context/authors'
|
import { AuthorsProvider } from './context/authors'
|
||||||
import { EditorProvider } from './context/editor'
|
import { EditorProvider } from './context/editor'
|
||||||
import { FeedProvider } from './context/feed'
|
import { FeedProvider } from './context/feed'
|
||||||
import { GraphQLClientProvider } from './context/graphql'
|
|
||||||
import { LocalizeProvider } from './context/localize'
|
import { LocalizeProvider } from './context/localize'
|
||||||
import { SessionProvider } from './context/session'
|
import { SessionProvider } from './context/session'
|
||||||
import { TopicsProvider } from './context/topics'
|
import { TopicsProvider } from './context/topics'
|
||||||
|
@ -18,7 +17,6 @@ export const Providers = (props: { children?: JSX.Element }) => {
|
||||||
return (
|
return (
|
||||||
<LocalizeProvider>
|
<LocalizeProvider>
|
||||||
<SessionProvider onStateChangeCallback={console.info}>
|
<SessionProvider onStateChangeCallback={console.info}>
|
||||||
<GraphQLClientProvider>
|
|
||||||
<TopicsProvider>
|
<TopicsProvider>
|
||||||
<FeedProvider>
|
<FeedProvider>
|
||||||
<MetaProvider>
|
<MetaProvider>
|
||||||
|
@ -33,7 +31,6 @@ export const Providers = (props: { children?: JSX.Element }) => {
|
||||||
</MetaProvider>
|
</MetaProvider>
|
||||||
</FeedProvider>
|
</FeedProvider>
|
||||||
</TopicsProvider>
|
</TopicsProvider>
|
||||||
</GraphQLClientProvider>
|
|
||||||
</SessionProvider>
|
</SessionProvider>
|
||||||
</LocalizeProvider>
|
</LocalizeProvider>
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,11 +3,12 @@ import { clsx } from 'clsx'
|
||||||
import { For, Show, Suspense, createMemo, createSignal, lazy } from 'solid-js'
|
import { For, Show, Suspense, createMemo, createSignal, lazy } from 'solid-js'
|
||||||
import { Icon } from '~/components/_shared/Icon'
|
import { Icon } from '~/components/_shared/Icon'
|
||||||
import { ShowIfAuthenticated } from '~/components/_shared/ShowIfAuthenticated'
|
import { ShowIfAuthenticated } from '~/components/_shared/ShowIfAuthenticated'
|
||||||
import { useGraphQL } from '~/context/graphql'
|
import { coreApiUrl } from '~/config'
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
import { useReactions } from '~/context/reactions'
|
import { useReactions } from '~/context/reactions'
|
||||||
import { useSession } from '~/context/session'
|
import { useSession } from '~/context/session'
|
||||||
import { useSnackbar, useUI } from '~/context/ui'
|
import { useSnackbar, useUI } from '~/context/ui'
|
||||||
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import deleteReactionMutation from '~/graphql/mutation/core/reaction-destroy'
|
import deleteReactionMutation from '~/graphql/mutation/core/reaction-destroy'
|
||||||
import {
|
import {
|
||||||
Author,
|
Author,
|
||||||
|
@ -49,8 +50,7 @@ export const Comment = (props: Props) => {
|
||||||
const { createReaction, updateReaction } = useReactions()
|
const { createReaction, updateReaction } = useReactions()
|
||||||
const { showConfirm } = useUI()
|
const { showConfirm } = useUI()
|
||||||
const { showSnackbar } = useSnackbar()
|
const { showSnackbar } = useSnackbar()
|
||||||
const { mutation } = useGraphQL()
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
const canEdit = createMemo(
|
const canEdit = createMemo(
|
||||||
() =>
|
() =>
|
||||||
Boolean(author()?.id) &&
|
Boolean(author()?.id) &&
|
||||||
|
@ -70,7 +70,9 @@ export const Comment = (props: Props) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
if (isConfirmed) {
|
if (isConfirmed) {
|
||||||
const resp = await mutation(deleteReactionMutation, { id: props.comment.id }).toPromise()
|
const resp = await client()
|
||||||
|
?.mutation(deleteReactionMutation, { id: props.comment.id })
|
||||||
|
.toPromise()
|
||||||
const result = resp?.data?.delete_reaction
|
const result = resp?.data?.delete_reaction
|
||||||
const { error } = result
|
const { error } = result
|
||||||
const notificationType = error ? 'error' : 'success'
|
const notificationType = error ? 'error' : 'success'
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import type { Author } from '~/graphql/schema/core.gen'
|
import type { Author } from '~/graphql/schema/core.gen'
|
||||||
|
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import { Show, createSignal } from 'solid-js'
|
import { Show, createMemo, createSignal } from 'solid-js'
|
||||||
import { useGraphQL } from '~/context/graphql'
|
import { coreApiUrl } from '~/config'
|
||||||
|
import { useSession } from '~/context/session'
|
||||||
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import rateAuthorMutation from '~/graphql/mutation/core/author-rate'
|
import rateAuthorMutation from '~/graphql/mutation/core/author-rate'
|
||||||
import styles from './AuthorRatingControl.module.scss'
|
import styles from './AuthorRatingControl.module.scss'
|
||||||
|
|
||||||
|
@ -14,19 +16,24 @@ interface AuthorRatingControlProps {
|
||||||
export const AuthorRatingControl = (props: AuthorRatingControlProps) => {
|
export const AuthorRatingControl = (props: AuthorRatingControlProps) => {
|
||||||
const isUpvoted = false
|
const isUpvoted = false
|
||||||
const isDownvoted = false
|
const isDownvoted = false
|
||||||
|
|
||||||
|
const { session } = useSession()
|
||||||
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
// eslint-disable-next-line unicorn/consistent-function-scoping
|
// eslint-disable-next-line unicorn/consistent-function-scoping
|
||||||
const handleRatingChange = async (isUpvote: boolean) => {
|
const handleRatingChange = async (isUpvote: boolean) => {
|
||||||
console.log('handleRatingChange', { isUpvote })
|
console.log('handleRatingChange', { isUpvote })
|
||||||
if (props.author?.slug) {
|
if (props.author?.slug) {
|
||||||
const value = isUpvote ? 1 : -1
|
const value = isUpvote ? 1 : -1
|
||||||
const _resp = await mutation(rateAuthorMutation, {
|
const _resp = await client()
|
||||||
|
?.mutation(rateAuthorMutation, {
|
||||||
rated_slug: props.author?.slug,
|
rated_slug: props.author?.slug,
|
||||||
value
|
value
|
||||||
}).toPromise()
|
})
|
||||||
|
.toPromise()
|
||||||
setRating((r) => (r || 0) + value)
|
setRating((r) => (r || 0) + value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const { mutation } = useGraphQL()
|
|
||||||
const [rating, setRating] = createSignal(props.author?.stat?.rating)
|
const [rating, setRating] = createSignal(props.author?.stat?.rating)
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -2,11 +2,12 @@ import { A, useLocation } from '@solidjs/router'
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import { For, Match, Show, Switch, createEffect, createMemo, createSignal } from 'solid-js'
|
import { For, Match, Show, Switch, createEffect, createMemo, createSignal } from 'solid-js'
|
||||||
import { Loading } from '~/components/_shared/Loading'
|
import { Loading } from '~/components/_shared/Loading'
|
||||||
|
import { coreApiUrl } from '~/config'
|
||||||
import { useAuthors } from '~/context/authors'
|
import { useAuthors } from '~/context/authors'
|
||||||
import { useFollowing } from '~/context/following'
|
import { useFollowing } from '~/context/following'
|
||||||
import { useGraphQL } from '~/context/graphql'
|
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
import { useSession } from '~/context/session'
|
import { useSession } from '~/context/session'
|
||||||
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import getAuthorFollowersQuery from '~/graphql/query/core/author-followers'
|
import getAuthorFollowersQuery from '~/graphql/query/core/author-followers'
|
||||||
import getAuthorFollowsQuery from '~/graphql/query/core/author-follows'
|
import getAuthorFollowsQuery from '~/graphql/query/core/author-follows'
|
||||||
import type { Author, Reaction, Shout, Topic } from '~/graphql/schema/core.gen'
|
import type { Author, Reaction, Shout, Topic } from '~/graphql/schema/core.gen'
|
||||||
|
@ -36,8 +37,10 @@ export const AuthorView = (props: AuthorViewProps) => {
|
||||||
// contexts
|
// contexts
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
const loc = useLocation()
|
const loc = useLocation()
|
||||||
|
|
||||||
const { session } = useSession()
|
const { session } = useSession()
|
||||||
const { query } = useGraphQL()
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
const { loadAuthor, authorsEntities } = useAuthors()
|
const { loadAuthor, authorsEntities } = useAuthors()
|
||||||
const { followers: myFollowers, follows: myFollows } = useFollowing()
|
const { followers: myFollowers, follows: myFollows } = useFollowing()
|
||||||
|
|
||||||
|
@ -70,11 +73,15 @@ export const AuthorView = (props: AuthorViewProps) => {
|
||||||
setAuthor(foundAuthor)
|
setAuthor(foundAuthor)
|
||||||
|
|
||||||
if (foundAuthor) {
|
if (foundAuthor) {
|
||||||
const followsResp = await query(getAuthorFollowsQuery, { slug: foundAuthor.slug }).toPromise()
|
const followsResp = await client()
|
||||||
|
?.query(getAuthorFollowsQuery, { slug: foundAuthor.slug })
|
||||||
|
.toPromise()
|
||||||
const follows = followsResp?.data?.get_author_followers || {}
|
const follows = followsResp?.data?.get_author_followers || {}
|
||||||
changeFollowing([...(follows?.authors || []), ...(follows?.topics || [])])
|
changeFollowing([...(follows?.authors || []), ...(follows?.topics || [])])
|
||||||
|
|
||||||
const followersResp = await query(getAuthorFollowersQuery, { slug: foundAuthor.slug }).toPromise()
|
const followersResp = await client()
|
||||||
|
?.query(getAuthorFollowersQuery, { slug: foundAuthor.slug })
|
||||||
|
.toPromise()
|
||||||
setFollowers(followersResp?.data?.get_author_followers || [])
|
setFollowers(followersResp?.data?.get_author_followers || [])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import deepEqual from 'fast-deep-equal'
|
import deepEqual from 'fast-deep-equal'
|
||||||
import { Show, createEffect, createSignal, on, onCleanup, onMount } from 'solid-js'
|
import { Show, createEffect, createMemo, createSignal, on, onCleanup, onMount } from 'solid-js'
|
||||||
import { createStore } from 'solid-js/store'
|
import { createStore } from 'solid-js/store'
|
||||||
import { debounce } from 'throttle-debounce'
|
import { debounce } from 'throttle-debounce'
|
||||||
import { Icon } from '~/components/_shared/Icon'
|
import { Icon } from '~/components/_shared/Icon'
|
||||||
import { InviteMembers } from '~/components/_shared/InviteMembers'
|
import { InviteMembers } from '~/components/_shared/InviteMembers'
|
||||||
|
import { coreApiUrl } from '~/config'
|
||||||
import { ShoutForm, useEditorContext } from '~/context/editor'
|
import { ShoutForm, useEditorContext } from '~/context/editor'
|
||||||
import { useGraphQL } from '~/context/graphql'
|
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
|
import { useSession } from '~/context/session'
|
||||||
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import getMyShoutQuery from '~/graphql/query/core/article-my'
|
import getMyShoutQuery from '~/graphql/query/core/article-my'
|
||||||
import type { Shout, Topic } from '~/graphql/schema/core.gen'
|
import type { Shout, Topic } from '~/graphql/schema/core.gen'
|
||||||
import { isDesktop } from '~/lib/mediaQuery'
|
import { isDesktop } from '~/lib/mediaQuery'
|
||||||
|
@ -42,7 +44,9 @@ const handleScrollTopButtonClick = (ev: MouseEvent | TouchEvent) => {
|
||||||
export const EditSettingsView = (props: Props) => {
|
export const EditSettingsView = (props: Props) => {
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
const [isScrolled, setIsScrolled] = createSignal(false)
|
const [isScrolled, setIsScrolled] = createSignal(false)
|
||||||
const { query } = useGraphQL()
|
const { session } = useSession()
|
||||||
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
const { form, setForm, saveDraft, saveDraftToLocalStorage, getDraftFromLocalStorage } = useEditorContext()
|
const { form, setForm, saveDraft, saveDraftToLocalStorage, getDraftFromLocalStorage } = useEditorContext()
|
||||||
const [shoutTopics, setShoutTopics] = createSignal<Topic[]>([])
|
const [shoutTopics, setShoutTopics] = createSignal<Topic[]>([])
|
||||||
const [draft, setDraft] = createSignal()
|
const [draft, setDraft] = createSignal()
|
||||||
|
@ -106,7 +110,7 @@ export const EditSettingsView = (props: Props) => {
|
||||||
() => props.shout?.id,
|
() => props.shout?.id,
|
||||||
async (shoutId) => {
|
async (shoutId) => {
|
||||||
if (shoutId) {
|
if (shoutId) {
|
||||||
const resp = await query(getMyShoutQuery, { shout_id: shoutId })
|
const resp = await client()?.query(getMyShoutQuery, { shout_id: shoutId })
|
||||||
const result = resp?.data?.get_my_shout
|
const result = resp?.data?.get_my_shout
|
||||||
if (result) {
|
if (result) {
|
||||||
console.debug('[EditView] getMyShout result: ', result)
|
console.debug('[EditView] getMyShout result: ', result)
|
||||||
|
|
|
@ -19,9 +19,11 @@ import { InviteMembers } from '~/components/_shared/InviteMembers'
|
||||||
import { Loading } from '~/components/_shared/Loading'
|
import { Loading } from '~/components/_shared/Loading'
|
||||||
import { Popover } from '~/components/_shared/Popover'
|
import { Popover } from '~/components/_shared/Popover'
|
||||||
import { EditorSwiper } from '~/components/_shared/SolidSwiper'
|
import { EditorSwiper } from '~/components/_shared/SolidSwiper'
|
||||||
|
import { coreApiUrl } from '~/config'
|
||||||
import { ShoutForm, useEditorContext } from '~/context/editor'
|
import { ShoutForm, useEditorContext } from '~/context/editor'
|
||||||
import { useGraphQL } from '~/context/graphql'
|
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
|
import { useSession } from '~/context/session'
|
||||||
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import getMyShoutQuery from '~/graphql/query/core/article-my'
|
import getMyShoutQuery from '~/graphql/query/core/article-my'
|
||||||
import type { Shout, Topic } from '~/graphql/schema/core.gen'
|
import type { Shout, Topic } from '~/graphql/schema/core.gen'
|
||||||
import { slugify } from '~/intl/translit'
|
import { slugify } from '~/intl/translit'
|
||||||
|
@ -64,7 +66,9 @@ const handleScrollTopButtonClick = (ev: MouseEvent | TouchEvent) => {
|
||||||
export const EditView = (props: Props) => {
|
export const EditView = (props: Props) => {
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
const [isScrolled, setIsScrolled] = createSignal(false)
|
const [isScrolled, setIsScrolled] = createSignal(false)
|
||||||
const { query } = useGraphQL()
|
const { session } = useSession()
|
||||||
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
const {
|
const {
|
||||||
form,
|
form,
|
||||||
formErrors,
|
formErrors,
|
||||||
|
@ -140,7 +144,7 @@ export const EditView = (props: Props) => {
|
||||||
() => props.shout?.id,
|
() => props.shout?.id,
|
||||||
async (shoutId) => {
|
async (shoutId) => {
|
||||||
if (shoutId) {
|
if (shoutId) {
|
||||||
const resp = await query(getMyShoutQuery, { shout_id: shoutId })
|
const resp = await client()?.query(getMyShoutQuery, { shout_id: shoutId })
|
||||||
const result = resp?.data?.get_my_shout
|
const result = resp?.data?.get_my_shout
|
||||||
if (result) {
|
if (result) {
|
||||||
console.debug('[EditView] getMyShout result: ', result)
|
console.debug('[EditView] getMyShout result: ', result)
|
||||||
|
|
|
@ -5,10 +5,12 @@ import { ConditionalWrapper } from '~/components/_shared/ConditionalWrapper'
|
||||||
import { LoadMoreItems, LoadMoreWrapper } from '~/components/_shared/LoadMoreWrapper'
|
import { LoadMoreItems, LoadMoreWrapper } from '~/components/_shared/LoadMoreWrapper'
|
||||||
import { Loading } from '~/components/_shared/Loading'
|
import { Loading } from '~/components/_shared/Loading'
|
||||||
import { ArticleCardSwiper } from '~/components/_shared/SolidSwiper/ArticleCardSwiper'
|
import { ArticleCardSwiper } from '~/components/_shared/SolidSwiper/ArticleCardSwiper'
|
||||||
|
import { coreApiUrl } from '~/config'
|
||||||
import { useFeed } from '~/context/feed'
|
import { useFeed } from '~/context/feed'
|
||||||
import { useGraphQL } from '~/context/graphql'
|
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
|
import { useSession } from '~/context/session'
|
||||||
import { loadShouts } from '~/graphql/api/public'
|
import { loadShouts } from '~/graphql/api/public'
|
||||||
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import getRandomTopShoutsQuery from '~/graphql/query/core/articles-load-random-top'
|
import getRandomTopShoutsQuery from '~/graphql/query/core/articles-load-random-top'
|
||||||
import { LoadShoutsFilters, LoadShoutsOptions, Shout } from '~/graphql/schema/core.gen'
|
import { LoadShoutsFilters, LoadShoutsOptions, Shout } from '~/graphql/schema/core.gen'
|
||||||
import { SHOUTS_PER_PAGE } from '~/routes/(main)'
|
import { SHOUTS_PER_PAGE } from '~/routes/(main)'
|
||||||
|
@ -29,7 +31,9 @@ const LOAD_MORE_PAGE_SIZE = 12
|
||||||
|
|
||||||
export const Expo = (props: Props) => {
|
export const Expo = (props: Props) => {
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
const { query } = useGraphQL()
|
const { session } = useSession()
|
||||||
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
const [favoriteTopArticles, setFavoriteTopArticles] = createSignal<Shout[]>([])
|
const [favoriteTopArticles, setFavoriteTopArticles] = createSignal<Shout[]>([])
|
||||||
const [reactedTopMonthArticles, setReactedTopMonthArticles] = createSignal<Shout[]>([])
|
const [reactedTopMonthArticles, setReactedTopMonthArticles] = createSignal<Shout[]>([])
|
||||||
const [expoShouts, setExpoShouts] = createSignal<Shout[]>([])
|
const [expoShouts, setExpoShouts] = createSignal<Shout[]>([])
|
||||||
|
@ -55,7 +59,7 @@ export const Expo = (props: Props) => {
|
||||||
limit: 10,
|
limit: 10,
|
||||||
random_limit: 100
|
random_limit: 100
|
||||||
}
|
}
|
||||||
const resp = await query(getRandomTopShoutsQuery, { options }).toPromise()
|
const resp = await client()?.query(getRandomTopShoutsQuery, { options }).toPromise()
|
||||||
setFavoriteTopArticles(resp?.data?.load_shouts_random_top || [])
|
setFavoriteTopArticles(resp?.data?.load_shouts_random_top || [])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +71,7 @@ export const Expo = (props: Props) => {
|
||||||
limit: 10,
|
limit: 10,
|
||||||
random_limit: 10
|
random_limit: 10
|
||||||
}
|
}
|
||||||
const resp = await query(getRandomTopShoutsQuery, { options }).toPromise()
|
const resp = await client()?.query(getRandomTopShoutsQuery, { options }).toPromise()
|
||||||
setReactedTopMonthArticles(resp?.data?.load_shouts_random_top || [])
|
setReactedTopMonthArticles(resp?.data?.load_shouts_random_top || [])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,15 @@ import { Icon } from '~/components/_shared/Icon'
|
||||||
import { InviteMembers } from '~/components/_shared/InviteMembers'
|
import { InviteMembers } from '~/components/_shared/InviteMembers'
|
||||||
import { Loading } from '~/components/_shared/Loading'
|
import { Loading } from '~/components/_shared/Loading'
|
||||||
import { ShareModal } from '~/components/_shared/ShareModal'
|
import { ShareModal } from '~/components/_shared/ShareModal'
|
||||||
|
import { coreApiUrl } from '~/config'
|
||||||
import { useAuthors } from '~/context/authors'
|
import { useAuthors } from '~/context/authors'
|
||||||
import { useGraphQL } from '~/context/graphql'
|
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
import { useReactions } from '~/context/reactions'
|
import { useReactions } from '~/context/reactions'
|
||||||
import { useSession } from '~/context/session'
|
import { useSession } from '~/context/session'
|
||||||
import { useTopics } from '~/context/topics'
|
import { useTopics } from '~/context/topics'
|
||||||
import { useUI } from '~/context/ui'
|
import { useUI } from '~/context/ui'
|
||||||
import { loadUnratedShouts } from '~/graphql/api/private'
|
import { loadUnratedShouts } from '~/graphql/api/private'
|
||||||
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import type { Author, Reaction, Shout } from '~/graphql/schema/core.gen'
|
import type { Author, Reaction, Shout } from '~/graphql/schema/core.gen'
|
||||||
import { byCreated } from '~/lib/sort'
|
import { byCreated } from '~/lib/sort'
|
||||||
import { FeedSearchParams } from '~/routes/feed/[...order]'
|
import { FeedSearchParams } from '~/routes/feed/[...order]'
|
||||||
|
@ -48,10 +49,12 @@ const PERIODS = {
|
||||||
export const FeedView = (props: FeedProps) => {
|
export const FeedView = (props: FeedProps) => {
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
const loc = useLocation()
|
const loc = useLocation()
|
||||||
const client = useGraphQL()
|
const { session } = useSession()
|
||||||
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
const unrated = createAsync(async () => {
|
const unrated = createAsync(async () => {
|
||||||
if (client) {
|
if (client) {
|
||||||
const shoutsLoader = loadUnratedShouts(client, { limit: 5 })
|
const shoutsLoader = loadUnratedShouts(client(), { limit: 5 })
|
||||||
return await shoutsLoader()
|
return await shoutsLoader()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -59,7 +62,6 @@ export const FeedView = (props: FeedProps) => {
|
||||||
const { showModal } = useUI()
|
const { showModal } = useUI()
|
||||||
const [isLoading, setIsLoading] = createSignal(false)
|
const [isLoading, setIsLoading] = createSignal(false)
|
||||||
const [isRightColumnLoaded, setIsRightColumnLoaded] = createSignal(false)
|
const [isRightColumnLoaded, setIsRightColumnLoaded] = createSignal(false)
|
||||||
const { session } = useSession()
|
|
||||||
const { loadReactionsBy } = useReactions()
|
const { loadReactionsBy } = useReactions()
|
||||||
const { topTopics } = useTopics()
|
const { topTopics } = useTopics()
|
||||||
const { topAuthors } = useAuthors()
|
const { topAuthors } = useAuthors()
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
import { useMatch, useNavigate } from '@solidjs/router'
|
import { useMatch, useNavigate } from '@solidjs/router'
|
||||||
import { Editor } from '@tiptap/core'
|
import { Editor } from '@tiptap/core'
|
||||||
import type { JSX } from 'solid-js'
|
import type { JSX } from 'solid-js'
|
||||||
import { Accessor, createContext, createSignal, useContext } from 'solid-js'
|
import { Accessor, createContext, createMemo, createSignal, useContext } from 'solid-js'
|
||||||
import { SetStoreFunction, createStore } from 'solid-js/store'
|
import { SetStoreFunction, createStore } from 'solid-js/store'
|
||||||
|
import { coreApiUrl } from '~/config'
|
||||||
import { useSnackbar } from '~/context/ui'
|
import { useSnackbar } from '~/context/ui'
|
||||||
import deleteShoutQuery from '~/graphql/mutation/core/article-delete'
|
import deleteShoutQuery from '~/graphql/mutation/core/article-delete'
|
||||||
import updateShoutQuery from '~/graphql/mutation/core/article-update'
|
import updateShoutQuery from '~/graphql/mutation/core/article-update'
|
||||||
import { Topic, TopicInput } from '~/graphql/schema/core.gen'
|
import { Topic, TopicInput } from '~/graphql/schema/core.gen'
|
||||||
import { slugify } from '~/intl/translit'
|
import { slugify } from '~/intl/translit'
|
||||||
import { useFeed } from '../context/feed'
|
import { useFeed } from '../context/feed'
|
||||||
import { useGraphQL } from './graphql'
|
import { graphqlClientCreate } from '../graphql/client'
|
||||||
import { useLocalize } from './localize'
|
import { useLocalize } from './localize'
|
||||||
|
import { useSession } from './session'
|
||||||
|
|
||||||
type WordCounter = {
|
type WordCounter = {
|
||||||
characters: number
|
characters: number
|
||||||
|
@ -82,7 +84,9 @@ export const EditorProvider = (props: { children: JSX.Element }) => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const matchEdit = useMatch(() => '/edit')
|
const matchEdit = useMatch(() => '/edit')
|
||||||
const matchEditSettings = useMatch(() => '/editSettings')
|
const matchEditSettings = useMatch(() => '/editSettings')
|
||||||
const { mutation } = useGraphQL()
|
const { session } = useSession()
|
||||||
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
const { addFeed } = useFeed()
|
const { addFeed } = useFeed()
|
||||||
const snackbar = useSnackbar()
|
const snackbar = useSnackbar()
|
||||||
const [isEditorPanelVisible, setIsEditorPanelVisible] = createSignal<boolean>(false)
|
const [isEditorPanelVisible, setIsEditorPanelVisible] = createSignal<boolean>(false)
|
||||||
|
@ -133,7 +137,7 @@ export const EditorProvider = (props: { children: JSX.Element }) => {
|
||||||
console.error(formToUpdate)
|
console.error(formToUpdate)
|
||||||
return { error: 'not enought data' }
|
return { error: 'not enought data' }
|
||||||
}
|
}
|
||||||
const resp = await mutation(updateShoutQuery, {
|
const resp = await client()?.mutation(updateShoutQuery, {
|
||||||
shout_id: formToUpdate.shoutId,
|
shout_id: formToUpdate.shoutId,
|
||||||
shout_input: {
|
shout_input: {
|
||||||
body: formToUpdate.body,
|
body: formToUpdate.body,
|
||||||
|
@ -235,7 +239,7 @@ export const EditorProvider = (props: { children: JSX.Element }) => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const resp = await mutation(updateShoutQuery, { shout_id, publish: true }).toPromise()
|
const resp = await client()?.mutation(updateShoutQuery, { shout_id, publish: true }).toPromise()
|
||||||
const result = resp?.data?.update_shout
|
const result = resp?.data?.update_shout
|
||||||
if (result) {
|
if (result) {
|
||||||
const { shout: newShout, error } = result
|
const { shout: newShout, error } = result
|
||||||
|
@ -259,7 +263,7 @@ export const EditorProvider = (props: { children: JSX.Element }) => {
|
||||||
|
|
||||||
const deleteShout = async (shout_id: number) => {
|
const deleteShout = async (shout_id: number) => {
|
||||||
try {
|
try {
|
||||||
const resp = await mutation(deleteShoutQuery, { shout_id }).toPromise()
|
const resp = await client()?.mutation(deleteShoutQuery, { shout_id }).toPromise()
|
||||||
return resp?.data?.delete_shout
|
return resp?.data?.delete_shout
|
||||||
} catch {
|
} catch {
|
||||||
snackbar?.showSnackbar({ type: 'error', body: localize?.t('Error') || '' })
|
snackbar?.showSnackbar({ type: 'error', body: localize?.t('Error') || '' })
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { createLazyMemo } from '@solid-primitives/memo'
|
import { createLazyMemo } from '@solid-primitives/memo'
|
||||||
import { makePersisted } from '@solid-primitives/storage'
|
import { makePersisted } from '@solid-primitives/storage'
|
||||||
import { Accessor, JSX, Setter, createContext, createSignal, useContext } from 'solid-js'
|
import { Accessor, JSX, Setter, createContext, createMemo, createSignal, useContext } from 'solid-js'
|
||||||
|
import { coreApiUrl } from '~/config'
|
||||||
import { loadFollowedShouts } from '~/graphql/api/private'
|
import { loadFollowedShouts } from '~/graphql/api/private'
|
||||||
import { loadShoutsSearch as fetchShoutsSearch, getShout, loadShouts } from '~/graphql/api/public'
|
import { loadShoutsSearch as fetchShoutsSearch, getShout, loadShouts } from '~/graphql/api/public'
|
||||||
import {
|
import {
|
||||||
|
@ -10,8 +11,9 @@ import {
|
||||||
Shout,
|
Shout,
|
||||||
Topic
|
Topic
|
||||||
} from '~/graphql/schema/core.gen'
|
} from '~/graphql/schema/core.gen'
|
||||||
|
import { graphqlClientCreate } from '../graphql/client'
|
||||||
import { byStat } from '../lib/sort'
|
import { byStat } from '../lib/sort'
|
||||||
import { useGraphQL } from './graphql'
|
import { useSession } from './session'
|
||||||
|
|
||||||
export const PRERENDERED_ARTICLES_COUNT = 5
|
export const PRERENDERED_ARTICLES_COUNT = 5
|
||||||
export const SHOUTS_PER_PAGE = 20
|
export const SHOUTS_PER_PAGE = 20
|
||||||
|
@ -172,14 +174,16 @@ export const FeedProvider = (props: { children: JSX.Element }) => {
|
||||||
addFeed(result)
|
addFeed(result)
|
||||||
return { hasMore, newShouts: result }
|
return { hasMore, newShouts: result }
|
||||||
}
|
}
|
||||||
const client = useGraphQL()
|
const { session } = useSession()
|
||||||
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
// Load the user's feed based on the provided options and update the articleEntities and sortedFeed state
|
// Load the user's feed based on the provided options and update the articleEntities and sortedFeed state
|
||||||
const loadMyFeed = async (
|
const loadMyFeed = async (
|
||||||
options: LoadShoutsOptions
|
options: LoadShoutsOptions
|
||||||
): Promise<{ hasMore: boolean; newShouts: Shout[] }> => {
|
): Promise<{ hasMore: boolean; newShouts: Shout[] }> => {
|
||||||
if (!options.limit) options.limit = 0
|
if (!options.limit) options.limit = 0
|
||||||
options.limit += 1
|
options.limit += 1
|
||||||
const fetcher = await loadFollowedShouts(client, options)
|
const fetcher = await loadFollowedShouts(client(), options)
|
||||||
const result = (await fetcher()) || []
|
const result = (await fetcher()) || []
|
||||||
const hasMore = result.length === options.limit + 1
|
const hasMore = result.length === options.limit + 1
|
||||||
if (hasMore) result.splice(-1)
|
if (hasMore) result.splice(-1)
|
||||||
|
|
|
@ -10,11 +10,12 @@ import {
|
||||||
} from 'solid-js'
|
} from 'solid-js'
|
||||||
import { createStore } from 'solid-js/store'
|
import { createStore } from 'solid-js/store'
|
||||||
|
|
||||||
|
import { coreApiUrl } from '~/config'
|
||||||
import followMutation from '~/graphql/mutation/core/follow'
|
import followMutation from '~/graphql/mutation/core/follow'
|
||||||
import unfollowMutation from '~/graphql/mutation/core/unfollow'
|
import unfollowMutation from '~/graphql/mutation/core/unfollow'
|
||||||
import loadAuthorFollowers from '~/graphql/query/core/author-followers'
|
import loadAuthorFollowers from '~/graphql/query/core/author-followers'
|
||||||
import { Author, Community, FollowingEntity, Topic } from '~/graphql/schema/core.gen'
|
import { Author, Community, FollowingEntity, Topic } from '~/graphql/schema/core.gen'
|
||||||
import { useGraphQL } from './graphql'
|
import { graphqlClientCreate } from '../graphql/client'
|
||||||
import { useSession } from './session'
|
import { useSession } from './session'
|
||||||
|
|
||||||
export type FollowsFilter = 'all' | 'authors' | 'topics' | 'communities'
|
export type FollowsFilter = 'all' | 'authors' | 'topics' | 'communities'
|
||||||
|
@ -71,14 +72,14 @@ export const FollowingProvider = (props: { children: JSX.Element }) => {
|
||||||
const [follows, setFollows] = createStore<AuthorFollowsResult>(EMPTY_SUBSCRIPTIONS)
|
const [follows, setFollows] = createStore<AuthorFollowsResult>(EMPTY_SUBSCRIPTIONS)
|
||||||
const { session } = useSession()
|
const { session } = useSession()
|
||||||
const authorized = createMemo<boolean>(() => Boolean(session()?.access_token))
|
const authorized = createMemo<boolean>(() => Boolean(session()?.access_token))
|
||||||
const { query, mutation } = useGraphQL()
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
try {
|
try {
|
||||||
if (session()?.access_token) {
|
if (session()?.access_token) {
|
||||||
console.debug('[context.following] fetching subs data...')
|
console.debug('[context.following] fetching subs data...')
|
||||||
const result = await query(loadAuthorFollowers, { user: session()?.user?.id }).toPromise()
|
const result = await client()?.query(loadAuthorFollowers, { user: session()?.user?.id }).toPromise()
|
||||||
if (result) {
|
if (result) {
|
||||||
setFollows((_: AuthorFollowsResult) => {
|
setFollows((_: AuthorFollowsResult) => {
|
||||||
return { ...EMPTY_SUBSCRIPTIONS, ...result } as AuthorFollowsResult
|
return { ...EMPTY_SUBSCRIPTIONS, ...result } as AuthorFollowsResult
|
||||||
|
@ -98,7 +99,7 @@ export const FollowingProvider = (props: { children: JSX.Element }) => {
|
||||||
if (!authorized()) return
|
if (!authorized()) return
|
||||||
setFollowing({ slug, type: 'follow' })
|
setFollowing({ slug, type: 'follow' })
|
||||||
try {
|
try {
|
||||||
const resp = await mutation(followMutation, { what, slug }).toPromise()
|
const resp = await client()?.mutation(followMutation, { what, slug }).toPromise()
|
||||||
const result = resp?.data?.follow
|
const result = resp?.data?.follow
|
||||||
if (!result) return
|
if (!result) return
|
||||||
setFollows((subs) => {
|
setFollows((subs) => {
|
||||||
|
@ -117,7 +118,7 @@ export const FollowingProvider = (props: { children: JSX.Element }) => {
|
||||||
if (!authorized()) return
|
if (!authorized()) return
|
||||||
setFollowing({ slug: slug, type: 'unfollow' })
|
setFollowing({ slug: slug, type: 'unfollow' })
|
||||||
try {
|
try {
|
||||||
const resp = await mutation(unfollowMutation, { what, slug }).toPromise()
|
const resp = await client()?.mutation(unfollowMutation, { what, slug }).toPromise()
|
||||||
const result = resp?.data?.unfollow
|
const result = resp?.data?.unfollow
|
||||||
if (!result) return
|
if (!result) return
|
||||||
setFollows((subs) => {
|
setFollows((subs) => {
|
||||||
|
|
|
@ -1,73 +0,0 @@
|
||||||
import { Client, ClientOptions, cacheExchange, createClient, fetchExchange } from '@urql/core'
|
|
||||||
import { createContext, createEffect, createSignal, on, useContext } from 'solid-js'
|
|
||||||
import { JSX } from 'solid-js/jsx-runtime'
|
|
||||||
import { chatApiUrl, coreApiUrl } from '../config'
|
|
||||||
import { useSession } from './session'
|
|
||||||
|
|
||||||
type GraphQLClientContextType = Record<string, Client>
|
|
||||||
|
|
||||||
const GraphQLClientContext = createContext<GraphQLClientContextType>({} as GraphQLClientContextType)
|
|
||||||
|
|
||||||
// Function to create a GraphQL client based on the provided URL and token
|
|
||||||
const graphqlClientCreate = (url: string, token = ''): Client => {
|
|
||||||
const exchanges = [fetchExchange, cacheExchange]
|
|
||||||
const options: ClientOptions = {
|
|
||||||
url,
|
|
||||||
exchanges
|
|
||||||
}
|
|
||||||
|
|
||||||
if (token) {
|
|
||||||
options.fetchOptions = () => ({
|
|
||||||
headers: {
|
|
||||||
'content-type': 'application/json',
|
|
||||||
authorization: token
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return createClient(options)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const defaultClient = graphqlClientCreate(coreApiUrl)
|
|
||||||
|
|
||||||
export const GraphQLClientProvider = (props: { children?: JSX.Element }) => {
|
|
||||||
const { session } = useSession()
|
|
||||||
const [clients, setClients] = createSignal<GraphQLClientContextType>({ [coreApiUrl]: defaultClient })
|
|
||||||
|
|
||||||
createEffect(
|
|
||||||
on(
|
|
||||||
() => session?.()?.access_token || '',
|
|
||||||
(tkn: string) => {
|
|
||||||
if (tkn) {
|
|
||||||
console.info('[context.graphql] authorized client')
|
|
||||||
setClients(() => ({
|
|
||||||
[coreApiUrl]: graphqlClientCreate(coreApiUrl, tkn),
|
|
||||||
[chatApiUrl]: graphqlClientCreate(chatApiUrl, tkn)
|
|
||||||
}))
|
|
||||||
} else {
|
|
||||||
console.info('[context.graphql] can fetch data')
|
|
||||||
setClients(() => ({
|
|
||||||
[coreApiUrl]: defaultClient
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ defer: true }
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return <GraphQLClientContext.Provider value={clients()}>{props.children}</GraphQLClientContext.Provider>
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useGraphQL = (url: string = coreApiUrl) => {
|
|
||||||
const clients = useContext(GraphQLClientContext)
|
|
||||||
let c = clients[coreApiUrl]
|
|
||||||
if (url !== coreApiUrl) {
|
|
||||||
try {
|
|
||||||
c = clients[url]
|
|
||||||
} catch (_e) {
|
|
||||||
// pass
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!c) c = clients[coreApiUrl]
|
|
||||||
return c
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
import type { Accessor, JSX } from 'solid-js'
|
import type { Accessor, JSX } from 'solid-js'
|
||||||
import { createContext, createSignal, useContext } from 'solid-js'
|
import { createContext, createMemo, createSignal, useContext } from 'solid-js'
|
||||||
import { chatApiUrl } from '~/config'
|
import { chatApiUrl } from '~/config'
|
||||||
import { useGraphQL } from '~/context/graphql'
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import createChatMutation from '~/graphql/mutation/chat/chat-create'
|
import createChatMutation from '~/graphql/mutation/chat/chat-create'
|
||||||
import createMessageMutation from '~/graphql/mutation/chat/chat-message-create'
|
import createMessageMutation from '~/graphql/mutation/chat/chat-message-create'
|
||||||
import loadChatMessagesQuery from '~/graphql/query/chat/chat-messages-load-by'
|
import loadChatMessagesQuery from '~/graphql/query/chat/chat-messages-load-by'
|
||||||
|
@ -10,6 +10,7 @@ import type { Chat, Message, MessagesBy, MutationCreate_MessageArgs } from '~/gr
|
||||||
import { Author } from '~/graphql/schema/core.gen'
|
import { Author } from '~/graphql/schema/core.gen'
|
||||||
import { useAuthors } from '../context/authors'
|
import { useAuthors } from '../context/authors'
|
||||||
import { SSEMessage, useConnect } from './connect'
|
import { SSEMessage, useConnect } from './connect'
|
||||||
|
import { useSession } from './session'
|
||||||
|
|
||||||
type InboxContextType = {
|
type InboxContextType = {
|
||||||
chats: Accessor<Chat[]>
|
chats: Accessor<Chat[]>
|
||||||
|
@ -37,7 +38,8 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
|
||||||
const [chats, setChats] = createSignal<Chat[]>([])
|
const [chats, setChats] = createSignal<Chat[]>([])
|
||||||
const [messages, setMessages] = createSignal<Message[]>([])
|
const [messages, setMessages] = createSignal<Message[]>([])
|
||||||
const { authorsSorted } = useAuthors()
|
const { authorsSorted } = useAuthors()
|
||||||
const { query, mutation } = useGraphQL(chatApiUrl)
|
const { session } = useSession()
|
||||||
|
const client = createMemo(() => graphqlClientCreate(chatApiUrl, session()?.access_token))
|
||||||
|
|
||||||
const handleMessage = (sseMessage: SSEMessage) => {
|
const handleMessage = (sseMessage: SSEMessage) => {
|
||||||
// handling all action types: create update delete join left seen
|
// handling all action types: create update delete join left seen
|
||||||
|
@ -56,13 +58,13 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
|
||||||
addHandler(handleMessage)
|
addHandler(handleMessage)
|
||||||
|
|
||||||
const loadMessages = async (by: MessagesBy, limit = 50, offset = 0): Promise<Message[]> => {
|
const loadMessages = async (by: MessagesBy, limit = 50, offset = 0): Promise<Message[]> => {
|
||||||
const resp = await query(loadChatMessagesQuery, { by, limit, offset })
|
const resp = await client()?.query(loadChatMessagesQuery, { by, limit, offset })
|
||||||
const result = resp?.data?.load_chat_messages || []
|
const result = resp?.data?.load_chat_messages || []
|
||||||
setMessages((mmm) => [...new Set([...mmm, ...result])])
|
setMessages((mmm) => [...new Set([...mmm, ...result])])
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
const loadChats = async () => {
|
const loadChats = async () => {
|
||||||
const resp = await query(loadChatsQuery, { limit: 50, offset: 0 }).toPromise()
|
const resp = await client()?.query(loadChatsQuery, { limit: 50, offset: 0 }).toPromise()
|
||||||
const result = resp?.data?.load_chats || []
|
const result = resp?.data?.load_chats || []
|
||||||
setChats(result)
|
setChats(result)
|
||||||
return result
|
return result
|
||||||
|
@ -81,7 +83,7 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendMessage = async (args: MutationCreate_MessageArgs) => {
|
const sendMessage = async (args: MutationCreate_MessageArgs) => {
|
||||||
const resp = await mutation(createMessageMutation, args).toPromise()
|
const resp = await client()?.mutation(createMessageMutation, args).toPromise()
|
||||||
const result = resp?.data?.create_message
|
const result = resp?.data?.create_message
|
||||||
if (result) {
|
if (result) {
|
||||||
const { message, error } = result
|
const { message, error } = result
|
||||||
|
@ -100,7 +102,7 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
|
||||||
|
|
||||||
const createChat = async (members: number[], title: string) => {
|
const createChat = async (members: number[], title: string) => {
|
||||||
try {
|
try {
|
||||||
const resp = await mutation(createChatMutation, { members, title }).toPromise()
|
const resp = await client()?.mutation(createChatMutation, { members, title }).toPromise()
|
||||||
const result = resp?.data?.create_chat
|
const result = resp?.data?.create_chat
|
||||||
if (result) {
|
if (result) {
|
||||||
const { chat, error } = result
|
const { chat, error } = result
|
||||||
|
|
|
@ -5,6 +5,8 @@ import { createContext, createMemo, createSignal, onMount, useContext } from 'so
|
||||||
import { createStore } from 'solid-js/store'
|
import { createStore } from 'solid-js/store'
|
||||||
import { Portal } from 'solid-js/web'
|
import { Portal } from 'solid-js/web'
|
||||||
|
|
||||||
|
import { coreApiUrl } from '~/config'
|
||||||
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import markSeenMutation from '~/graphql/mutation/notifier/mark-seen'
|
import markSeenMutation from '~/graphql/mutation/notifier/mark-seen'
|
||||||
import markSeenAfterMutation from '~/graphql/mutation/notifier/mark-seen-after'
|
import markSeenAfterMutation from '~/graphql/mutation/notifier/mark-seen-after'
|
||||||
import markSeenThreadMutation from '~/graphql/mutation/notifier/mark-seen-thread'
|
import markSeenThreadMutation from '~/graphql/mutation/notifier/mark-seen-thread'
|
||||||
|
@ -13,7 +15,6 @@ import { NotificationGroup, QueryLoad_NotificationsArgs } from '~/graphql/schema
|
||||||
import { NotificationsPanel } from '../components/NotificationsPanel'
|
import { NotificationsPanel } from '../components/NotificationsPanel'
|
||||||
import { ShowIfAuthenticated } from '../components/_shared/ShowIfAuthenticated'
|
import { ShowIfAuthenticated } from '../components/_shared/ShowIfAuthenticated'
|
||||||
import { SSEMessage, useConnect } from './connect'
|
import { SSEMessage, useConnect } from './connect'
|
||||||
import { useGraphQL } from './graphql'
|
|
||||||
import { useSession } from './session'
|
import { useSession } from './session'
|
||||||
|
|
||||||
type NotificationsContextType = {
|
type NotificationsContextType = {
|
||||||
|
@ -49,11 +50,11 @@ export const NotificationsProvider = (props: { children: JSX.Element }) => {
|
||||||
const { session } = useSession()
|
const { session } = useSession()
|
||||||
const authorized = createMemo<boolean>(() => Boolean(session()?.access_token))
|
const authorized = createMemo<boolean>(() => Boolean(session()?.access_token))
|
||||||
const { addHandler } = useConnect()
|
const { addHandler } = useConnect()
|
||||||
const { query, mutation } = useGraphQL()
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
const loadNotificationsGrouped = async (options: QueryLoad_NotificationsArgs) => {
|
const loadNotificationsGrouped = async (options: QueryLoad_NotificationsArgs) => {
|
||||||
if (authorized()) {
|
if (authorized()) {
|
||||||
const resp = await query(getNotifications, options).toPromise()
|
const resp = await client()?.query(getNotifications, options).toPromise()
|
||||||
const result = resp?.data?.get_notifications
|
const result = resp?.data?.get_notifications
|
||||||
const groups = result?.notifications || []
|
const groups = result?.notifications || []
|
||||||
const total = result?.total || 0
|
const total = result?.total || 0
|
||||||
|
@ -98,7 +99,7 @@ export const NotificationsProvider = (props: { children: JSX.Element }) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const markSeenThread = async (threadId: string) => {
|
const markSeenThread = async (threadId: string) => {
|
||||||
await mutation(markSeenThreadMutation, { threadId }).toPromise()
|
await client()?.mutation(markSeenThreadMutation, { threadId }).toPromise()
|
||||||
const thread = notificationEntities[threadId]
|
const thread = notificationEntities[threadId]
|
||||||
thread.seen = true
|
thread.seen = true
|
||||||
setNotificationEntities((nnn) => ({ ...nnn, [threadId]: thread }))
|
setNotificationEntities((nnn) => ({ ...nnn, [threadId]: thread }))
|
||||||
|
@ -107,14 +108,14 @@ export const NotificationsProvider = (props: { children: JSX.Element }) => {
|
||||||
|
|
||||||
const markSeenAll = async () => {
|
const markSeenAll = async () => {
|
||||||
if (authorized()) {
|
if (authorized()) {
|
||||||
const _resp = await mutation(markSeenAfterMutation, { after: after() }).toPromise()
|
const _resp = await client()?.mutation(markSeenAfterMutation, { after: after() }).toPromise()
|
||||||
await loadNotificationsGrouped({ after: after() || now, limit: loadedNotificationsCount() })
|
await loadNotificationsGrouped({ after: after() || now, limit: loadedNotificationsCount() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const markSeen = async (notification_id: number) => {
|
const markSeen = async (notification_id: number) => {
|
||||||
if (authorized()) {
|
if (authorized()) {
|
||||||
await mutation(markSeenMutation, { notification_id }).toPromise()
|
await client()?.mutation(markSeenMutation, { notification_id }).toPromise()
|
||||||
await loadNotificationsGrouped({ after: after() || now, limit: loadedNotificationsCount() })
|
await loadNotificationsGrouped({ after: after() || now, limit: loadedNotificationsCount() })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,21 @@
|
||||||
import type { Author, ProfileInput } from '~/graphql/schema/core.gen'
|
import type { Author, ProfileInput } from '~/graphql/schema/core.gen'
|
||||||
|
|
||||||
import { AuthToken } from '@authorizerdev/authorizer-js'
|
import { AuthToken } from '@authorizerdev/authorizer-js'
|
||||||
import { Accessor, JSX, createContext, createEffect, createSignal, on, useContext } from 'solid-js'
|
import {
|
||||||
|
Accessor,
|
||||||
|
JSX,
|
||||||
|
createContext,
|
||||||
|
createEffect,
|
||||||
|
createMemo,
|
||||||
|
createSignal,
|
||||||
|
on,
|
||||||
|
useContext
|
||||||
|
} from 'solid-js'
|
||||||
import { createStore } from 'solid-js/store'
|
import { createStore } from 'solid-js/store'
|
||||||
|
import { coreApiUrl } from '~/config'
|
||||||
import updateAuthorMuatation from '~/graphql/mutation/core/author-update'
|
import updateAuthorMuatation from '~/graphql/mutation/core/author-update'
|
||||||
|
import { graphqlClientCreate } from '../graphql/client'
|
||||||
import { useAuthors } from './authors'
|
import { useAuthors } from './authors'
|
||||||
import { useGraphQL } from './graphql'
|
|
||||||
import { useSession } from './session'
|
import { useSession } from './session'
|
||||||
|
|
||||||
type ProfileContextType = {
|
type ProfileContextType = {
|
||||||
|
@ -32,7 +42,7 @@ const userpicUrl = (userpic: string) => {
|
||||||
|
|
||||||
export const ProfileProvider = (props: { children: JSX.Element }) => {
|
export const ProfileProvider = (props: { children: JSX.Element }) => {
|
||||||
const { session } = useSession()
|
const { session } = useSession()
|
||||||
const { mutation } = useGraphQL()
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
const { addAuthor } = useAuthors()
|
const { addAuthor } = useAuthors()
|
||||||
const [form, setForm] = createStore<ProfileInput>({} as ProfileInput)
|
const [form, setForm] = createStore<ProfileInput>({} as ProfileInput)
|
||||||
const [author, setAuthor] = createSignal<Author>({} as Author)
|
const [author, setAuthor] = createSignal<Author>({} as Author)
|
||||||
|
@ -55,7 +65,7 @@ export const ProfileProvider = (props: { children: JSX.Element }) => {
|
||||||
)
|
)
|
||||||
|
|
||||||
const submit = async (profile: ProfileInput) => {
|
const submit = async (profile: ProfileInput) => {
|
||||||
const response = await mutation(updateAuthorMuatation, profile).toPromise()
|
const response = await client()?.mutation(updateAuthorMuatation, profile).toPromise()
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error(response.error)
|
console.error(response.error)
|
||||||
throw response.error
|
throw response.error
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import type { JSX } from 'solid-js'
|
import type { JSX } from 'solid-js'
|
||||||
|
|
||||||
import { createContext, onCleanup, useContext } from 'solid-js'
|
import { createContext, createMemo, onCleanup, useContext } from 'solid-js'
|
||||||
import { createStore, reconcile } from 'solid-js/store'
|
import { createStore, reconcile } from 'solid-js/store'
|
||||||
|
import { coreApiUrl } from '~/config'
|
||||||
import { loadReactions } from '~/graphql/api/public'
|
import { loadReactions } from '~/graphql/api/public'
|
||||||
import createReactionMutation from '~/graphql/mutation/core/reaction-create'
|
import createReactionMutation from '~/graphql/mutation/core/reaction-create'
|
||||||
import destroyReactionMutation from '~/graphql/mutation/core/reaction-destroy'
|
import destroyReactionMutation from '~/graphql/mutation/core/reaction-destroy'
|
||||||
|
@ -13,8 +14,9 @@ import {
|
||||||
Reaction,
|
Reaction,
|
||||||
ReactionKind
|
ReactionKind
|
||||||
} from '~/graphql/schema/core.gen'
|
} from '~/graphql/schema/core.gen'
|
||||||
import { useGraphQL } from './graphql'
|
import { graphqlClientCreate } from '../graphql/client'
|
||||||
import { useLocalize } from './localize'
|
import { useLocalize } from './localize'
|
||||||
|
import { useSession } from './session'
|
||||||
import { useSnackbar } from './ui'
|
import { useSnackbar } from './ui'
|
||||||
|
|
||||||
type ReactionsContextType = {
|
type ReactionsContextType = {
|
||||||
|
@ -38,7 +40,9 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => {
|
||||||
const [reactionsByShout, setReactionsByShout] = createStore<Record<number, Reaction[]>>({})
|
const [reactionsByShout, setReactionsByShout] = createStore<Record<number, Reaction[]>>({})
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
const { showSnackbar } = useSnackbar()
|
const { showSnackbar } = useSnackbar()
|
||||||
const { mutation } = useGraphQL()
|
const { session } = useSession()
|
||||||
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
const addReactions = (rrr: Reaction[]) => {
|
const addReactions = (rrr: Reaction[]) => {
|
||||||
const newReactionsByShout: Record<string, Reaction[]> = { ...reactionsByShout }
|
const newReactionsByShout: Record<string, Reaction[]> = { ...reactionsByShout }
|
||||||
const newReactionEntities = rrr.reduce(
|
const newReactionEntities = rrr.reduce(
|
||||||
|
@ -64,7 +68,7 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const createReaction = async (input: MutationCreate_ReactionArgs): Promise<void> => {
|
const createReaction = async (input: MutationCreate_ReactionArgs): Promise<void> => {
|
||||||
const resp = await mutation(createReactionMutation, input).toPromise()
|
const resp = await client()?.mutation(createReactionMutation, input).toPromise()
|
||||||
const { error, reaction } = resp?.data?.create_reaction || {}
|
const { error, reaction } = resp?.data?.create_reaction || {}
|
||||||
if (error) await showSnackbar({ type: 'error', body: t(error) })
|
if (error) await showSnackbar({ type: 'error', body: t(error) })
|
||||||
if (!reaction) return
|
if (!reaction) return
|
||||||
|
@ -96,7 +100,7 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => {
|
||||||
reaction_id: number
|
reaction_id: number
|
||||||
): Promise<{ error: string; reaction?: string } | null> => {
|
): Promise<{ error: string; reaction?: string } | null> => {
|
||||||
if (reaction_id) {
|
if (reaction_id) {
|
||||||
const resp = await mutation(destroyReactionMutation, { reaction_id }).toPromise()
|
const resp = await client()?.mutation(destroyReactionMutation, { reaction_id }).toPromise()
|
||||||
const result = resp?.data?.destroy_reaction
|
const result = resp?.data?.destroy_reaction
|
||||||
if (!result.error) {
|
if (!result.error) {
|
||||||
setReactionEntities({
|
setReactionEntities({
|
||||||
|
@ -109,7 +113,7 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateReaction = async (input: MutationUpdate_ReactionArgs): Promise<Reaction> => {
|
const updateReaction = async (input: MutationUpdate_ReactionArgs): Promise<Reaction> => {
|
||||||
const resp = await mutation(updateReactionMutation, input).toPromise()
|
const resp = await client()?.mutation(updateReactionMutation, input).toPromise()
|
||||||
const result = resp?.data?.update_reaction
|
const result = resp?.data?.update_reaction
|
||||||
if (!result) throw new Error('cannot update reaction')
|
if (!result) throw new Error('cannot update reaction')
|
||||||
const { error, reaction } = result
|
const { error, reaction } = result
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { cache } from '@solidjs/router'
|
import { cache } from '@solidjs/router'
|
||||||
import { defaultClient } from '~/context/graphql'
|
import { defaultClient } from '~/graphql/client'
|
||||||
import getShoutQuery from '~/graphql/query/core/article-load'
|
import getShoutQuery from '~/graphql/query/core/article-load'
|
||||||
import loadShoutsByQuery from '~/graphql/query/core/articles-load-by'
|
import loadShoutsByQuery from '~/graphql/query/core/articles-load-by'
|
||||||
import loadShoutsSearchQuery from '~/graphql/query/core/articles-load-search'
|
import loadShoutsSearchQuery from '~/graphql/query/core/articles-load-search'
|
||||||
|
|
24
src/graphql/client.ts
Normal file
24
src/graphql/client.ts
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { Client, ClientOptions, cacheExchange, createClient, fetchExchange } from '@urql/core'
|
||||||
|
import { coreApiUrl } from '~/config'
|
||||||
|
|
||||||
|
// Функция для создания GraphQL клиента с заданным URL и токеном
|
||||||
|
export const graphqlClientCreate = (url: string, token = ''): Client => {
|
||||||
|
const exchanges = [fetchExchange, cacheExchange]
|
||||||
|
const options: ClientOptions = {
|
||||||
|
url,
|
||||||
|
exchanges
|
||||||
|
}
|
||||||
|
|
||||||
|
if (token) {
|
||||||
|
options.fetchOptions = () => ({
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/json',
|
||||||
|
authorization: token
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return createClient(options)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const defaultClient = graphqlClientCreate(coreApiUrl)
|
|
@ -16,6 +16,7 @@ import AuthorPage, { AuthorPageProps } from '../author/[slug]/[...tab]'
|
||||||
import TopicPage, { TopicPageProps } from '../topic/[slug]/[...tab]'
|
import TopicPage, { TopicPageProps } from '../topic/[slug]/[...tab]'
|
||||||
|
|
||||||
const fetchShout = async (slug: string): Promise<Shout | undefined> => {
|
const fetchShout = async (slug: string): Promise<Shout | undefined> => {
|
||||||
|
if (slug.startsWith('@')) return
|
||||||
const shoutLoader = getShout({ slug })
|
const shoutLoader = getShout({ slug })
|
||||||
const result = await shoutLoader()
|
const result = await shoutLoader()
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { RouteSectionProps } from '@solidjs/router'
|
import { RouteSectionProps } from '@solidjs/router'
|
||||||
import { ErrorBoundary, createEffect, createMemo, createSignal, on } from 'solid-js'
|
import { ErrorBoundary, Suspense, createEffect, createMemo, createSignal, on } from 'solid-js'
|
||||||
import { AuthorView } from '~/components/Views/Author'
|
import { AuthorView } from '~/components/Views/Author'
|
||||||
import { FourOuFourView } from '~/components/Views/FourOuFour'
|
import { FourOuFourView } from '~/components/Views/FourOuFour'
|
||||||
import { LoadMoreItems, LoadMoreWrapper } from '~/components/_shared/LoadMoreWrapper'
|
import { LoadMoreItems, LoadMoreWrapper } from '~/components/_shared/LoadMoreWrapper'
|
||||||
|
import { Loading } from '~/components/_shared/Loading'
|
||||||
import { PageLayout } from '~/components/_shared/PageLayout'
|
import { PageLayout } from '~/components/_shared/PageLayout'
|
||||||
import { useAuthors } from '~/context/authors'
|
import { useAuthors } from '~/context/authors'
|
||||||
import { SHOUTS_PER_PAGE, useFeed } from '~/context/feed'
|
import { SHOUTS_PER_PAGE, useFeed } from '~/context/feed'
|
||||||
|
@ -100,6 +101,7 @@ export default function AuthorPage(props: RouteSectionProps<AuthorPageProps>) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ErrorBoundary fallback={(_err) => <FourOuFourView />}>
|
<ErrorBoundary fallback={(_err) => <FourOuFourView />}>
|
||||||
|
<Suspense fallback={<Loading />}>
|
||||||
<PageLayout
|
<PageLayout
|
||||||
title={`${t('Discours')} :: ${title()}`}
|
title={`${t('Discours')} :: ${title()}`}
|
||||||
headerTitle={author()?.name || ''}
|
headerTitle={author()?.name || ''}
|
||||||
|
@ -118,6 +120,7 @@ export default function AuthorPage(props: RouteSectionProps<AuthorPageProps>) {
|
||||||
</LoadMoreWrapper>
|
</LoadMoreWrapper>
|
||||||
</ReactionsProvider>
|
</ReactionsProvider>
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
|
</Suspense>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
import { createAsync } from '@solidjs/router'
|
import { createAsync } from '@solidjs/router'
|
||||||
import { Client } from '@urql/core'
|
import { Client } from '@urql/core'
|
||||||
|
import { createMemo } from 'solid-js'
|
||||||
import { AuthGuard } from '~/components/AuthGuard'
|
import { AuthGuard } from '~/components/AuthGuard'
|
||||||
import { DraftsView } from '~/components/Views/DraftsView'
|
import { DraftsView } from '~/components/Views/DraftsView'
|
||||||
import { PageLayout } from '~/components/_shared/PageLayout'
|
import { PageLayout } from '~/components/_shared/PageLayout'
|
||||||
import { useGraphQL } from '~/context/graphql'
|
import { coreApiUrl } from '~/config'
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
|
import { useSession } from '~/context/session'
|
||||||
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import getDraftsQuery from '~/graphql/query/core/articles-load-drafts'
|
import getDraftsQuery from '~/graphql/query/core/articles-load-drafts'
|
||||||
import { Shout } from '~/graphql/schema/core.gen'
|
import { Shout } from '~/graphql/schema/core.gen'
|
||||||
|
|
||||||
|
@ -16,8 +19,9 @@ const fetchDrafts = async (client: Client) => {
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
const client = useGraphQL()
|
const { session } = useSession()
|
||||||
const drafts = createAsync(async () => await fetchDrafts(client))
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
const drafts = createAsync(async () => await fetchDrafts(client()))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageLayout title={`${t('Discours')} :: ${t('Drafts')}`}>
|
<PageLayout title={`${t('Discours')} :: ${t('Drafts')}`}>
|
||||||
|
|
|
@ -2,10 +2,11 @@ import { RouteSectionProps, redirect } from '@solidjs/router'
|
||||||
import { createEffect, createMemo, createSignal, lazy, on } from 'solid-js'
|
import { createEffect, createMemo, createSignal, lazy, on } from 'solid-js'
|
||||||
import { AuthGuard } from '~/components/AuthGuard'
|
import { AuthGuard } from '~/components/AuthGuard'
|
||||||
import { PageLayout } from '~/components/_shared/PageLayout'
|
import { PageLayout } from '~/components/_shared/PageLayout'
|
||||||
import { useGraphQL } from '~/context/graphql'
|
import { coreApiUrl } from '~/config'
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
import { useSession } from '~/context/session'
|
import { useSession } from '~/context/session'
|
||||||
import { useSnackbar } from '~/context/ui'
|
import { useSnackbar } from '~/context/ui'
|
||||||
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import getShoutDraft from '~/graphql/query/core/article-my'
|
import getShoutDraft from '~/graphql/query/core/article-my'
|
||||||
import { Shout } from '~/graphql/schema/core.gen'
|
import { Shout } from '~/graphql/schema/core.gen'
|
||||||
import { LayoutType } from '~/types/common'
|
import { LayoutType } from '~/types/common'
|
||||||
|
@ -38,12 +39,12 @@ export default (props: RouteSectionProps) => {
|
||||||
redirect('/edit') // all drafts page
|
redirect('/edit') // all drafts page
|
||||||
}
|
}
|
||||||
const [shout, setShout] = createSignal<Shout>()
|
const [shout, setShout] = createSignal<Shout>()
|
||||||
const client = useGraphQL()
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
createEffect(on(session, (s) => s?.access_token && loadDraft(), { defer: true }))
|
createEffect(on(session, (s) => s?.access_token && loadDraft(), { defer: true }))
|
||||||
|
|
||||||
const loadDraft = async () => {
|
const loadDraft = async () => {
|
||||||
const result = await client.query(getShoutDraft, { shout_id: props.params.id }).toPromise()
|
const result = await client()?.query(getShoutDraft, { shout_id: props.params.id }).toPromise()
|
||||||
if (result) {
|
if (result) {
|
||||||
const { shout: loadedShout, error } = result.data.get_my_shout
|
const { shout: loadedShout, error } = result.data.get_my_shout
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
|
@ -1,22 +1,23 @@
|
||||||
import { RouteSectionProps } from '@solidjs/router'
|
import { RouteSectionProps } from '@solidjs/router'
|
||||||
import { createEffect, createSignal, on } from 'solid-js'
|
import { createEffect, createMemo, createSignal, on } from 'solid-js'
|
||||||
import { AuthGuard } from '~/components/AuthGuard'
|
import { AuthGuard } from '~/components/AuthGuard'
|
||||||
import EditSettingsView from '~/components/Views/EditView/EditSettingsView'
|
import EditSettingsView from '~/components/Views/EditView/EditSettingsView'
|
||||||
import { PageLayout } from '~/components/_shared/PageLayout'
|
import { PageLayout } from '~/components/_shared/PageLayout'
|
||||||
import { useGraphQL } from '~/context/graphql'
|
import { coreApiUrl } from '~/config'
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
import { useSession } from '~/context/session'
|
import { useSession } from '~/context/session'
|
||||||
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import getShoutDraft from '~/graphql/query/core/article-my'
|
import getShoutDraft from '~/graphql/query/core/article-my'
|
||||||
import { Shout } from '~/graphql/schema/core.gen'
|
import { Shout } from '~/graphql/schema/core.gen'
|
||||||
|
|
||||||
export default (props: RouteSectionProps) => {
|
export default (props: RouteSectionProps) => {
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
const client = useGraphQL()
|
|
||||||
const { session } = useSession()
|
const { session } = useSession()
|
||||||
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
createEffect(on(session, (s) => s?.access_token && loadDraft(), { defer: true }))
|
createEffect(on(session, (s) => s?.access_token && loadDraft(), { defer: true }))
|
||||||
const [shout, setShout] = createSignal<Shout>()
|
const [shout, setShout] = createSignal<Shout>()
|
||||||
const loadDraft = async () => {
|
const loadDraft = async () => {
|
||||||
const result = await client.query(getShoutDraft, { shout_id: props.params.id }).toPromise()
|
const result = await client()?.query(getShoutDraft, { shout_id: props.params.id }).toPromise()
|
||||||
if (result) {
|
if (result) {
|
||||||
const { shout: loadedShout, error } = result.data.get_my_shout
|
const { shout: loadedShout, error } = result.data.get_my_shout
|
||||||
if (error) throw new Error(error)
|
if (error) throw new Error(error)
|
||||||
|
|
|
@ -1,25 +1,31 @@
|
||||||
import { useNavigate } from '@solidjs/router'
|
import { useNavigate } from '@solidjs/router'
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import { For } from 'solid-js'
|
import { For, createMemo } from 'solid-js'
|
||||||
import { AuthGuard } from '~/components/AuthGuard'
|
import { AuthGuard } from '~/components/AuthGuard'
|
||||||
import { Button } from '~/components/_shared/Button'
|
import { Button } from '~/components/_shared/Button'
|
||||||
import { Icon } from '~/components/_shared/Icon'
|
import { Icon } from '~/components/_shared/Icon'
|
||||||
import { PageLayout } from '~/components/_shared/PageLayout'
|
import { PageLayout } from '~/components/_shared/PageLayout'
|
||||||
import { useGraphQL } from '~/context/graphql'
|
import { coreApiUrl } from '~/config'
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
|
import { useSession } from '~/context/session'
|
||||||
import { useSnackbar } from '~/context/ui'
|
import { useSnackbar } from '~/context/ui'
|
||||||
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import createShoutMutation from '~/graphql/mutation/core/article-create'
|
import createShoutMutation from '~/graphql/mutation/core/article-create'
|
||||||
import styles from '~/styles/Create.module.scss'
|
import styles from '~/styles/Create.module.scss'
|
||||||
import { LayoutType } from '~/types/common'
|
import { LayoutType } from '~/types/common'
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
const client = useGraphQL()
|
const { session } = useSession()
|
||||||
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
const { showSnackbar } = useSnackbar()
|
const { showSnackbar } = useSnackbar()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const handleCreate = async (layout: LayoutType) => {
|
const handleCreate = async (layout: LayoutType) => {
|
||||||
console.debug('[routes : edit/new] handling create click...')
|
console.debug('[routes : edit/new] handling create click...')
|
||||||
const result = await client.mutation(createShoutMutation, { shout: { layout: layout } }).toPromise()
|
const result = await client()
|
||||||
|
?.mutation(createShoutMutation, { shout: { layout: layout } })
|
||||||
|
.toPromise()
|
||||||
if (result) {
|
if (result) {
|
||||||
console.debug(result)
|
console.debug(result)
|
||||||
const { shout, error } = result.data.create_shout
|
const { shout, error } = result.data.create_shout
|
||||||
|
|
|
@ -5,10 +5,11 @@ import { Feed } from '~/components/Views/Feed'
|
||||||
import { FeedProps } from '~/components/Views/Feed/Feed'
|
import { FeedProps } from '~/components/Views/Feed/Feed'
|
||||||
import { LoadMoreItems, LoadMoreWrapper } from '~/components/_shared/LoadMoreWrapper'
|
import { LoadMoreItems, LoadMoreWrapper } from '~/components/_shared/LoadMoreWrapper'
|
||||||
import { PageLayout } from '~/components/_shared/PageLayout'
|
import { PageLayout } from '~/components/_shared/PageLayout'
|
||||||
|
import { coreApiUrl } from '~/config'
|
||||||
import { useFeed } from '~/context/feed'
|
import { useFeed } from '~/context/feed'
|
||||||
import { useGraphQL } from '~/context/graphql'
|
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
import { ReactionsProvider } from '~/context/reactions'
|
import { ReactionsProvider } from '~/context/reactions'
|
||||||
|
import { useSession } from '~/context/session'
|
||||||
import { useTopics } from '~/context/topics'
|
import { useTopics } from '~/context/topics'
|
||||||
import {
|
import {
|
||||||
loadCoauthoredShouts,
|
loadCoauthoredShouts,
|
||||||
|
@ -16,6 +17,7 @@ import {
|
||||||
loadFollowedShouts,
|
loadFollowedShouts,
|
||||||
loadUnratedShouts
|
loadUnratedShouts
|
||||||
} from '~/graphql/api/private'
|
} from '~/graphql/api/private'
|
||||||
|
import { graphqlClientCreate } from '~/graphql/client'
|
||||||
import { LoadShoutsOptions, Shout, Topic } from '~/graphql/schema/core.gen'
|
import { LoadShoutsOptions, Shout, Topic } from '~/graphql/schema/core.gen'
|
||||||
|
|
||||||
const feeds = {
|
const feeds = {
|
||||||
|
@ -54,8 +56,8 @@ export default (props: RouteSectionProps<{ shouts: Shout[]; topics: Topic[] }>)
|
||||||
const [searchParams] = useSearchParams<FeedSearchParams>() // ?period=month
|
const [searchParams] = useSearchParams<FeedSearchParams>() // ?period=month
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
const { setFeed, feed } = useFeed()
|
const { setFeed, feed } = useFeed()
|
||||||
// TODO: use const { requireAuthentication } = useSession()
|
const { session } = useSession()
|
||||||
const client = useGraphQL()
|
const client = createMemo(() => graphqlClientCreate(coreApiUrl, session()?.access_token))
|
||||||
|
|
||||||
// preload all topics
|
// preload all topics
|
||||||
const { addTopics, sortedTopics } = useTopics()
|
const { addTopics, sortedTopics } = useTopics()
|
||||||
|
@ -97,7 +99,7 @@ export default (props: RouteSectionProps<{ shouts: Shout[]; topics: Topic[] }>)
|
||||||
options.filters = { after: getFromDate(period as FeedPeriod) }
|
options.filters = { after: getFromDate(period as FeedPeriod) }
|
||||||
}
|
}
|
||||||
|
|
||||||
const shoutsLoader = gqlHandler(client, options)
|
const shoutsLoader = gqlHandler(client(), options)
|
||||||
const loaded = await shoutsLoader()
|
const loaded = await shoutsLoader()
|
||||||
loaded && setFeed((prev: Shout[]) => [...prev, ...loaded])
|
loaded && setFeed((prev: Shout[]) => [...prev, ...loaded])
|
||||||
return loaded as LoadMoreItems
|
return loaded as LoadMoreItems
|
||||||
|
|
Loading…
Reference in New Issue
Block a user