session-patch
This commit is contained in:
parent
409e64ddaf
commit
603ebbb4a5
|
@ -57,7 +57,7 @@ export const ProfileSettings = () => {
|
|||
const [nameError, setNameError] = createSignal<string>()
|
||||
const { form, submit, updateFormField, setForm } = useProfileForm()
|
||||
const { showSnackbar } = useSnackbar()
|
||||
const { loadAuthor, session } = useSession()
|
||||
const { loadSession, session } = useSession()
|
||||
const { showConfirm } = useConfirm()
|
||||
const [clearAbout, setClearAbout] = createSignal(false)
|
||||
|
||||
|
@ -112,7 +112,7 @@ export const ProfileSettings = () => {
|
|||
setIsSaving(false)
|
||||
}
|
||||
|
||||
await loadAuthor() // renews author's profile
|
||||
setTimeout(loadSession, 5000) // renews author's profile
|
||||
}
|
||||
|
||||
const handleCancel = async () => {
|
||||
|
|
|
@ -47,13 +47,11 @@ const defaultConfig: ConfigType = {
|
|||
export type SessionContextType = {
|
||||
config: Accessor<ConfigType>
|
||||
session: Resource<AuthToken>
|
||||
author: Resource<Author | null>
|
||||
author: Accessor<Author>
|
||||
authError: Accessor<string>
|
||||
isSessionLoaded: Accessor<boolean>
|
||||
loadSession: () => AuthToken | Promise<AuthToken>
|
||||
setSession: (token: AuthToken | null) => void // setSession
|
||||
loadAuthor: (info?: unknown) => Author | Promise<Author>
|
||||
setAuthor: (a: Author) => void
|
||||
requireAuthentication: (
|
||||
callback: (() => Promise<void>) | (() => void),
|
||||
modalSource: AuthModalSource,
|
||||
|
@ -205,6 +203,7 @@ export const SessionProvider = (props: {
|
|||
ssrLoadFrom: 'initial',
|
||||
initialValue: null,
|
||||
})
|
||||
const author = createMemo(() => session().user?.app_data?.profile)
|
||||
|
||||
const checkSessionIsExpired = () => {
|
||||
const expires_at_data = localStorage.getItem('expires_at')
|
||||
|
@ -226,15 +225,6 @@ export const SessionProvider = (props: {
|
|||
|
||||
onCleanup(() => clearTimeout(minuteLater))
|
||||
|
||||
const authorData = async () => {
|
||||
const u = session()?.user
|
||||
return u ? (await apiClient.getAuthorId({ user: u.id.trim() })) || null : null
|
||||
}
|
||||
const [author, { refetch: loadAuthor, mutate: setAuthor }] = createResource<Author | null>(authorData, {
|
||||
ssrLoadFrom: 'initial',
|
||||
initialValue: null,
|
||||
})
|
||||
|
||||
// when session is loaded
|
||||
createEffect(
|
||||
on(
|
||||
|
@ -249,16 +239,8 @@ export const SessionProvider = (props: {
|
|||
}
|
||||
|
||||
try {
|
||||
const appdata = session()?.user.app_data
|
||||
if (appdata) {
|
||||
const { profile } = appdata
|
||||
if (profile?.id) {
|
||||
setAuthor(profile)
|
||||
addAuthors([profile])
|
||||
} else {
|
||||
setTimeout(loadAuthor, 15)
|
||||
}
|
||||
}
|
||||
const profile = session()?.user?.app_data?.profile
|
||||
if (profile?.id) addAuthors([profile])
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
@ -274,7 +256,6 @@ export const SessionProvider = (props: {
|
|||
const reset = () => {
|
||||
setIsSessionLoaded(true)
|
||||
setSession(null)
|
||||
setAuthor(null)
|
||||
}
|
||||
|
||||
// initial effect
|
||||
|
@ -406,9 +387,7 @@ export const SessionProvider = (props: {
|
|||
updateProfile,
|
||||
setIsSessionLoaded,
|
||||
setSession,
|
||||
setAuthor,
|
||||
authorizer,
|
||||
loadAuthor,
|
||||
forgotPassword,
|
||||
changePassword,
|
||||
oauth,
|
||||
|
|
|
@ -40,7 +40,6 @@ import loadShoutsUnrated from '../query/core/articles-load-unrated'
|
|||
import authorBy from '../query/core/author-by'
|
||||
import authorFollowers from '../query/core/author-followers'
|
||||
import authorFollows from '../query/core/author-follows'
|
||||
import authorId from '../query/core/author-id'
|
||||
import authorsAll from '../query/core/authors-all'
|
||||
import authorsLoadBy from '../query/core/authors-load-by'
|
||||
import reactionsLoadBy from '../query/core/reactions-load-by'
|
||||
|
@ -121,11 +120,6 @@ export const apiClient = {
|
|||
return response.data.get_author
|
||||
},
|
||||
|
||||
getAuthorId: async (params: { user: string }): Promise<Author> => {
|
||||
const response = await publicGraphQLClient.query(authorId, params).toPromise()
|
||||
return response.data.get_author_id
|
||||
},
|
||||
|
||||
getAuthorFollowers: async ({ slug }: { slug: string }): Promise<Author[]> => {
|
||||
const response = await publicGraphQLClient.query(authorFollowers, { slug }).toPromise()
|
||||
return response.data.get_author_followers
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
import { gql } from '@urql/core'
|
||||
|
||||
export default gql`
|
||||
query GetAuthorId($user: String!) {
|
||||
get_author_id(user: $user) {
|
||||
id
|
||||
slug
|
||||
name
|
||||
bio
|
||||
about
|
||||
pic
|
||||
links
|
||||
created_at
|
||||
last_seen
|
||||
stat {
|
||||
shouts
|
||||
authors
|
||||
followers
|
||||
rating
|
||||
comments
|
||||
rating_shouts
|
||||
rating_comments
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
Loading…
Reference in New Issue
Block a user