drafts-reload-session
This commit is contained in:
parent
6e8b6043d7
commit
3ce53728ea
|
@ -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">
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,6 +3,8 @@ import { gql } from '@urql/core'
|
|||
export default gql`
|
||||
query LoadDraftsQuery {
|
||||
get_shouts_drafts {
|
||||
error
|
||||
shouts {
|
||||
id
|
||||
title
|
||||
subtitle
|
||||
|
@ -40,4 +42,5 @@ export default gql`
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue
Block a user