session-context-fixes
This commit is contained in:
parent
9a55056b9d
commit
11788bcf0d
|
@ -4,13 +4,13 @@ import { clsx } from 'clsx'
|
||||||
import { createSignal, JSX, Show } from 'solid-js'
|
import { createSignal, JSX, Show } from 'solid-js'
|
||||||
|
|
||||||
import { useLocalize } from '../../../context/localize'
|
import { useLocalize } from '../../../context/localize'
|
||||||
|
import { useSession } from '../../../context/session'
|
||||||
import { useRouter } from '../../../stores/router'
|
import { useRouter } from '../../../stores/router'
|
||||||
import { hideModal } from '../../../stores/ui'
|
import { hideModal } from '../../../stores/ui'
|
||||||
|
|
||||||
import { PasswordField } from './PasswordField'
|
import { PasswordField } from './PasswordField'
|
||||||
|
|
||||||
import styles from './AuthModal.module.scss'
|
import styles from './AuthModal.module.scss'
|
||||||
import { useSession } from '../../../context/session'
|
|
||||||
|
|
||||||
type FormFields = {
|
type FormFields = {
|
||||||
password: string
|
password: string
|
||||||
|
|
|
@ -21,7 +21,7 @@ type ValidationErrors = Partial<Record<keyof FormFields, string | JSX.Element>>
|
||||||
|
|
||||||
export const ForgotPasswordForm = () => {
|
export const ForgotPasswordForm = () => {
|
||||||
const { changeSearchParams } = useRouter<AuthModalSearchParams>()
|
const { changeSearchParams } = useRouter<AuthModalSearchParams>()
|
||||||
const { t, lang } = useLocalize()
|
const { t } = useLocalize()
|
||||||
const handleEmailInput = (newEmail: string) => {
|
const handleEmailInput = (newEmail: string) => {
|
||||||
setValidationErrors(({ email: _notNeeded, ...rest }) => rest)
|
setValidationErrors(({ email: _notNeeded, ...rest }) => rest)
|
||||||
setEmail(newEmail)
|
setEmail(newEmail)
|
||||||
|
|
|
@ -17,7 +17,6 @@ import { email, setEmail } from './sharedLogic'
|
||||||
import { SocialProviders } from './SocialProviders'
|
import { SocialProviders } from './SocialProviders'
|
||||||
|
|
||||||
import styles from './AuthModal.module.scss'
|
import styles from './AuthModal.module.scss'
|
||||||
import { VerifyEmailInput } from '@authorizerdev/authorizer-js'
|
|
||||||
|
|
||||||
type FormFields = {
|
type FormFields = {
|
||||||
email: string
|
email: string
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { clsx } from 'clsx'
|
import { clsx } from 'clsx'
|
||||||
import { createEffect, createSignal, JSX, on, Show } from 'solid-js'
|
import { createEffect, createSignal, on, Show } from 'solid-js'
|
||||||
|
|
||||||
import { useLocalize } from '../../../../context/localize'
|
import { useLocalize } from '../../../../context/localize'
|
||||||
import { resetSortedArticles } from '../../../../stores/zine/articles'
|
// import { resetSortedArticles } from '../../../../stores/zine/articles'
|
||||||
import { Icon } from '../../../_shared/Icon'
|
import { Icon } from '../../../_shared/Icon'
|
||||||
|
|
||||||
import styles from './PasswordField.module.scss'
|
import styles from './PasswordField.module.scss'
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { Shout, Topic } from '../../graphql/schema/core.gen'
|
|
||||||
import { getPagePath } from '@nanostores/router'
|
import { getPagePath } from '@nanostores/router'
|
||||||
import { batch, createMemo, createSignal, For, onMount, Show } from 'solid-js'
|
import { batch, createMemo, createSignal, For, onMount, Show } from 'solid-js'
|
||||||
|
|
||||||
import { useLocalize } from '../../context/localize'
|
import { useLocalize } from '../../context/localize'
|
||||||
|
import { apiClient } from '../../graphql/client/core'
|
||||||
|
import { Shout, Topic } from '../../graphql/schema/core.gen'
|
||||||
import { router } from '../../stores/router'
|
import { router } from '../../stores/router'
|
||||||
import {
|
import {
|
||||||
loadShouts,
|
loadShouts,
|
||||||
|
@ -28,7 +29,6 @@ import RowShort from '../Feed/RowShort'
|
||||||
import { Topics } from '../Nav/Topics'
|
import { Topics } from '../Nav/Topics'
|
||||||
|
|
||||||
import styles from './Home.module.scss'
|
import styles from './Home.module.scss'
|
||||||
import { apiClient } from '../../graphql/client/core'
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
shouts: Shout[]
|
shouts: Shout[]
|
||||||
|
|
|
@ -52,7 +52,7 @@ export const InboxView = () => {
|
||||||
const [isScrollToNewVisible, setIsScrollToNewVisible] = createSignal(false)
|
const [isScrollToNewVisible, setIsScrollToNewVisible] = createSignal(false)
|
||||||
const { author } = useSession()
|
const { author } = useSession()
|
||||||
const currentUserId = createMemo(() => author()?.id)
|
const currentUserId = createMemo(() => author()?.id)
|
||||||
const { changeSearchParam, searchParams } = useRouter<InboxSearchParams>()
|
const { changeSearchParams, searchParams } = useRouter<InboxSearchParams>()
|
||||||
|
|
||||||
const messagesContainerRef: { current: HTMLDivElement } = {
|
const messagesContainerRef: { current: HTMLDivElement } = {
|
||||||
current: null,
|
current: null,
|
||||||
|
|
|
@ -38,7 +38,7 @@ const LOAD_MORE_PAGE_SIZE = 9 // Row3 + Row3 + Row3
|
||||||
|
|
||||||
export const TopicView = (props: Props) => {
|
export const TopicView = (props: Props) => {
|
||||||
const { t, lang } = useLocalize()
|
const { t, lang } = useLocalize()
|
||||||
const { searchParams, changeSearchParam } = useRouter<TopicsPageSearchParams>()
|
const { searchParams, changeSearchParams } = useRouter<TopicsPageSearchParams>()
|
||||||
|
|
||||||
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
|
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
|
||||||
|
|
||||||
|
@ -56,7 +56,6 @@ export const TopicView = (props: Props) => {
|
||||||
true,
|
true,
|
||||||
)}`
|
)}`
|
||||||
onMount(() => (document.title = title()))
|
onMount(() => (document.title = title()))
|
||||||
createEffect(() => props.title(title()))
|
|
||||||
|
|
||||||
const loadMore = async () => {
|
const loadMore = async () => {
|
||||||
saveScrollPosition()
|
saveScrollPosition()
|
||||||
|
@ -76,7 +75,7 @@ export const TopicView = (props: Props) => {
|
||||||
loadMore()
|
loadMore()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
/*
|
||||||
const selectionTitle = createMemo(() => {
|
const selectionTitle = createMemo(() => {
|
||||||
const m = searchParams().by
|
const m = searchParams().by
|
||||||
if (m === 'viewed') return t('Top viewed')
|
if (m === 'viewed') return t('Top viewed')
|
||||||
|
@ -84,7 +83,7 @@ export const TopicView = (props: Props) => {
|
||||||
if (m === 'commented') return t('Top discussed')
|
if (m === 'commented') return t('Top discussed')
|
||||||
return t('Top recent')
|
return t('Top recent')
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
const pages = createMemo<Shout[][]>(() =>
|
const pages = createMemo<Shout[][]>(() =>
|
||||||
splitToPages(sortedArticles(), PRERENDERED_ARTICLES_COUNT, LOAD_MORE_PAGE_SIZE),
|
splitToPages(sortedArticles(), PRERENDERED_ARTICLES_COUNT, LOAD_MORE_PAGE_SIZE),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import type { JSX } from 'solid-js'
|
import type { JSX } from 'solid-js'
|
||||||
|
|
||||||
import { Link } from '@solidjs/meta'
|
import { Link } from '@solidjs/meta'
|
||||||
import { createEffect, splitProps } from 'solid-js'
|
import { splitProps } from 'solid-js'
|
||||||
|
|
||||||
import { getImageUrl } from '../../../utils/getImageUrl'
|
import { getImageUrl } from '../../../utils/getImageUrl'
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ export const SessionProvider = (props: {
|
||||||
try {
|
try {
|
||||||
console.info('[context.session] loading session')
|
console.info('[context.session] loading session')
|
||||||
return await authorizer().getSession()
|
return await authorizer().getSession()
|
||||||
} catch (_) {
|
} catch {
|
||||||
console.info('[context.session] cannot refresh session')
|
console.info('[context.session] cannot refresh session')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -163,14 +163,15 @@ export const SessionProvider = (props: {
|
||||||
setIsSessionLoaded(true)
|
setIsSessionLoaded(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
console.log('[context.session] setting session null')
|
})
|
||||||
if (session() === null && author() !== null) {
|
|
||||||
|
createEffect(() => {
|
||||||
|
if (session() !== null && author() === null) {
|
||||||
setIsSessionLoaded(true)
|
setIsSessionLoaded(true)
|
||||||
setAuthor(null)
|
setAuthor(null)
|
||||||
setSubscriptions(EMPTY_SUBSCRIPTIONS)
|
setSubscriptions(EMPTY_SUBSCRIPTIONS)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// initial effect
|
// initial effect
|
||||||
|
@ -180,7 +181,9 @@ export const SessionProvider = (props: {
|
||||||
let s
|
let s
|
||||||
try {
|
try {
|
||||||
s = await loadSession()
|
s = await loadSession()
|
||||||
} catch (e) {}
|
} catch {
|
||||||
|
console.warn('[context.session] load session failed')
|
||||||
|
}
|
||||||
if (!s) {
|
if (!s) {
|
||||||
setIsSessionLoaded(true)
|
setIsSessionLoaded(true)
|
||||||
setSession(null)
|
setSession(null)
|
||||||
|
|
|
@ -29,13 +29,14 @@ import shoutsLoadBy from '../query/core/articles-load-by'
|
||||||
import draftsLoad from '../query/core/articles-load-drafts'
|
import draftsLoad from '../query/core/articles-load-drafts'
|
||||||
import myFeed from '../query/core/articles-load-feed'
|
import myFeed from '../query/core/articles-load-feed'
|
||||||
import loadShoutsTopRandom from '../query/core/articles-load-random-top'
|
import loadShoutsTopRandom from '../query/core/articles-load-random-top'
|
||||||
|
import articlesLoadRandomTopic from '../query/core/articles-load-random-topic'
|
||||||
import shoutsLoadSearch from '../query/core/articles-load-search'
|
import shoutsLoadSearch from '../query/core/articles-load-search'
|
||||||
import loadShoutsUnrated from '../query/core/articles-load-unrated'
|
import loadShoutsUnrated from '../query/core/articles-load-unrated'
|
||||||
import authorBy from '../query/core/author-by'
|
import authorBy from '../query/core/author-by'
|
||||||
import authorFollowers from '../query/core/author-followers'
|
import authorFollowers from '../query/core/author-followers'
|
||||||
import authorId from '../query/core/author-id'
|
import authorId from '../query/core/author-id'
|
||||||
import authorsAll from '../query/core/authors-all'
|
|
||||||
import authorFollowed from '../query/core/authors-followed-by'
|
import authorFollowed from '../query/core/authors-followed-by'
|
||||||
|
import authorsAll from '../query/core/authors-load-all'
|
||||||
import authorsLoadBy from '../query/core/authors-load-by'
|
import authorsLoadBy from '../query/core/authors-load-by'
|
||||||
import mySubscriptions from '../query/core/my-followed'
|
import mySubscriptions from '../query/core/my-followed'
|
||||||
import reactionsLoadBy from '../query/core/reactions-load-by'
|
import reactionsLoadBy from '../query/core/reactions-load-by'
|
||||||
|
@ -43,7 +44,6 @@ import topicBySlug from '../query/core/topic-by-slug'
|
||||||
import topicsAll from '../query/core/topics-all'
|
import topicsAll from '../query/core/topics-all'
|
||||||
import userFollowedTopics from '../query/core/topics-by-author'
|
import userFollowedTopics from '../query/core/topics-by-author'
|
||||||
import topicsRandomQuery from '../query/core/topics-random'
|
import topicsRandomQuery from '../query/core/topics-random'
|
||||||
import articlesLoadRandomTopic from '../query/core/articles-load-random-topic'
|
|
||||||
|
|
||||||
const publicGraphQLClient = createGraphQLClient('core')
|
const publicGraphQLClient = createGraphQLClient('core')
|
||||||
|
|
||||||
|
@ -93,11 +93,11 @@ export const apiClient = {
|
||||||
|
|
||||||
return response.data.get_topics_all
|
return response.data.get_topics_all
|
||||||
},
|
},
|
||||||
getAllAuthors: async (limit: number = 50, offset: number = 0) => {
|
getAllAuthors: async () => {
|
||||||
const response = await publicGraphQLClient.query(authorsAll, { limit, offset }).toPromise()
|
const response = await publicGraphQLClient.query(authorsAll, {}).toPromise()
|
||||||
if (!response.data) console.error('[graphql.client.core] load_authors_all', response)
|
if (!response.data) console.error('[graphql.client.core] load_authors_all', response)
|
||||||
|
|
||||||
return response.data.load_authors_all
|
return response.data.get_authors_all
|
||||||
},
|
},
|
||||||
getAuthor: async (params: { slug?: string; author_id?: number }): Promise<Author> => {
|
getAuthor: async (params: { slug?: string; author_id?: number }): Promise<Author> => {
|
||||||
const response = await publicGraphQLClient.query(authorBy, params).toPromise()
|
const response = await publicGraphQLClient.query(authorBy, params).toPromise()
|
||||||
|
@ -172,8 +172,9 @@ export const apiClient = {
|
||||||
console.debug('[graphql.client.core] updateReaction:', response)
|
console.debug('[graphql.client.core] updateReaction:', response)
|
||||||
return response.data.update_reaction.reaction
|
return response.data.update_reaction.reaction
|
||||||
},
|
},
|
||||||
getAuthorsBy: async (args: QueryLoad_Authors_ByArgs) => {
|
loadAuthorsBy: async (args: QueryLoad_Authors_ByArgs) => {
|
||||||
const resp = await publicGraphQLClient.query(authorsLoadBy, args).toPromise()
|
const resp = await publicGraphQLClient.query(authorsLoadBy, args).toPromise()
|
||||||
|
console.debug('[graphql.client.core] authorsLoadBy:', resp)
|
||||||
return resp.data.load_authors_by
|
return resp.data.load_authors_by
|
||||||
},
|
},
|
||||||
getShoutBySlug: async (slug: string) => {
|
getShoutBySlug: async (slug: string) => {
|
||||||
|
|
|
@ -1,19 +1,14 @@
|
||||||
import { gql } from '@urql/core'
|
import { gql } from '@urql/core'
|
||||||
|
|
||||||
export default gql`
|
export default gql`
|
||||||
query AuthorsAllQuery($limit: Int, $offset: Int) {
|
query {
|
||||||
load_authors_all(limit: $limit, offset: $offset) {
|
get_authors_all() {
|
||||||
id
|
id
|
||||||
slug
|
slug
|
||||||
name
|
name
|
||||||
bio
|
bio
|
||||||
pic
|
pic
|
||||||
created_at
|
created_at
|
||||||
stat {
|
|
||||||
shouts
|
|
||||||
followers
|
|
||||||
comments: commented
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
19
src/graphql/query/core/authors-load-all.ts
Normal file
19
src/graphql/query/core/authors-load-all.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { gql } from '@urql/core'
|
||||||
|
|
||||||
|
export default gql`
|
||||||
|
query AuthorsAllQuery($limit: Int, $offset: Int) {
|
||||||
|
load_authors_all(limit: $limit, offset: $offset) {
|
||||||
|
id
|
||||||
|
slug
|
||||||
|
name
|
||||||
|
bio
|
||||||
|
pic
|
||||||
|
created_at
|
||||||
|
stat {
|
||||||
|
shouts
|
||||||
|
followers
|
||||||
|
comments: commented
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
|
@ -1,21 +1,19 @@
|
||||||
import { gql } from '@urql/core'
|
import { gql } from '@urql/core'
|
||||||
|
|
||||||
export default gql`
|
export default gql`
|
||||||
query AuthorLoadByQuery($by: AuthorsBy, $limit: Int, $offset: Int) {
|
query AuthorsAllQuery($by: AuthorsBy, $limit: Int, $offset: Int) {
|
||||||
load_authors_by(by: $by, limit: $limit, offset: $offset) {
|
load_authors_(by: $by, limit: $limit, offset: $offset) {
|
||||||
id
|
id
|
||||||
slug
|
slug
|
||||||
name
|
name
|
||||||
bio
|
bio
|
||||||
userpic
|
pic
|
||||||
# communities
|
|
||||||
links
|
|
||||||
created_at
|
created_at
|
||||||
last_seen
|
stat {
|
||||||
# ratings {
|
shouts
|
||||||
# rater
|
followers
|
||||||
# value
|
comments: commented
|
||||||
# }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
|
@ -3,8 +3,8 @@ import type { PageContext } from '../renderer/types'
|
||||||
|
|
||||||
import { render } from 'vike/abort'
|
import { render } from 'vike/abort'
|
||||||
|
|
||||||
import { apiClient } from '../graphql/client/core'
|
|
||||||
import { PRERENDERED_ARTICLES_COUNT } from '../components/Views/Topic'
|
import { PRERENDERED_ARTICLES_COUNT } from '../components/Views/Topic'
|
||||||
|
import { apiClient } from '../graphql/client/core'
|
||||||
|
|
||||||
export const onBeforeRender = async (pageContext: PageContext) => {
|
export const onBeforeRender = async (pageContext: PageContext) => {
|
||||||
const { slug } = pageContext.routeParams
|
const { slug } = pageContext.routeParams
|
||||||
|
|
|
@ -83,8 +83,8 @@ export const addAuthorsByTopic = (newAuthorsByTopic: { [topicSlug: string]: Auth
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadAllAuthors = async (limit: number = 50, offset = 0): Promise<void> => {
|
export const loadAllAuthors = async (): Promise<void> => {
|
||||||
const authors = await apiClient.getAllAuthors(limit, offset)
|
const authors = await apiClient.getAllAuthors()
|
||||||
addAuthors(authors)
|
addAuthors(authors)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +93,11 @@ type InitialState = {
|
||||||
sortBy?: AuthorsSortBy
|
sortBy?: AuthorsSortBy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const loadAuthors = async (by = {}, limit: number = 50, offset = 0): Promise<void> => {
|
||||||
|
const authors = await apiClient.loadAuthorsBy({ by, limit, offset })
|
||||||
|
addAuthors(authors)
|
||||||
|
}
|
||||||
|
|
||||||
export const useAuthorsStore = (initialState: InitialState = {}) => {
|
export const useAuthorsStore = (initialState: InitialState = {}) => {
|
||||||
if (initialState.sortBy) {
|
if (initialState.sortBy) {
|
||||||
setSortAllBy(initialState.sortBy)
|
setSortAllBy(initialState.sortBy)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user