From aca1358c184be99cfbbf14cb4a85ec15bbb51023 Mon Sep 17 00:00:00 2001 From: Untone Date: Sun, 24 Dec 2023 20:29:16 +0300 Subject: [PATCH] get-authors-all-fix --- src/components/Views/AllAuthors.tsx | 10 +++--- src/components/Views/Author/Author.tsx | 38 +++++++++++++++------- src/graphql/client/core.ts | 2 +- src/graphql/query/core/authors-load-all.ts | 19 ----------- src/stores/zine/authors.ts | 2 +- 5 files changed, 34 insertions(+), 37 deletions(-) delete mode 100644 src/graphql/query/core/authors-load-all.ts diff --git a/src/components/Views/AllAuthors.tsx b/src/components/Views/AllAuthors.tsx index cb5b406f..1c259677 100644 --- a/src/components/Views/AllAuthors.tsx +++ b/src/components/Views/AllAuthors.tsx @@ -34,7 +34,7 @@ export const AllAuthorsView = (props: Props) => { const { searchParams, changeSearchParams } = useRouter() const { sortedAuthors } = useAuthorsStore({ authors: props.authors, - sortBy: searchParams().by || 'shouts', + sortBy: searchParams().by || 'name', }) const [searchQuery, setSearchQuery] = createSignal('') @@ -42,13 +42,13 @@ export const AllAuthorsView = (props: Props) => { createEffect(() => { if (!searchParams().by) { changeSearchParams({ - by: 'shouts', + by: 'name', }) } }) createEffect(() => { - setAuthorsSort(searchParams().by || 'shouts') + setAuthorsSort(searchParams().by || 'name') }) const byLetter = createMemo<{ [letter: string]: Author[] }>(() => { @@ -171,7 +171,9 @@ export const AllAuthorsView = (props: Props) => {
{author.name} - {author.stat.shouts} + + {author.stat.shouts} +
)} diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index 3d29ba44..2cca6646 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -40,13 +40,19 @@ export const AuthorView = (props: Props) => { const { authorEntities } = useAuthorsStore({ authors: [props.author] }) const { page: getPage } = useRouter() - const author = createMemo(() => authorEntities()[props.authorSlug]) const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) const [isBioExpanded, setIsBioExpanded] = createSignal(false) const [followers, setFollowers] = createSignal([]) const [following, setFollowing] = createSignal>([]) const [showExpandBioControl, setShowExpandBioControl] = createSignal(false) + const author = createMemo(() => authorEntities()[props.authorSlug]) + createEffect(async () => { + if (author() && !author().stat) { + await apiClient.getAuthor({ author_id: author().id }) + } + }) + const bioContainerRef: { current: HTMLDivElement } = { current: null } const bioWrapperRef: { current: HTMLDivElement } = { current: null } const fetchSubscriptions = async (): Promise<{ authors: Author[]; topics: Topic[] }> => { @@ -71,20 +77,24 @@ export const AuthorView = (props: Props) => { } onMount(async () => { - try { - const userSubscribers = await apiClient.getAuthorFollowers({ slug: props.authorSlug }) - setFollowers(userSubscribers) - } catch (error) { - console.error('[getAuthorFollowers]', error) - } - checkBioHeight() + // pagination if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) { await loadMore() } - const { authors, topics } = await fetchSubscriptions() - setFollowing([...(authors || []), ...(topics || [])]) + }) + + createEffect(async () => { + console.error('[AuthorView] load subscriptions') + try { + const { authors, topics } = await fetchSubscriptions() + setFollowing([...(authors || []), ...(topics || [])]) + const userSubscribers = await apiClient.getAuthorFollowers({ slug: author().slug }) + setFollowers(userSubscribers) + } catch (error) { + console.error('[AuthorView] error:', error) + } }) createEffect(() => { @@ -160,13 +170,17 @@ export const AuthorView = (props: Props) => { {t('Publications')} - {author().stat.shouts} + + {author().stat.shouts} +
  • {t('Comments')} - {author().stat.commented} + + {author().stat.commented} +
  • ('shouts') +const [sortAllBy, setSortAllBy] = createSignal('name') export const setAuthorsSort = (sortBy: AuthorsSortBy) => setSortAllBy(sortBy)