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'
export const DraftsView = () => {
const { session } = useSession()
const { author, loadSession } = useSession()
const [drafts, setDrafts] = createSignal<Shout[]>([])
createEffect(
on(
() => session(),
async (s) => {
if (s) {
const loadedDrafts = await apiClient.getDrafts()
setDrafts(loadedDrafts.reverse() || [])
() => author(),
async (a) => {
if (a) {
const { shouts: loadedDrafts, error } = await apiClient.getDrafts()
if (error) {
console.warn(error)
await loadSession()
}
setDrafts(loadedDrafts || [])
}
},
),
@ -46,7 +50,7 @@ export const DraftsView = () => {
return (
<div class={clsx(styles.DraftsView)}>
<Show when={session()?.user?.id} fallback={<Loading />}>
<Show when={author()?.id} fallback={<Loading />}>
<div class="wide-container">
<div class="row">
<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)
},
getDrafts: async (): Promise<Shout[]> => {
getDrafts: async (): Promise<CommonResult> => {
const response = await apiClient.private.query(draftsLoad, {}).toPromise()
console.debug('[graphql.client.core] getDrafts:', response)
return response.data.get_shouts_drafts

View File

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