drafts-reload-session

This commit is contained in:
Untone 2024-05-06 21:16:13 +03:00
parent 6e8b6043d7
commit 3ce53728ea
3 changed files with 44 additions and 37 deletions

View File

@ -13,16 +13,20 @@ import { Loading } from '../../_shared/Loading'
import styles from './DraftsView.module.scss' import styles from './DraftsView.module.scss'
export const DraftsView = () => { export const DraftsView = () => {
const { session } = useSession() const { author, loadSession } = useSession()
const [drafts, setDrafts] = createSignal<Shout[]>([]) const [drafts, setDrafts] = createSignal<Shout[]>([])
createEffect( createEffect(
on( on(
() => session(), () => author(),
async (s) => { async (a) => {
if (s) { if (a) {
const loadedDrafts = await apiClient.getDrafts() const { shouts: loadedDrafts, error } = await apiClient.getDrafts()
setDrafts(loadedDrafts.reverse() || []) if (error) {
console.warn(error)
await loadSession()
}
setDrafts(loadedDrafts || [])
} }
}, },
), ),
@ -46,7 +50,7 @@ export const DraftsView = () => {
return ( return (
<div class={clsx(styles.DraftsView)}> <div class={clsx(styles.DraftsView)}>
<Show when={session()?.user?.id} fallback={<Loading />}> <Show when={author()?.id} fallback={<Loading />}>
<div class="wide-container"> <div class="wide-container">
<div class="row"> <div class="row">
<div class="col-md-19 col-lg-18 col-xl-16 offset-md-5"> <div class="col-md-19 col-lg-18 col-xl-16 offset-md-5">

View File

@ -175,7 +175,7 @@ export const apiClient = {
console.debug('[graphql.client.core] deleteShout:', response) console.debug('[graphql.client.core] deleteShout:', response)
}, },
getDrafts: async (): Promise<Shout[]> => { getDrafts: async (): Promise<CommonResult> => {
const response = await apiClient.private.query(draftsLoad, {}).toPromise() const response = await apiClient.private.query(draftsLoad, {}).toPromise()
console.debug('[graphql.client.core] getDrafts:', response) console.debug('[graphql.client.core] getDrafts:', response)
return response.data.get_shouts_drafts return response.data.get_shouts_drafts

View File

@ -3,40 +3,43 @@ import { gql } from '@urql/core'
export default gql` export default gql`
query LoadDraftsQuery { query LoadDraftsQuery {
get_shouts_drafts { get_shouts_drafts {
id error
title shouts {
subtitle
slug
layout
cover
# community
media
main_topic
topics {
id id
title title
body subtitle
slug slug
stat { layout
shouts cover
authors # community
followers media
main_topic
topics {
id
title
body
slug
stat {
shouts
authors
followers
}
}
authors {
id
name
slug
pic
created_at
} }
}
authors {
id
name
slug
pic
created_at created_at
} published_at
created_at featured_at
published_at stat {
featured_at viewed
stat { rating
viewed commented
rating }
commented
} }
} }
} }