diff --git a/src/components/Nav/AuthModal/ChangePasswordForm.tsx b/src/components/Nav/AuthModal/ChangePasswordForm.tsx index 1f7f212b..09ad3907 100644 --- a/src/components/Nav/AuthModal/ChangePasswordForm.tsx +++ b/src/components/Nav/AuthModal/ChangePasswordForm.tsx @@ -4,13 +4,13 @@ import { clsx } from 'clsx' import { createSignal, JSX, Show } from 'solid-js' import { useLocalize } from '../../../context/localize' +import { useSession } from '../../../context/session' import { useRouter } from '../../../stores/router' import { hideModal } from '../../../stores/ui' import { PasswordField } from './PasswordField' import styles from './AuthModal.module.scss' -import { useSession } from '../../../context/session' type FormFields = { password: string diff --git a/src/components/Nav/AuthModal/ForgotPasswordForm.tsx b/src/components/Nav/AuthModal/ForgotPasswordForm.tsx index aec2dd26..233c38aa 100644 --- a/src/components/Nav/AuthModal/ForgotPasswordForm.tsx +++ b/src/components/Nav/AuthModal/ForgotPasswordForm.tsx @@ -21,7 +21,7 @@ type ValidationErrors = Partial> export const ForgotPasswordForm = () => { const { changeSearchParams } = useRouter() - const { t, lang } = useLocalize() + const { t } = useLocalize() const handleEmailInput = (newEmail: string) => { setValidationErrors(({ email: _notNeeded, ...rest }) => rest) setEmail(newEmail) @@ -65,7 +65,7 @@ export const ForgotPasswordForm = () => { email: email(), redirect_uri: window.location.origin, }) - console.debug('[ForgotPasswordForm] authorizer response: ', response) + console.debug('[ForgotPasswordForm] authorizer response:', response) if (response && response.message) setMessage(response.message) } catch (error) { console.error(error) diff --git a/src/components/Nav/AuthModal/LoginForm.tsx b/src/components/Nav/AuthModal/LoginForm.tsx index 9238d0dc..187a3e78 100644 --- a/src/components/Nav/AuthModal/LoginForm.tsx +++ b/src/components/Nav/AuthModal/LoginForm.tsx @@ -17,7 +17,6 @@ import { email, setEmail } from './sharedLogic' import { SocialProviders } from './SocialProviders' import styles from './AuthModal.module.scss' -import { VerifyEmailInput } from '@authorizerdev/authorizer-js' type FormFields = { email: string diff --git a/src/components/Nav/AuthModal/PasswordField/PasswordField.tsx b/src/components/Nav/AuthModal/PasswordField/PasswordField.tsx index 6dab7ef8..8e5abd08 100644 --- a/src/components/Nav/AuthModal/PasswordField/PasswordField.tsx +++ b/src/components/Nav/AuthModal/PasswordField/PasswordField.tsx @@ -1,8 +1,8 @@ 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 { resetSortedArticles } from '../../../../stores/zine/articles' +// import { resetSortedArticles } from '../../../../stores/zine/articles' import { Icon } from '../../../_shared/Icon' import styles from './PasswordField.module.scss' diff --git a/src/components/NotificationsPanel/NotificationView/NotificationView.tsx b/src/components/NotificationsPanel/NotificationView/NotificationView.tsx deleted file mode 100644 index e69de29b..00000000 diff --git a/src/components/Views/Home.tsx b/src/components/Views/Home.tsx index 11effc2a..2d8121c8 100644 --- a/src/components/Views/Home.tsx +++ b/src/components/Views/Home.tsx @@ -1,8 +1,9 @@ -import { Shout, Topic } from '../../graphql/schema/core.gen' import { getPagePath } from '@nanostores/router' import { batch, createMemo, createSignal, For, onMount, Show } from 'solid-js' 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 { loadShouts, @@ -28,7 +29,6 @@ import RowShort from '../Feed/RowShort' import { Topics } from '../Nav/Topics' import styles from './Home.module.scss' -import { apiClient } from '../../graphql/client/core' type Props = { shouts: Shout[] diff --git a/src/components/Views/Inbox.tsx b/src/components/Views/Inbox.tsx index a01aa5bf..3afc8ecc 100644 --- a/src/components/Views/Inbox.tsx +++ b/src/components/Views/Inbox.tsx @@ -52,7 +52,7 @@ export const InboxView = () => { const [isScrollToNewVisible, setIsScrollToNewVisible] = createSignal(false) const { author } = useSession() const currentUserId = createMemo(() => author()?.id) - const { changeSearchParam, searchParams } = useRouter() + const { changeSearchParams, searchParams } = useRouter() const messagesContainerRef: { current: HTMLDivElement } = { current: null, diff --git a/src/components/Views/Topic.tsx b/src/components/Views/Topic.tsx index 9be67b3b..a0ac01e2 100644 --- a/src/components/Views/Topic.tsx +++ b/src/components/Views/Topic.tsx @@ -38,7 +38,7 @@ const LOAD_MORE_PAGE_SIZE = 9 // Row3 + Row3 + Row3 export const TopicView = (props: Props) => { const { t, lang } = useLocalize() - const { searchParams, changeSearchParam } = useRouter() + const { searchParams, changeSearchParams } = useRouter() const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) @@ -56,7 +56,6 @@ export const TopicView = (props: Props) => { true, )}` onMount(() => (document.title = title())) - createEffect(() => props.title(title())) const loadMore = async () => { saveScrollPosition() @@ -76,7 +75,7 @@ export const TopicView = (props: Props) => { loadMore() } }) - + /* const selectionTitle = createMemo(() => { const m = searchParams().by if (m === 'viewed') return t('Top viewed') @@ -84,7 +83,7 @@ export const TopicView = (props: Props) => { if (m === 'commented') return t('Top discussed') return t('Top recent') }) - + */ const pages = createMemo(() => splitToPages(sortedArticles(), PRERENDERED_ARTICLES_COUNT, LOAD_MORE_PAGE_SIZE), ) diff --git a/src/components/_shared/Image/Image.tsx b/src/components/_shared/Image/Image.tsx index 75542cc5..413f66c8 100644 --- a/src/components/_shared/Image/Image.tsx +++ b/src/components/_shared/Image/Image.tsx @@ -1,7 +1,7 @@ import type { JSX } from 'solid-js' import { Link } from '@solidjs/meta' -import { createEffect, splitProps } from 'solid-js' +import { splitProps } from 'solid-js' import { getImageUrl } from '../../../utils/getImageUrl' diff --git a/src/context/session.tsx b/src/context/session.tsx index 06358997..5945040e 100644 --- a/src/context/session.tsx +++ b/src/context/session.tsx @@ -113,7 +113,7 @@ export const SessionProvider = (props: { try { console.info('[context.session] loading session') return await authorizer().getSession() - } catch (_) { + } catch { console.info('[context.session] cannot refresh session') return null } @@ -163,13 +163,14 @@ export const SessionProvider = (props: { setIsSessionLoaded(true) } } - } else { - console.log('[context.session] setting session null') - if (session() === null && author() !== null) { - setIsSessionLoaded(true) - setAuthor(null) - setSubscriptions(EMPTY_SUBSCRIPTIONS) - } + } + }) + + createEffect(() => { + if (session() !== null && author() === null) { + setIsSessionLoaded(true) + setAuthor(null) + setSubscriptions(EMPTY_SUBSCRIPTIONS) } }) @@ -180,7 +181,9 @@ export const SessionProvider = (props: { let s try { s = await loadSession() - } catch (e) {} + } catch { + console.warn('[context.session] load session failed') + } if (!s) { setIsSessionLoaded(true) setSession(null) diff --git a/src/graphql/client/core.ts b/src/graphql/client/core.ts index 9b0d84b5..ad906a3e 100644 --- a/src/graphql/client/core.ts +++ b/src/graphql/client/core.ts @@ -29,13 +29,14 @@ import shoutsLoadBy from '../query/core/articles-load-by' import draftsLoad from '../query/core/articles-load-drafts' import myFeed from '../query/core/articles-load-feed' 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 loadShoutsUnrated from '../query/core/articles-load-unrated' import authorBy from '../query/core/author-by' import authorFollowers from '../query/core/author-followers' import authorId from '../query/core/author-id' -import authorsAll from '../query/core/authors-all' 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 mySubscriptions from '../query/core/my-followed' 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 userFollowedTopics from '../query/core/topics-by-author' import topicsRandomQuery from '../query/core/topics-random' -import articlesLoadRandomTopic from '../query/core/articles-load-random-topic' const publicGraphQLClient = createGraphQLClient('core') @@ -93,11 +93,11 @@ export const apiClient = { return response.data.get_topics_all }, - getAllAuthors: async (limit: number = 50, offset: number = 0) => { - const response = await publicGraphQLClient.query(authorsAll, { limit, offset }).toPromise() + getAllAuthors: async () => { + const response = await publicGraphQLClient.query(authorsAll, {}).toPromise() 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 => { const response = await publicGraphQLClient.query(authorBy, params).toPromise() @@ -172,8 +172,9 @@ export const apiClient = { console.debug('[graphql.client.core] updateReaction:', response) 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() + console.debug('[graphql.client.core] authorsLoadBy:', resp) return resp.data.load_authors_by }, getShoutBySlug: async (slug: string) => { diff --git a/src/graphql/query/core/authors-all.ts b/src/graphql/query/core/authors-all.ts index 3d3f97a6..c8071e10 100644 --- a/src/graphql/query/core/authors-all.ts +++ b/src/graphql/query/core/authors-all.ts @@ -1,19 +1,14 @@ import { gql } from '@urql/core' export default gql` - query AuthorsAllQuery($limit: Int, $offset: Int) { - load_authors_all(limit: $limit, offset: $offset) { + query { + get_authors_all() { id slug name bio pic created_at - stat { - shouts - followers - comments: commented - } } } ` diff --git a/src/graphql/query/core/authors-load-all.ts b/src/graphql/query/core/authors-load-all.ts new file mode 100644 index 00000000..3d3f97a6 --- /dev/null +++ b/src/graphql/query/core/authors-load-all.ts @@ -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 + } + } + } +` diff --git a/src/graphql/query/core/authors-load-by.ts b/src/graphql/query/core/authors-load-by.ts index a5c5b3f5..a78ab877 100644 --- a/src/graphql/query/core/authors-load-by.ts +++ b/src/graphql/query/core/authors-load-by.ts @@ -1,21 +1,19 @@ import { gql } from '@urql/core' export default gql` - query AuthorLoadByQuery($by: AuthorsBy, $limit: Int, $offset: Int) { - load_authors_by(by: $by, limit: $limit, offset: $offset) { + query AuthorsAllQuery($by: AuthorsBy, $limit: Int, $offset: Int) { + load_authors_(by: $by, limit: $limit, offset: $offset) { id slug name bio - userpic - # communities - links + pic created_at - last_seen - # ratings { - # rater - # value - # } + stat { + shouts + followers + comments: commented + } } } ` diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/pages/topic.page.server.ts b/src/pages/topic.page.server.ts index 64dc7725..d495aa8b 100644 --- a/src/pages/topic.page.server.ts +++ b/src/pages/topic.page.server.ts @@ -3,8 +3,8 @@ import type { PageContext } from '../renderer/types' import { render } from 'vike/abort' -import { apiClient } from '../graphql/client/core' import { PRERENDERED_ARTICLES_COUNT } from '../components/Views/Topic' +import { apiClient } from '../graphql/client/core' export const onBeforeRender = async (pageContext: PageContext) => { const { slug } = pageContext.routeParams diff --git a/src/stores/zine/authors.ts b/src/stores/zine/authors.ts index fdade0b9..45cd3bd9 100644 --- a/src/stores/zine/authors.ts +++ b/src/stores/zine/authors.ts @@ -83,8 +83,8 @@ export const addAuthorsByTopic = (newAuthorsByTopic: { [topicSlug: string]: Auth }) } -export const loadAllAuthors = async (limit: number = 50, offset = 0): Promise => { - const authors = await apiClient.getAllAuthors(limit, offset) +export const loadAllAuthors = async (): Promise => { + const authors = await apiClient.getAllAuthors() addAuthors(authors) } @@ -93,6 +93,11 @@ type InitialState = { sortBy?: AuthorsSortBy } +export const loadAuthors = async (by = {}, limit: number = 50, offset = 0): Promise => { + const authors = await apiClient.loadAuthorsBy({ by, limit, offset }) + addAuthors(authors) +} + export const useAuthorsStore = (initialState: InitialState = {}) => { if (initialState.sortBy) { setSortAllBy(initialState.sortBy) diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts deleted file mode 100644 index e69de29b..00000000