From 98264cfce7a9f713a663914af1daaef5d2cad274 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 16 Feb 2024 13:21:25 +0300 Subject: [PATCH 01/13] canEdit-fix --- src/components/Article/Comment/Comment.tsx | 12 ++++++------ src/components/Article/FullArticle.tsx | 9 +++++++-- src/components/Feed/ArticleCard/ArticleCard.tsx | 11 +++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/components/Article/Comment/Comment.tsx b/src/components/Article/Comment/Comment.tsx index d6af579f..50a8f9c5 100644 --- a/src/components/Article/Comment/Comment.tsx +++ b/src/components/Article/Comment/Comment.tsx @@ -38,12 +38,14 @@ export const Comment = (props: Props) => { const [loading, setLoading] = createSignal(false) const [editMode, setEditMode] = createSignal(false) const [clearEditor, setClearEditor] = createSignal(false) - const { author } = useSession() + const { author, session } = useSession() const { createReaction, deleteReaction, updateReaction } = useReactions() const { showConfirm } = useConfirm() const { showSnackbar } = useSnackbar() - const isCommentAuthor = createMemo(() => props.comment.created_by?.slug === author()?.slug) + const canEdit = createMemo( + () => props.comment.created_by?.slug === author()?.slug || session()?.user?.roles.includes('editor'), + ) const comment = createMemo(() => props.comment) const body = createMemo(() => (comment().body || '').trim()) @@ -108,9 +110,7 @@ export const Comment = (props: Props) => { return (
  • props.lastSeen, - })} + class={clsx(styles.comment, props.class, { [styles.isNew]: comment()?.created_at > props.lastSeen })} >
    @@ -189,7 +189,7 @@ export const Comment = (props: Props) => { {loading() ? t('Loading') : t('Reply')} - +
  • - +
  • - +
  • - {/**/} + {/**/} {/*
  • */} {/* Date: Fri, 16 Feb 2024 19:22:50 +0300 Subject: [PATCH 05/13] minor-fix --- src/components/Nav/Header/Link.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Nav/Header/Link.tsx b/src/components/Nav/Header/Link.tsx index c041c4d0..98711721 100644 --- a/src/components/Nav/Header/Link.tsx +++ b/src/components/Nav/Header/Link.tsx @@ -17,7 +17,7 @@ type Props = { export const Link = (props: Props) => { const { page } = useRouter() - const isSelected = page().route === props.routeName + const isSelected = page()?.route === props.routeName return (
  • Date: Fri, 16 Feb 2024 19:27:38 +0300 Subject: [PATCH 06/13] delete-reaction-fix-header-link-fix --- src/components/Nav/Header/Link.tsx | 2 +- src/graphql/client/core.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Nav/Header/Link.tsx b/src/components/Nav/Header/Link.tsx index 98711721..6bf639b5 100644 --- a/src/components/Nav/Header/Link.tsx +++ b/src/components/Nav/Header/Link.tsx @@ -21,7 +21,7 @@ export const Link = (props: Props) => { return (
  • { - const response = await apiClient.private.mutation(reactionDestroy, { id: id }).toPromise() + destroyReaction: async (reaction_id: number) => { + const response = await apiClient.private.mutation(reactionDestroy, { reaction_id }).toPromise() console.debug('[graphql.client.core] destroyReaction:', response) return response.data.delete_reaction.reaction }, From b295ba0dbf62be7418497d4355c2ea7d16743fcf Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 16 Feb 2024 19:58:24 +0300 Subject: [PATCH 07/13] update-reaction-query-fix --- src/components/Article/Comment/Comment.tsx | 3 ++- src/context/reactions.tsx | 6 +++--- src/graphql/client/core.ts | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/Article/Comment/Comment.tsx b/src/components/Article/Comment/Comment.tsx index 0df0a748..f0d468a2 100644 --- a/src/components/Article/Comment/Comment.tsx +++ b/src/components/Article/Comment/Comment.tsx @@ -96,7 +96,8 @@ export const Comment = (props: Props) => { const handleUpdate = async (value) => { setLoading(true) try { - await updateReaction(props.comment.id, { + await updateReaction({ + id: props.comment.id, kind: ReactionKind.Comment, body: value, shout: props.comment.shout.id, diff --git a/src/context/reactions.tsx b/src/context/reactions.tsx index 48da0594..ae4c7b95 100644 --- a/src/context/reactions.tsx +++ b/src/context/reactions.tsx @@ -18,7 +18,7 @@ type ReactionsContextType = { offset?: number }) => Promise createReaction: (reaction: ReactionInput) => Promise - updateReaction: (id: number, reaction: ReactionInput) => Promise + updateReaction: (reaction: ReactionInput) => Promise deleteReaction: (id: number) => Promise } @@ -88,8 +88,8 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => { } } - const updateReaction = async (id: number, input: ReactionInput): Promise => { - const reaction = await apiClient.updateReaction(id, input) + const updateReaction = async (input: ReactionInput): Promise => { + const reaction = await apiClient.updateReaction(input) setReactionEntities(reaction.id, reaction) } diff --git a/src/graphql/client/core.ts b/src/graphql/client/core.ts index bd6571c1..e83d4872 100644 --- a/src/graphql/client/core.ts +++ b/src/graphql/client/core.ts @@ -183,9 +183,9 @@ export const apiClient = { console.debug('[graphql.client.core] destroyReaction:', response) return response.data.delete_reaction.reaction }, - updateReaction: async (id: number, input: ReactionInput) => { + updateReaction: async (reaction: ReactionInput) => { const response = await apiClient.private - .mutation(reactionUpdate, { id: id, reaction: input }) + .mutation(reactionUpdate, { reaction }) .toPromise() console.debug('[graphql.client.core] updateReaction:', response) return response.data.update_reaction.reaction From 6cc6b4f5ac3b570378553ee23db7355216118149 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 16 Feb 2024 20:04:05 +0300 Subject: [PATCH 08/13] id-optional-fix-2 --- src/components/Article/Comment/Comment.tsx | 6 ++++-- src/components/Article/FullArticle.tsx | 9 ++++++--- src/components/Feed/ArticleCard/ArticleCard.tsx | 9 ++++++--- src/graphql/client/core.ts | 4 +--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/components/Article/Comment/Comment.tsx b/src/components/Article/Comment/Comment.tsx index f0d468a2..d22a8da7 100644 --- a/src/components/Article/Comment/Comment.tsx +++ b/src/components/Article/Comment/Comment.tsx @@ -43,8 +43,10 @@ export const Comment = (props: Props) => { const { showConfirm } = useConfirm() const { showSnackbar } = useSnackbar() - const canEdit = createMemo ( () => - Boolean(author()?.id) && ((props.comment?.created_by?.id === author().id) || session()?.user?.roles.includes('editor')) + const canEdit = createMemo( + () => + Boolean(author()?.id) && + (props.comment?.created_by?.id === author().id || session()?.user?.roles.includes('editor')), ) const comment = createMemo(() => props.comment) diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index 6e32755d..46177b8c 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -79,9 +79,12 @@ export const FullArticle = (props: Props) => { const formattedDate = createMemo(() => formatDate(new Date(props.article.published_at * 1000))) - const canEdit = createMemo(() => - Boolean(author()?.id) && ((props.article?.authors?.some((a) => Boolean(a) && a?.id === author().id)) || - (props.article?.created_by?.id === author().id) || session()?.user?.roles.includes('editor')) + const canEdit = createMemo( + () => + Boolean(author()?.id) && + (props.article?.authors?.some((a) => Boolean(a) && a?.id === author().id) || + props.article?.created_by?.id === author().id || + session()?.user?.roles.includes('editor')), ) const mainTopic = createMemo(() => { diff --git a/src/components/Feed/ArticleCard/ArticleCard.tsx b/src/components/Feed/ArticleCard/ArticleCard.tsx index 451714da..c181cc27 100644 --- a/src/components/Feed/ArticleCard/ArticleCard.tsx +++ b/src/components/Feed/ArticleCard/ArticleCard.tsx @@ -120,9 +120,12 @@ export const ArticleCard = (props: ArticleCardProps) => { props.article.published_at ? formatDate(new Date(props.article.published_at * 1000)) : '', ) - const canEdit = createMemo(() => - Boolean(author()?.id) && ((props.article?.authors?.some((a) => Boolean(a) && a?.id === author().id)) || - (props.article?.created_by?.id === author().id) || session()?.user?.roles.includes('editor')) + const canEdit = createMemo( + () => + Boolean(author()?.id) && + (props.article?.authors?.some((a) => Boolean(a) && a?.id === author().id) || + props.article?.created_by?.id === author().id || + session()?.user?.roles.includes('editor')), ) const scrollToComments = (event) => { diff --git a/src/graphql/client/core.ts b/src/graphql/client/core.ts index e83d4872..752b4de4 100644 --- a/src/graphql/client/core.ts +++ b/src/graphql/client/core.ts @@ -184,9 +184,7 @@ export const apiClient = { return response.data.delete_reaction.reaction }, updateReaction: async (reaction: ReactionInput) => { - const response = await apiClient.private - .mutation(reactionUpdate, { reaction }) - .toPromise() + const response = await apiClient.private.mutation(reactionUpdate, { reaction }).toPromise() console.debug('[graphql.client.core] updateReaction:', response) return response.data.update_reaction.reaction }, From b731f1cfa66ff9ef098aa5ffd310f26dadf37b67 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 16 Feb 2024 20:07:38 +0300 Subject: [PATCH 09/13] gql-fix --- src/graphql/mutation/core/reaction-update.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphql/mutation/core/reaction-update.ts b/src/graphql/mutation/core/reaction-update.ts index 03c32a04..6c20be49 100644 --- a/src/graphql/mutation/core/reaction-update.ts +++ b/src/graphql/mutation/core/reaction-update.ts @@ -1,8 +1,8 @@ import { gql } from '@urql/core' export default gql` - mutation UpdateReactionMutation($id: Int!, $reaction: ReactionInput!) { - update_reaction(id: $id, reaction: $reaction) { + mutation UpdateReactionMutation($reaction: ReactionInput!) { + update_reaction(reaction: $reaction) { error reaction { id From da7c98afabb85b648743b7b61ee82b0c1be14f3e Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 17 Feb 2024 16:04:47 +0300 Subject: [PATCH 10/13] minor --- src/components/Nav/Header/Link.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Nav/Header/Link.tsx b/src/components/Nav/Header/Link.tsx index c041c4d0..6bf639b5 100644 --- a/src/components/Nav/Header/Link.tsx +++ b/src/components/Nav/Header/Link.tsx @@ -17,11 +17,11 @@ type Props = { export const Link = (props: Props) => { const { page } = useRouter() - const isSelected = page().route === props.routeName + const isSelected = page()?.route === props.routeName return (
  • Date: Wed, 21 Feb 2024 16:44:21 +0300 Subject: [PATCH 11/13] fix scroll to comments by search params (#416) * fix scroll to comments by search params * CommentsTree sort * Cancel cleanup search params in link to comment --- src/components/Article/CommentsTree.tsx | 3 --- src/components/Article/FullArticle.tsx | 25 ++++++++++--------------- src/stores/router.ts | 2 +- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx index 3057ffb6..03a39287 100644 --- a/src/components/Article/CommentsTree.tsx +++ b/src/components/Article/CommentsTree.tsx @@ -66,9 +66,6 @@ export const CommentsTree = (props: Props) => { if (commentsOrder() === 'rating') { newSortedComments = newSortedComments.sort(sortCommentsByRating) } - - newSortedComments.reverse() - return newSortedComments }) diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index 46177b8c..1bb30930 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -58,9 +58,8 @@ export type ArticlePageSearchParams = { const scrollTo = (el: HTMLElement) => { const { top } = el.getBoundingClientRect() - window.scrollTo({ - top: top + window.scrollY - DEFAULT_HEADER_OFFSET, + top: top - DEFAULT_HEADER_OFFSET, left: 0, behavior: 'smooth', }) @@ -152,22 +151,16 @@ export const FullArticle = (props: Props) => { current: HTMLDivElement } = { current: null } - const scrollToComments = () => { - scrollTo(commentsRef.current) - } - createEffect(() => { if (props.scrollToComments) { - scrollToComments() + scrollTo(commentsRef.current) } }) createEffect(() => { if (searchParams()?.scrollTo === 'comments' && commentsRef.current) { - scrollToComments() - changeSearchParams({ - scrollTo: null, - }) + requestAnimationFrame(() => scrollTo(commentsRef.current)) + changeSearchParams({ scrollTo: null }) } }) @@ -177,10 +170,8 @@ export const FullArticle = (props: Props) => { `[id='comment_${searchParams().commentId}']`, ) - changeSearchParams({ commentId: null }) - if (commentElement) { - scrollTo(commentElement) + requestAnimationFrame(() => scrollTo(commentElement)) } } }) @@ -473,7 +464,11 @@ export const FullArticle = (props: Props) => { {(triggerRef: (el) => void) => ( -
    +
    scrollTo(commentsRef.current)} + > = Record< } const clearSearchParams = (replace = false) => { - searchParamsStore.open({}, replace) + // searchParamsStore.open({}, replace) } return { From 01a4b558bd983e007c15a069812a2a8706c65665 Mon Sep 17 00:00:00 2001 From: Tony <454794+tonyrewin@users.noreply.github.com> Date: Wed, 21 Feb 2024 17:25:28 +0300 Subject: [PATCH 12/13] api update (#417) * api update * query-fix --- .../Author/AuthorBadge/AuthorBadge.tsx | 2 +- .../Topic/TopicBadge/TopicBadge.tsx | 2 +- src/components/Views/Author/Author.tsx | 8 +--- src/components/Views/Home.tsx | 8 ++-- .../ProfileSubscriptions.tsx | 9 ++-- src/context/following.tsx | 20 +++------ src/graphql/client/core.ts | 43 ++++++++++--------- src/graphql/query/core/author-follows.ts | 20 +++++++++ src/graphql/query/core/authors-followed-by.ts | 17 -------- 9 files changed, 60 insertions(+), 69 deletions(-) create mode 100644 src/graphql/query/core/author-follows.ts delete mode 100644 src/graphql/query/core/authors-followed-by.ts diff --git a/src/components/Author/AuthorBadge/AuthorBadge.tsx b/src/components/Author/AuthorBadge/AuthorBadge.tsx index a3d7e74d..063cf8f7 100644 --- a/src/components/Author/AuthorBadge/AuthorBadge.tsx +++ b/src/components/Author/AuthorBadge/AuthorBadge.tsx @@ -120,7 +120,7 @@ export const AuthorBadge = (props: Props) => { 0}>
    - {t('PublicationsWithCount', { count: props.author.stat?.shouts ?? 0 })} + {t('PublicationsWithCount', { count: props.author?.stat.shouts ?? 0 })}
    diff --git a/src/components/Topic/TopicBadge/TopicBadge.tsx b/src/components/Topic/TopicBadge/TopicBadge.tsx index a4ccd348..9f7f712e 100644 --- a/src/components/Topic/TopicBadge/TopicBadge.tsx +++ b/src/components/Topic/TopicBadge/TopicBadge.tsx @@ -75,7 +75,7 @@ export const TopicBadge = (props: Props) => { when={props.topic.body} fallback={
    - {t('PublicationsWithCount', { count: props.topic.stat.shouts ?? 0 })} + {t('PublicationsWithCount', { count: props.topic?.stat?.shouts ?? 0 })}
    } > diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index bb62322c..5bcd6ba8 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -71,13 +71,7 @@ export const AuthorView = (props: Props) => { const fetchData = async (slug) => { try { const [subscriptionsResult, followersResult] = await Promise.all([ - (async () => { - const [getAuthors, getTopics] = await Promise.all([ - apiClient.getAuthorFollowingAuthors({ slug }), - apiClient.getAuthorFollowingTopics({ slug }), - ]) - return { authors: getAuthors, topics: getTopics } - })(), + apiClient.getAuthorFollows({ slug }), apiClient.getAuthorFollowers({ slug }), ]) diff --git a/src/components/Views/Home.tsx b/src/components/Views/Home.tsx index 200434b5..4e4dbce3 100644 --- a/src/components/Views/Home.tsx +++ b/src/components/Views/Home.tsx @@ -69,10 +69,12 @@ export const HomeView = (props: Props) => { } const result = await apiClient.getRandomTopicShouts(RANDOM_TOPIC_SHOUTS_COUNT) - if (!result) console.warn('[apiClient.getRandomTopicShouts] failed') + if (!result || result.error) console.warn('[apiClient.getRandomTopicShouts] failed') batch(() => { - if (result?.topic) setRandomTopic(result.topic) - if (result?.shouts) setRandomTopicArticles(result.shouts) + if (!result?.error) { + if (result?.topic) setRandomTopic(result.topic) + if (result?.shouts) setRandomTopicArticles(result.shouts) + } }) }) diff --git a/src/components/Views/ProfileSubscriptions/ProfileSubscriptions.tsx b/src/components/Views/ProfileSubscriptions/ProfileSubscriptions.tsx index 8c342356..6e1b4d8d 100644 --- a/src/components/Views/ProfileSubscriptions/ProfileSubscriptions.tsx +++ b/src/components/Views/ProfileSubscriptions/ProfileSubscriptions.tsx @@ -29,12 +29,9 @@ export const ProfileSubscriptions = () => { const fetchSubscriptions = async () => { try { const slug = author()?.slug - const [getAuthors, getTopics] = await Promise.all([ - apiClient.getAuthorFollowingAuthors({ slug }), - apiClient.getAuthorFollowingTopics({ slug }), - ]) - setFollowing([...getAuthors, ...getTopics]) - setFiltered([...getAuthors, ...getTopics]) + const authorFollows = await apiClient.getAuthorFollows({ slug }) + setFollowing([...authorFollows['authors']]) + setFiltered([...authorFollows['authors'], ...authorFollows['topics']]) } catch (error) { console.error('[fetchSubscriptions] :', error) throw error diff --git a/src/context/following.tsx b/src/context/following.tsx index b7a5ab0d..f3208ca9 100644 --- a/src/context/following.tsx +++ b/src/context/following.tsx @@ -2,20 +2,14 @@ import { Accessor, JSX, createContext, createEffect, createSignal, useContext } import { createStore } from 'solid-js/store' import { apiClient } from '../graphql/client/core' -import { Author, Community, FollowingEntity, Topic } from '../graphql/schema/core.gen' +import { AuthorFollows, FollowingEntity } from '../graphql/schema/core.gen' import { useSession } from './session' -type SubscriptionsData = { - topics?: Topic[] - authors?: Author[] - communities?: Community[] -} - interface FollowingContextType { loading: Accessor - subscriptions: SubscriptionsData - setSubscriptions: (subscriptions: SubscriptionsData) => void + subscriptions: AuthorFollows + setSubscriptions: (subscriptions: AuthorFollows) => void setFollowing: (what: FollowingEntity, slug: string, value: boolean) => void loadSubscriptions: () => void follow: (what: FollowingEntity, slug: string) => Promise @@ -29,7 +23,7 @@ export function useFollowing() { return useContext(FollowingContext) } -const EMPTY_SUBSCRIPTIONS = { +const EMPTY_SUBSCRIPTIONS: AuthorFollows = { topics: [], authors: [], communities: [], @@ -37,15 +31,15 @@ const EMPTY_SUBSCRIPTIONS = { export const FollowingProvider = (props: { children: JSX.Element }) => { const [loading, setLoading] = createSignal(false) - const [subscriptions, setSubscriptions] = createStore(EMPTY_SUBSCRIPTIONS) - const { author } = useSession() + const [subscriptions, setSubscriptions] = createStore(EMPTY_SUBSCRIPTIONS) + const { author, session } = useSession() const fetchData = async () => { setLoading(true) try { if (apiClient.private) { console.debug('[context.following] fetching subs data...') - const result = await apiClient.getMySubscriptions() + const result = await apiClient.getAuthorFollows({ user: session()?.user.id }) setSubscriptions(result || EMPTY_SUBSCRIPTIONS) console.info('[context.following] subs:', subscriptions) } diff --git a/src/graphql/client/core.ts b/src/graphql/client/core.ts index 752b4de4..d9fef87a 100644 --- a/src/graphql/client/core.ts +++ b/src/graphql/client/core.ts @@ -1,7 +1,7 @@ import type { Author, + AuthorFollows, CommonResult, - Community, FollowingEntity, LoadShoutsOptions, MutationDelete_ShoutArgs, @@ -37,16 +37,14 @@ 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 authorFollows from '../query/core/author-follows' import authorId from '../query/core/author-id' import authorsAll from '../query/core/authors-all' -import authorFollowedAuthors from '../query/core/authors-followed-by' import authorsLoadBy from '../query/core/authors-load-by' -import authorFollowedCommunities from '../query/core/communities-followed-by' import mySubscriptions from '../query/core/my-followed' import reactionsLoadBy from '../query/core/reactions-load-by' import topicBySlug from '../query/core/topic-by-slug' import topicsAll from '../query/core/topics-all' -import authorFollowedTopics from '../query/core/topics-followed-by' import topicsRandomQuery from '../query/core/topics-random' const publicGraphQLClient = createGraphQLClient('core') @@ -86,7 +84,7 @@ export const apiClient = { return response.data.get_topics_random }, - getRandomTopicShouts: async (limit: number): Promise<{ topic: Topic; shouts: Shout[] }> => { + getRandomTopicShouts: async (limit: number): Promise => { const resp = await publicGraphQLClient.query(articlesLoadRandomTopic, { limit }).toPromise() if (!resp.data) console.error('[graphql.client.core] load_shouts_random_topic', resp) return resp.data.load_shouts_random_topic @@ -96,6 +94,7 @@ export const apiClient = { const response = await apiClient.private.mutation(followMutation, { what, slug }).toPromise() return response.data.follow }, + unfollow: async ({ what, slug }: { what: FollowingEntity; slug: string }) => { const response = await apiClient.private.mutation(unfollowMutation, { what, slug }).toPromise() return response.data.unfollow @@ -107,48 +106,53 @@ export const apiClient = { return response.data.get_topics_all }, + getAllAuthors: async () => { const response = await publicGraphQLClient.query(authorsAll, {}).toPromise() if (!response.data) console.error('[graphql.client.core] getAllAuthors', response) return response.data.get_authors_all }, + getAuthor: async (params: { slug?: string; author_id?: number }): Promise => { const response = await publicGraphQLClient.query(authorBy, params).toPromise() return response.data.get_author }, + getAuthorId: async (params: { user: string }): Promise => { const response = await publicGraphQLClient.query(authorId, params).toPromise() return response.data.get_author_id }, + getAuthorFollowers: async ({ slug }: { slug: string }): Promise => { const response = await publicGraphQLClient.query(authorFollowers, { slug }).toPromise() return response.data.get_author_followers }, - getAuthorFollowingAuthors: async ({ slug }: { slug: string }): Promise => { - const response = await publicGraphQLClient.query(authorFollowedAuthors, { slug }).toPromise() - return response.data.get_author_followed - }, - getAuthorFollowingTopics: async ({ slug }: { slug: string }): Promise => { - const response = await publicGraphQLClient.query(authorFollowedTopics, { slug }).toPromise() - return response.data.get_topics_by_author - }, - getAuthorFollowingCommunities: async ({ slug }: { slug: string }): Promise => { - const response = await publicGraphQLClient.query(authorFollowedCommunities, { slug }).toPromise() - return response.data.get_communities_by_author + + getAuthorFollows: async (params: { + slug?: string + author_id?: number + user?: string + }): Promise => { + const response = await publicGraphQLClient.query(authorFollows, params).toPromise() + return response.data.get_author_follows }, + updateAuthor: async (input: ProfileInput) => { const response = await apiClient.private.mutation(updateAuthor, { profile: input }).toPromise() return response.data.update_author }, + getTopic: async ({ slug }: { slug: string }): Promise => { const response = await publicGraphQLClient.query(topicBySlug, { slug }).toPromise() return response.data.get_topic }, + createArticle: async ({ article }: { article: ShoutInput }): Promise => { const response = await apiClient.private.mutation(createArticle, { shout: article }).toPromise() return response.data.create_shout.shout }, + updateArticle: async ({ shout_id, shout_input, @@ -164,10 +168,12 @@ export const apiClient = { console.debug('[graphql.client.core] updateArticle:', response.data) return response.data.update_shout.shout }, + deleteShout: async (params: MutationDelete_ShoutArgs): Promise => { const response = await apiClient.private.mutation(deleteShout, params).toPromise() console.debug('[graphql.client.core] deleteShout:', response) }, + getDrafts: async (): Promise => { const response = await apiClient.private.query(draftsLoad, {}).toPromise() console.debug('[graphql.client.core] getDrafts:', response) @@ -231,9 +237,4 @@ export const apiClient = { .toPromise() return resp.data.load_reactions_by }, - getMySubscriptions: async (): Promise => { - const resp = await apiClient.private.query(mySubscriptions, {}).toPromise() - - return resp.data.get_my_followed - }, } diff --git a/src/graphql/query/core/author-follows.ts b/src/graphql/query/core/author-follows.ts new file mode 100644 index 00000000..b1c8c0ce --- /dev/null +++ b/src/graphql/query/core/author-follows.ts @@ -0,0 +1,20 @@ +import { gql } from '@urql/core' + +export default gql` + query GetAuthorFollows($slug: String, $user: String, $author_id: Int) { + get_author_follows(slug: $slug, user: $user, author_id: $author_id) { + authors { + id + slug + name + pic + bio + } + topics { + id + slug + title + } + } + } +` diff --git a/src/graphql/query/core/authors-followed-by.ts b/src/graphql/query/core/authors-followed-by.ts deleted file mode 100644 index 06f6f5e9..00000000 --- a/src/graphql/query/core/authors-followed-by.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query AuthorsFollowedByQuery($slug: String, $user: String, $author_id: Int) { - get_author_followed(slug: $slug, user: $user, author_id: $author_id) { - id - slug - name - pic - bio - created_at - stat { - shouts - } - } - } -` From 4e931a39c5993fdb55c28a6d66e5c1394e17c0c4 Mon Sep 17 00:00:00 2001 From: Ilya Y <75578537+ilya-bkv@users.noreply.github.com> Date: Thu, 22 Feb 2024 10:29:52 +0300 Subject: [PATCH 13/13] Feature/all authors order (#410) Load Authors by btn click --------- Co-authored-by: Untone --- .husky/pre-commit | 4 - public/locales/en/translation.json | 1 + public/locales/ru/translation.json | 3 +- .../AuthorBadge/AuthorBadge.module.scss | 5 + .../Author/AuthorBadge/AuthorBadge.tsx | 15 +- .../AuthorsList/AuthorsList.module.scss | 26 ++ src/components/AuthorsList/AuthorsList.tsx | 90 +++++++ src/components/AuthorsList/index.ts | 1 + .../InlineLoader/InlineLoader.module.scss | 18 ++ src/components/InlineLoader/InlineLoader.tsx | 20 ++ src/components/InlineLoader/index.ts | 1 + src/components/Views/AllAuthors.tsx | 234 ------------------ .../{ => AllAuthors}/AllAuthors.module.scss | 2 + .../Views/AllAuthors/AllAuthors.tsx | 177 +++++++++++++ src/components/Views/AllAuthors/index.ts | 1 + .../InviteMembers/InviteMembers.module.scss | 18 -- .../_shared/InviteMembers/InviteMembers.tsx | 10 +- src/pages/allAuthors.page.tsx | 6 +- src/stores/zine/authors.ts | 8 +- 19 files changed, 368 insertions(+), 272 deletions(-) delete mode 100755 .husky/pre-commit create mode 100644 src/components/AuthorsList/AuthorsList.module.scss create mode 100644 src/components/AuthorsList/AuthorsList.tsx create mode 100644 src/components/AuthorsList/index.ts create mode 100644 src/components/InlineLoader/InlineLoader.module.scss create mode 100644 src/components/InlineLoader/InlineLoader.tsx create mode 100644 src/components/InlineLoader/index.ts delete mode 100644 src/components/Views/AllAuthors.tsx rename src/components/Views/{ => AllAuthors}/AllAuthors.module.scss (99%) create mode 100644 src/components/Views/AllAuthors/AllAuthors.tsx create mode 100644 src/components/Views/AllAuthors/index.ts diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100755 index d4a43dd1..00000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - -npm run pre-commit diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 113182a4..5dfd02bb 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -291,6 +291,7 @@ "Profile": "Profile", "Publications": "Publications", "PublicationsWithCount": "{count, plural, =0 {no publications} one {{count} publication} other {{count} publications}}", + "FollowersWithCount": "{count, plural, =0 {no followers} one {{count} follower} other {{count} followers}}", "Publish Album": "Publish Album", "Publish Settings": "Publish Settings", "Published": "Published", diff --git a/public/locales/ru/translation.json b/public/locales/ru/translation.json index bcdc7e2c..647917b0 100644 --- a/public/locales/ru/translation.json +++ b/public/locales/ru/translation.json @@ -309,9 +309,10 @@ "Publication settings": "Настройки публикации", "Publications": "Публикации", "PublicationsWithCount": "{count, plural, =0 {нет публикаций} one {{count} публикация} few {{count} публикации} other {{count} публикаций}}", + "FollowersWithCount": "{count, plural, =0 {нет подписчиков} one {{count} подписчик} few {{count} подписчика} other {{count} подписчиков}}", + "Publish": "Опубликовать", "Publish Album": "Опубликовать альбом", "Publish Settings": "Настройки публикации", - "Publish": "Опубликовать", "Published": "Опубликованные", "Punchline": "Панчлайн", "Quit": "Выйти", diff --git a/src/components/Author/AuthorBadge/AuthorBadge.module.scss b/src/components/Author/AuthorBadge/AuthorBadge.module.scss index e78f10ca..8dc68f4b 100644 --- a/src/components/Author/AuthorBadge/AuthorBadge.module.scss +++ b/src/components/Author/AuthorBadge/AuthorBadge.module.scss @@ -58,6 +58,11 @@ } .bio { + @include font-size(1.2rem); + + display: flex; + flex-direction: row; + gap: 1rem; color: var(--black-400); font-weight: 500; } diff --git a/src/components/Author/AuthorBadge/AuthorBadge.tsx b/src/components/Author/AuthorBadge/AuthorBadge.tsx index 063cf8f7..e0ef0334 100644 --- a/src/components/Author/AuthorBadge/AuthorBadge.tsx +++ b/src/components/Author/AuthorBadge/AuthorBadge.tsx @@ -118,12 +118,17 @@ export const AuthorBadge = (props: Props) => {
    - 0}> -
    - {t('PublicationsWithCount', { count: props.author?.stat.shouts ?? 0 })} -
    -
    + +
    + 0}> +
    {t('PublicationsWithCount', { count: props.author.stat?.shouts ?? 0 })}
    +
    + 0}> +
    {t('FollowersWithCount', { count: props.author.stat?.followers ?? 0 })}
    +
    +
    +
    diff --git a/src/components/AuthorsList/AuthorsList.module.scss b/src/components/AuthorsList/AuthorsList.module.scss new file mode 100644 index 00000000..bad088be --- /dev/null +++ b/src/components/AuthorsList/AuthorsList.module.scss @@ -0,0 +1,26 @@ +.AuthorsList { + .action { + display: flex; + align-items: center; + justify-content: center; + min-height: 8rem; + } + + .loading { + @include font-size(1.4rem); + + display: flex; + align-items: center; + justify-content: center; + gap: 1rem; + width: 100%; + flex-direction: row; + opacity: 0.5; + + .icon { + position: relative; + width: 18px; + height: 18px; + } + } +} diff --git a/src/components/AuthorsList/AuthorsList.tsx b/src/components/AuthorsList/AuthorsList.tsx new file mode 100644 index 00000000..236a586e --- /dev/null +++ b/src/components/AuthorsList/AuthorsList.tsx @@ -0,0 +1,90 @@ +import { clsx } from 'clsx' +import { For, Show, createEffect, createSignal } from 'solid-js' +import { useFollowing } from '../../context/following' +import { useLocalize } from '../../context/localize' +import { apiClient } from '../../graphql/client/core' +import { setAuthorsByFollowers, setAuthorsByShouts, useAuthorsStore } from '../../stores/zine/authors' +import { AuthorBadge } from '../Author/AuthorBadge' +import { InlineLoader } from '../InlineLoader' +import { Button } from '../_shared/Button' +import styles from './AuthorsList.module.scss' + +type Props = { + class?: string + query: 'shouts' | 'followers' +} + +const PAGE_SIZE = 20 +export const AuthorsList = (props: Props) => { + const { t } = useLocalize() + const { isOwnerSubscribed } = useFollowing() + const [loading, setLoading] = createSignal(false) + const [currentPage, setCurrentPage] = createSignal({ shouts: 0, followers: 0 }) + const { authorsByShouts, authorsByFollowers } = useAuthorsStore() + + const fetchAuthors = async (queryType: 'shouts' | 'followers', page: number) => { + setLoading(true) + const offset = PAGE_SIZE * page + const result = await apiClient.loadAuthorsBy({ + by: { order: queryType }, + limit: PAGE_SIZE, + offset: offset, + }) + + if (queryType === 'shouts') { + setAuthorsByShouts((prev) => [...prev, ...result]) + } else { + setAuthorsByFollowers((prev) => [...prev, ...result]) + } + setLoading(false) + return result + } + + const loadMoreAuthors = () => { + const queryType = props.query + const nextPage = currentPage()[queryType] + 1 + fetchAuthors(queryType, nextPage).then(() => + setCurrentPage({ ...currentPage(), [queryType]: nextPage }), + ) + } + + createEffect(() => { + const queryType = props.query + if ( + currentPage()[queryType] === 0 && + (authorsByShouts().length === 0 || authorsByFollowers().length === 0) + ) { + loadMoreAuthors() + } + }) + + const authorsList = () => (props.query === 'shouts' ? authorsByShouts() : authorsByFollowers()) + + return ( +
    + + {(author) => ( +
    +
    + +
    +
    + )} +
    +
    + +
    +
    + ) +} diff --git a/src/components/AuthorsList/index.ts b/src/components/AuthorsList/index.ts new file mode 100644 index 00000000..4187ebae --- /dev/null +++ b/src/components/AuthorsList/index.ts @@ -0,0 +1 @@ +export { AuthorsList } from './AuthorsList' diff --git a/src/components/InlineLoader/InlineLoader.module.scss b/src/components/InlineLoader/InlineLoader.module.scss new file mode 100644 index 00000000..dc90c7bd --- /dev/null +++ b/src/components/InlineLoader/InlineLoader.module.scss @@ -0,0 +1,18 @@ +.InlineLoader { + @include font-size(1.4rem); + + display: flex; + align-items: center; + justify-content: center; + gap: 1rem; + width: 100%; + flex-direction: row; + opacity: 0.5; + + .icon { + position: relative; + width: 18px; + height: 18px; + } + +} diff --git a/src/components/InlineLoader/InlineLoader.tsx b/src/components/InlineLoader/InlineLoader.tsx new file mode 100644 index 00000000..6f36ff4e --- /dev/null +++ b/src/components/InlineLoader/InlineLoader.tsx @@ -0,0 +1,20 @@ +import { clsx } from 'clsx' +import { useLocalize } from '../../context/localize' +import { Loading } from '../_shared/Loading' +import styles from './InlineLoader.module.scss' + +type Props = { + class?: string +} + +export const InlineLoader = (props: Props) => { + const { t } = useLocalize() + return ( +
    +
    + +
    +
    {t('Loading')}
    +
    + ) +} diff --git a/src/components/InlineLoader/index.ts b/src/components/InlineLoader/index.ts new file mode 100644 index 00000000..c94c5a50 --- /dev/null +++ b/src/components/InlineLoader/index.ts @@ -0,0 +1 @@ +export { InlineLoader } from './InlineLoader' diff --git a/src/components/Views/AllAuthors.tsx b/src/components/Views/AllAuthors.tsx deleted file mode 100644 index 6275621f..00000000 --- a/src/components/Views/AllAuthors.tsx +++ /dev/null @@ -1,234 +0,0 @@ -import type { Author } from '../../graphql/schema/core.gen' - -import { Meta } from '@solidjs/meta' -import { clsx } from 'clsx' -import { For, Show, createEffect, createMemo, createSignal } from 'solid-js' - -import { useFollowing } from '../../context/following' -import { useLocalize } from '../../context/localize' -import { useRouter } from '../../stores/router' -import { loadAuthors, setAuthorsSort, useAuthorsStore } from '../../stores/zine/authors' -import { dummyFilter } from '../../utils/dummyFilter' -import { getImageUrl } from '../../utils/getImageUrl' -import { scrollHandler } from '../../utils/scroll' -import { authorLetterReduce, translateAuthor } from '../../utils/translate' -import { AuthorBadge } from '../Author/AuthorBadge' -import { Loading } from '../_shared/Loading' -import { SearchField } from '../_shared/SearchField' - -import styles from './AllAuthors.module.scss' - -type AllAuthorsPageSearchParams = { - by: '' | 'name' | 'shouts' | 'followers' -} - -type Props = { - authors: Author[] - isLoaded: boolean -} - -const PAGE_SIZE = 20 - -export const AllAuthorsView = (props: Props) => { - const { t, lang } = useLocalize() - const ALPHABET = - lang() === 'ru' ? [...'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ@'] : [...'ABCDEFGHIJKLMNOPQRSTUVWXYZ@'] - const [offsetByShouts, setOffsetByShouts] = createSignal(0) - const [offsetByFollowers, setOffsetByFollowers] = createSignal(0) - const { searchParams, changeSearchParams } = useRouter() - const { sortedAuthors } = useAuthorsStore({ - authors: props.authors, - sortBy: searchParams().by || 'name', - }) - - const [searchQuery, setSearchQuery] = createSignal('') - const offset = searchParams()?.by === 'shouts' ? offsetByShouts : offsetByFollowers - createEffect(() => { - let by = searchParams().by - if (by) { - setAuthorsSort(by) - } else { - by = 'name' - changeSearchParams({ by }) - } - }) - - const loadMoreByShouts = async () => { - await loadAuthors({ by: { order: 'shouts_stat' }, limit: PAGE_SIZE, offset: offsetByShouts() }) - setOffsetByShouts((o) => o + PAGE_SIZE) - } - const loadMoreByFollowers = async () => { - await loadAuthors({ by: { order: 'followers_stat' }, limit: PAGE_SIZE, offset: offsetByFollowers() }) - setOffsetByFollowers((o) => o + PAGE_SIZE) - } - - const isStatsLoaded = createMemo(() => sortedAuthors()?.some((author) => author.stat)) - - createEffect(async () => { - if (!isStatsLoaded()) { - await loadMoreByShouts() - await loadMoreByFollowers() - } - }) - - const showMore = async () => - await { - shouts: loadMoreByShouts, - followers: loadMoreByFollowers, - }[searchParams().by]() - - const byLetter = createMemo<{ [letter: string]: Author[] }>(() => { - return sortedAuthors().reduce( - (acc, author) => authorLetterReduce(acc, author, lang()), - {} as { [letter: string]: Author[] }, - ) - }) - - const { isOwnerSubscribed } = useFollowing() - - const sortedKeys = createMemo(() => { - const keys = Object.keys(byLetter()) - keys.sort() - keys.push(keys.shift()) - return keys - }) - - const filteredAuthors = createMemo(() => { - return dummyFilter(sortedAuthors(), searchQuery(), lang()) - }) - - const ogImage = getImageUrl('production/image/logo_image.png') - const ogTitle = t('Authors') - const description = t('List of authors of the open editorial community') - - return ( -
    - - - - - - - - - - - }> -
    -
    -
    -

    {t('Authors')}

    -

    {t('Subscribe who you like to tune your personal feed')}

    - - - -
    -
    - - 0}> - - - - - {(letter) => ( -
    -

    {letter}

    -
    -
    -
    -
    - - {(author) => ( -
    -
    - {translateAuthor(author, lang())} - - {author.stat.shouts} - -
    -
    - )} -
    -
    -
    -
    -
    -
    - )} -
    -
    - - - - {(author) => ( -
    -
    - -
    -
    - )} -
    -
    - - PAGE_SIZE + offset() && searchParams().by !== 'name'}> -
    -
    - -
    -
    -
    -
    -
    -
    -
    - ) -} diff --git a/src/components/Views/AllAuthors.module.scss b/src/components/Views/AllAuthors/AllAuthors.module.scss similarity index 99% rename from src/components/Views/AllAuthors.module.scss rename to src/components/Views/AllAuthors/AllAuthors.module.scss index 94d4302c..63188b2b 100644 --- a/src/components/Views/AllAuthors.module.scss +++ b/src/components/Views/AllAuthors/AllAuthors.module.scss @@ -81,3 +81,5 @@ overflow-x: auto; } } + + diff --git a/src/components/Views/AllAuthors/AllAuthors.tsx b/src/components/Views/AllAuthors/AllAuthors.tsx new file mode 100644 index 00000000..c1723891 --- /dev/null +++ b/src/components/Views/AllAuthors/AllAuthors.tsx @@ -0,0 +1,177 @@ +import type { Author } from '../../../graphql/schema/core.gen' + +import { Meta } from '@solidjs/meta' +import { clsx } from 'clsx' +import { For, Show, createEffect, createMemo, createSignal } from 'solid-js' + +import { useLocalize } from '../../../context/localize' +import { useRouter } from '../../../stores/router' +import { setAuthorsSort, useAuthorsStore } from '../../../stores/zine/authors' +import { getImageUrl } from '../../../utils/getImageUrl' +import { scrollHandler } from '../../../utils/scroll' +import { authorLetterReduce, translateAuthor } from '../../../utils/translate' + +import { AuthorsList } from '../../AuthorsList' +import { Loading } from '../../_shared/Loading' +import { SearchField } from '../../_shared/SearchField' + +import styles from './AllAuthors.module.scss' + +type AllAuthorsPageSearchParams = { + by: '' | 'name' | 'shouts' | 'followers' +} + +type Props = { + authors: Author[] + isLoaded: boolean +} + +export const AllAuthors = (props: Props) => { + const { t, lang } = useLocalize() + const ALPHABET = + lang() === 'ru' ? [...'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ@'] : [...'ABCDEFGHIJKLMNOPQRSTUVWXYZ@'] + const { searchParams, changeSearchParams } = useRouter() + const { sortedAuthors } = useAuthorsStore({ + authors: props.authors, + sortBy: searchParams().by || 'name', + }) + + const [searchQuery, setSearchQuery] = createSignal('') + + createEffect(() => { + let by = searchParams().by + if (by) { + setAuthorsSort(by) + } else { + by = 'name' + changeSearchParams({ by }) + } + }) + + const byLetter = createMemo<{ [letter: string]: Author[] }>(() => { + return sortedAuthors().reduce( + (acc, author) => authorLetterReduce(acc, author, lang()), + {} as { [letter: string]: Author[] }, + ) + }) + + const sortedKeys = createMemo(() => { + const keys = Object.keys(byLetter()) + keys.sort() + keys.push(keys.shift()) + return keys + }) + + const ogImage = getImageUrl('production/image/logo_image.png') + const ogTitle = t('Authors') + const description = t('List of authors of the open editorial community') + + return ( +
    + + + + + + + + + + + }> +
    +
    +
    +

    {t('Authors')}

    +

    {t('Subscribe who you like to tune your personal feed')}

    + +
    +
    + + + + + {(letter) => ( +
    +

    {letter}

    +
    +
    +
    +
    + + {(author) => ( +
    +
    + {translateAuthor(author, lang())} + + {author.stat.shouts} + +
    +
    + )} +
    +
    +
    +
    +
    +
    + )} +
    +
    + }> + + +
    +
    +
    + ) +} diff --git a/src/components/Views/AllAuthors/index.ts b/src/components/Views/AllAuthors/index.ts new file mode 100644 index 00000000..13e92537 --- /dev/null +++ b/src/components/Views/AllAuthors/index.ts @@ -0,0 +1 @@ +export { AllAuthors } from './AllAuthors' diff --git a/src/components/_shared/InviteMembers/InviteMembers.module.scss b/src/components/_shared/InviteMembers/InviteMembers.module.scss index 8710a65a..0e9f8964 100644 --- a/src/components/_shared/InviteMembers/InviteMembers.module.scss +++ b/src/components/_shared/InviteMembers/InviteMembers.module.scss @@ -50,24 +50,6 @@ } } - .loading { - @include font-size(1.4rem); - - display: flex; - align-items: center; - justify-content: center; - gap: 1rem; - width: 100%; - flex-direction: row; - opacity: 0.5; - - .icon { - position: relative; - width: 18px; - height: 18px; - } - } - .teaser { min-height: 300px; display: flex; diff --git a/src/components/_shared/InviteMembers/InviteMembers.tsx b/src/components/_shared/InviteMembers/InviteMembers.tsx index 0458c7a5..3eca7cdc 100644 --- a/src/components/_shared/InviteMembers/InviteMembers.tsx +++ b/src/components/_shared/InviteMembers/InviteMembers.tsx @@ -12,6 +12,7 @@ import { Button } from '../Button' import { DropdownSelect } from '../DropdownSelect' import { Loading } from '../Loading' +import { InlineLoader } from '../../InlineLoader' import styles from './InviteMembers.module.scss' type InviteAuthor = Author & { selected: boolean } @@ -62,7 +63,7 @@ export const InviteMembers = (props: Props) => { return authors?.slice(start, end) } - const [pages, _infiniteScrollLoader, { end }] = createInfiniteScroll(fetcher) + const [pages, setEl, { end }] = createInfiniteScroll(fetcher) createEffect( on( @@ -158,11 +159,8 @@ export const InviteMembers = (props: Props) => { )} -
    -
    - -
    -
    {t('Loading')}
    +
    void}> +
    diff --git a/src/pages/allAuthors.page.tsx b/src/pages/allAuthors.page.tsx index 87a427b2..7079e8af 100644 --- a/src/pages/allAuthors.page.tsx +++ b/src/pages/allAuthors.page.tsx @@ -1,8 +1,8 @@ import type { PageProps } from './types' -import { createSignal, onMount } from 'solid-js' +import { createEffect, createSignal, onMount } from 'solid-js' -import { AllAuthorsView } from '../components/Views/AllAuthors' +import { AllAuthors } from '../components/Views/AllAuthors/' import { PageLayout } from '../components/_shared/PageLayout' import { useLocalize } from '../context/localize' import { loadAllAuthors } from '../stores/zine/authors' @@ -23,7 +23,7 @@ export const AllAuthorsPage = (props: PageProps) => { return ( - + ) } diff --git a/src/stores/zine/authors.ts b/src/stores/zine/authors.ts index db3f0627..c046737a 100644 --- a/src/stores/zine/authors.ts +++ b/src/stores/zine/authors.ts @@ -6,6 +6,7 @@ import { Author, QueryLoad_Authors_ByArgs } from '../../graphql/schema/core.gen' import { byStat } from '../../utils/sortby' export type AuthorsSortBy = 'shouts' | 'name' | 'followers' +type SortedAuthorsSetter = (prev: Author[]) => Author[] const [sortAllBy, setSortAllBy] = createSignal('name') @@ -13,6 +14,11 @@ export const setAuthorsSort = (sortBy: AuthorsSortBy) => setSortAllBy(sortBy) const [authorEntities, setAuthorEntities] = createSignal<{ [authorSlug: string]: Author }>({}) const [authorsByTopic, setAuthorsByTopic] = createSignal<{ [topicSlug: string]: Author[] }>({}) +const [authorsByShouts, setSortedAuthorsByShout] = createSignal([]) +const [authorsByFollowers, setSortedAuthorsByFollowers] = createSignal([]) + +export const setAuthorsByShouts = (authors: SortedAuthorsSetter) => setSortedAuthorsByShout(authors) +export const setAuthorsByFollowers = (authors: SortedAuthorsSetter) => setSortedAuthorsByFollowers(authors) const sortedAuthors = createLazyMemo(() => { const authors = Object.values(authorEntities()) @@ -108,5 +114,5 @@ export const useAuthorsStore = (initialState: InitialState = {}) => { } addAuthors([...(initialState.authors || [])]) - return { authorEntities, sortedAuthors, authorsByTopic } + return { authorEntities, sortedAuthors, authorsByTopic, authorsByShouts, authorsByFollowers } }