From 652d0b647aaabfb35fbac0f1042067deed61dbd3 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 20 May 2024 14:16:54 +0300 Subject: [PATCH] refactoring:following --- public/locales/en/translation.json | 2 +- public/locales/ru/translation.json | 2 +- .../Author/AuthorBadge/AuthorBadge.tsx | 26 ++-- .../Author/AuthorCard/AuthorCard.tsx | 46 +++---- src/components/Editor/extensions/Article.ts | 22 ++-- .../Editor/extensions/CustomBlockquote.ts | 16 ++- src/components/Feed/Sidebar/Sidebar.tsx | 8 +- src/components/Topic/Card.module.scss | 6 +- src/components/Topic/Card.tsx | 47 ++++---- src/components/Topic/Full.tsx | 9 +- .../Topic/TopicBadge/TopicBadge.module.scss | 9 +- .../Topic/TopicBadge/TopicBadge.tsx | 37 +++--- src/components/Views/Author/Author.tsx | 53 +++++---- .../ProfileSubscriptions.tsx | 55 +++++---- .../_shared/BadgeSubscribeButton/index.ts | 1 - .../_shared/Button/Button.module.scss | 4 +- .../FollowingButton.module.scss} | 0 .../FollowingButton.tsx} | 27 +++-- .../_shared/FollowingButton/index.ts | 1 + src/context/following.tsx | 112 +++++++++--------- src/graphql/mutation/core/follow.ts | 17 +++ src/graphql/mutation/core/unfollow.ts | 21 ++++ src/pages/types.ts | 2 +- vite.config.ts | 3 +- 24 files changed, 290 insertions(+), 236 deletions(-) delete mode 100644 src/components/_shared/BadgeSubscribeButton/index.ts rename src/components/_shared/{BadgeSubscribeButton/BadgeDubscribeButton.module.scss => FollowingButton/FollowingButton.module.scss} (100%) rename src/components/_shared/{BadgeSubscribeButton/BadgeSubscribeButton.tsx => FollowingButton/FollowingButton.tsx} (78%) create mode 100644 src/components/_shared/FollowingButton/index.ts diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 1d8a1736..37b99313 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -541,4 +541,4 @@ "You've reached a non-existed page": "You've reached a non-existed page", "Your email": "Your email", "Your name will appear on your profile page and as your signature in publications, comments and responses.": "Your name will appear on your profile page and as your signature in publications, comments and responses" -} \ No newline at end of file +} diff --git a/public/locales/ru/translation.json b/public/locales/ru/translation.json index 1a29a4ac..3c4517a0 100644 --- a/public/locales/ru/translation.json +++ b/public/locales/ru/translation.json @@ -568,4 +568,4 @@ "You've successfully logged out": "Вы успешно вышли из аккаунта", "Your email": "Ваш email", "Your name will appear on your profile page and as your signature in publications, comments and responses.": "Ваше имя появится на странице вашего профиля и как ваша подпись в публикациях, комментариях и откликах" -} \ No newline at end of file +} diff --git a/src/components/Author/AuthorBadge/AuthorBadge.tsx b/src/components/Author/AuthorBadge/AuthorBadge.tsx index b8260e2a..3a35caac 100644 --- a/src/components/Author/AuthorBadge/AuthorBadge.tsx +++ b/src/components/Author/AuthorBadge/AuthorBadge.tsx @@ -10,17 +10,17 @@ import { Author, FollowingEntity } from '../../../graphql/schema/core.gen' import { router, useRouter } from '../../../stores/router' import { translit } from '../../../utils/ru2en' import { isCyrillic } from '../../../utils/translate' -import { BadgeSubscribeButton } from '../../_shared/BadgeSubscribeButton' import { Button } from '../../_shared/Button' import { CheckButton } from '../../_shared/CheckButton' import { ConditionalWrapper } from '../../_shared/ConditionalWrapper' +import { FollowingButton } from '../../_shared/FollowingButton' import { Icon } from '../../_shared/Icon' import { Userpic } from '../Userpic' import styles from './AuthorBadge.module.scss' type Props = { author: Author - minimizeSubscribeButton?: boolean + minimize?: boolean showMessageButton?: boolean iconButtons?: boolean nameOnly?: boolean @@ -32,14 +32,14 @@ type Props = { export const AuthorBadge = (props: Props) => { const { mediaMatches } = useMediaQuery() const { author, requireAuthentication } = useSession() - const { follow, unfollow, subscriptions, subscribeInAction } = useFollowing() + const { follow, unfollow, follows, following } = useFollowing() const [isMobileView, setIsMobileView] = createSignal(false) - const [isSubscribed, setIsSubscribed] = createSignal() + const [isFollowed, setIsFollowed] = createSignal() createEffect(() => { - if (!(subscriptions && props.author)) return - const subscribed = subscriptions.authors?.some((authorEntity) => authorEntity.id === props.author?.id) - setIsSubscribed(subscribed) + if (!(follows && props.author)) return + const followed = follows?.authors?.some((authorEntity) => authorEntity.id === props.author?.id) + setIsFollowed(followed) }) createEffect(() => { @@ -73,9 +73,9 @@ export const AuthorBadge = (props: Props) => { const handleFollowClick = () => { requireAuthentication(async () => { - const handle = isSubscribed() ? unfollow : follow + const handle = isFollowed() ? unfollow : follow await handle(FollowingEntity.Author, props.author.slug) - }, 'subscribe') + }, 'follow') } return ( @@ -131,12 +131,10 @@ export const AuthorBadge = (props: Props) => {
- handleFollowClick()} - isSubscribed={isSubscribed()} - actionMessageType={ - subscribeInAction()?.slug === props.author.slug ? subscribeInAction().type : undefined - } + isFollowed={isFollowed()} + actionMessageType={following()?.slug === props.author.slug ? following().type : undefined} /> {props.following.length}
  • - @@ -294,10 +294,10 @@ export const AuthorCard = (props: Props) => {
  • - diff --git a/src/components/Editor/extensions/Article.ts b/src/components/Editor/extensions/Article.ts index 3725e96f..db0a02ce 100644 --- a/src/components/Editor/extensions/Article.ts +++ b/src/components/Editor/extensions/Article.ts @@ -30,7 +30,7 @@ export default Node.create({ addOptions() { return { 'data-type': 'incut', - }; + } }, addAttributes() { @@ -48,20 +48,20 @@ export default Node.create({ return { toggleArticle: () => - // eslint-disable-next-line unicorn/consistent-function-scoping - ({ commands }) => { - return commands.toggleWrap('article') - }, + // eslint-disable-next-line unicorn/consistent-function-scoping + ({ commands }) => { + return commands.toggleWrap('article') + }, setArticleFloat: (value) => - ({ commands }) => { - return commands.updateAttributes(this.name, { 'data-float': value }) - }, + ({ commands }) => { + return commands.updateAttributes(this.name, { 'data-float': value }) + }, setArticleBg: (value) => - ({ commands }) => { - return commands.updateAttributes(this.name, { 'data-bg': value }) - }, + ({ commands }) => { + return commands.updateAttributes(this.name, { 'data-bg': value }) + }, } }, }) diff --git a/src/components/Editor/extensions/CustomBlockquote.ts b/src/components/Editor/extensions/CustomBlockquote.ts index 70c10f98..024bd6c2 100644 --- a/src/components/Editor/extensions/CustomBlockquote.ts +++ b/src/components/Editor/extensions/CustomBlockquote.ts @@ -17,7 +17,7 @@ export const CustomBlockquote = Blockquote.extend({ content: 'block+', addOptions(): BlockquoteOptions { - return {} as BlockquoteOptions; + return {} as BlockquoteOptions }, addAttributes() { @@ -35,15 +35,13 @@ export const CustomBlockquote = Blockquote.extend({ addCommands() { return { toggleBlockquote: - (type) => ({ commands }) => commands.toggleWrap( - this.name, - { 'data-type': type } - ), + (type) => + ({ commands }) => + commands.toggleWrap(this.name, { 'data-type': type }), setBlockQuoteFloat: - (value) => ({ commands }) => commands.updateAttributes( - this.name, - { 'data-float': value } - ), + (value) => + ({ commands }) => + commands.updateAttributes(this.name, { 'data-float': value }), } }, }) diff --git a/src/components/Feed/Sidebar/Sidebar.tsx b/src/components/Feed/Sidebar/Sidebar.tsx index a116bc4b..313dd0b6 100644 --- a/src/components/Feed/Sidebar/Sidebar.tsx +++ b/src/components/Feed/Sidebar/Sidebar.tsx @@ -15,7 +15,7 @@ import styles from './Sidebar.module.scss' export const Sidebar = () => { const { t } = useLocalize() const { seen } = useSeen() - const { subscriptions } = useFollowing() + const { follows } = useFollowing() const { page } = useRouter() const { articlesByTopic, articlesByAuthor } = useArticlesStore() const [isSubscriptionsVisible, setSubscriptionsVisible] = createSignal(true) @@ -111,7 +111,7 @@ export const Sidebar = () => {
  • - 0 || subscriptions.topics.length > 0}> + 0 || follows?.topics?.length > 0}>

    { @@ -123,7 +123,7 @@ export const Sidebar = () => {

    -
    diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index 9c0423ba..026af7dd 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -39,54 +39,55 @@ const LOAD_MORE_PAGE_SIZE = 9 export const AuthorView = (props: Props) => { const { t } = useLocalize() - const { followers: myFollowers } = useFollowing() - const { session } = useSession() + const { followers: myFollowers, follows: myFollows } = useFollowing() + const { session, author: me } = useSession() const { sortedArticles } = useArticlesStore({ shouts: props.shouts }) const { page: getPage, searchParams } = useRouter() const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) const [isBioExpanded, setIsBioExpanded] = createSignal(false) const [author, setAuthor] = createSignal() const [followers, setFollowers] = createSignal([]) - const [following, setFollowing] = createSignal>([]) // flat AuthorFollowsResult + const [following, changeFollowing] = createSignal>([]) // flat AuthorFollowsResult const [showExpandBioControl, setShowExpandBioControl] = createSignal(false) const [commented, setCommented] = createSignal() const modal = MODALS[searchParams().m] const [sessionChecked, setSessionChecked] = createSignal(false) - createEffect(() => { - if ( - !sessionChecked() && - props.authorSlug && - session()?.user?.app_data?.profile?.slug === props.authorSlug - ) { - setSessionChecked(true) - const appdata = session()?.user.app_data - if (appdata) { - console.info('preloaded my own profile') - const { authors, profile, topics } = appdata - setFollowers(myFollowers) - setAuthor(profile) - setFollowing([...authors, ...topics]) - } - } - }) + createEffect( + on( + [() => sessionChecked(), () => props.authorSlug, () => session()?.user?.app_data?.profile?.slug], + ([checked, slug, mySlug]) => { + if (!checked && slug && mySlug === slug) { + setSessionChecked(true) + const appdata = session()?.user.app_data + if (appdata) { + console.info('preloaded my own profile') + setFollowers(myFollowers()) + setAuthor(me()) + const { authors, topics } = myFollows + changeFollowing([...authors, ...topics]) + } + } + }, + { defer: true }, + ), + ) const bioContainerRef: { current: HTMLDivElement } = { current: null } const bioWrapperRef: { current: HTMLDivElement } = { current: null } const fetchData = async (slug: string) => { try { - const [subscriptionsResult, followersResult, authorResult] = await Promise.all([ + const [followsResult, followersResult, authorResult] = await Promise.all([ apiClient.getAuthorFollows({ slug }), apiClient.getAuthorFollowers({ slug }), loadAuthor({ slug }), ]) - const { authors, topics } = subscriptionsResult - setAuthor(authorResult) - setFollowing([...(authors || []), ...(topics || [])]) - setFollowers(followersResult || []) - console.info('[components.Author] data loaded') + setAuthor(authorResult) + setFollowers(followersResult || []) + const { authors, topics } = followsResult + changeFollowing([...(authors || []), ...(topics || [])]) } catch (error) { console.error('[components.Author] fetch error', error) } diff --git a/src/components/Views/ProfileSubscriptions/ProfileSubscriptions.tsx b/src/components/Views/ProfileSubscriptions/ProfileSubscriptions.tsx index 26f1e3c8..26cf9ce1 100644 --- a/src/components/Views/ProfileSubscriptions/ProfileSubscriptions.tsx +++ b/src/components/Views/ProfileSubscriptions/ProfileSubscriptions.tsx @@ -1,12 +1,11 @@ import { clsx } from 'clsx' -import { For, Show, createEffect, createSignal } from 'solid-js' +import { For, Show, createEffect, createSignal, on } from 'solid-js' import { useFollowing } from '../../../context/following' import { useLocalize } from '../../../context/localize' import { Author, Topic } from '../../../graphql/schema/core.gen' -import { SubscriptionFilter } from '../../../pages/types' +import { FollowsFilter } from '../../../pages/types' import { dummyFilter } from '../../../utils/dummyFilter' -// TODO: refactor styles import { isAuthor } from '../../../utils/isAuthor' import { AuthorBadge } from '../../Author/AuthorBadge' import { ProfileSettingsNavigation } from '../../Nav/ProfileSettingsNavigation' @@ -19,30 +18,30 @@ import stylesSettings from '../../../styles/FeedSettings.module.scss' export const ProfileSubscriptions = () => { const { t, lang } = useLocalize() - const { subscriptions } = useFollowing() - const [following, setFollowing] = createSignal>([]) + const { follows } = useFollowing() + const [flatFollows, setFlatFollows] = createSignal>([]) const [filtered, setFiltered] = createSignal>([]) - const [subscriptionFilter, setSubscriptionFilter] = createSignal('all') + const [followsFilter, setFollowsFilter] = createSignal('all') const [searchQuery, setSearchQuery] = createSignal('') - createEffect(() => { - const { authors, topics } = subscriptions - if (authors || topics) { - const fdata = [...(authors || []), ...(topics || [])] - setFollowing(fdata) - if (subscriptionFilter() === 'authors') { - setFiltered(fdata.filter((s) => 'name' in s)) - } else if (subscriptionFilter() === 'topics') { - setFiltered(fdata.filter((s) => 'title' in s)) + createEffect(() => setFlatFollows([...(follows?.authors || []), ...(follows?.topics || [])])) + + createEffect( + on([flatFollows, followsFilter], ([flat, mode]) => { + if (mode === 'authors') { + setFiltered(flat.filter((s) => 'name' in s)) + } else if (mode === 'topics') { + setFiltered(flat.filter((s) => 'title' in s)) } else { - setFiltered(fdata) + setFiltered(flat) } - } - }) + }), + { defer: true }, + ) createEffect(() => { if (searchQuery()) { - setFiltered(dummyFilter(following(), searchQuery(), lang())) + setFiltered(dummyFilter(flatFollows(), searchQuery(), lang())) } }) @@ -60,32 +59,32 @@ export const ProfileSubscriptions = () => {

    {t('My subscriptions')}

    {t('Here you can manage all your Discours subscriptions')}

    - }> + }>
    • -
    • -
    • -
    • @@ -104,9 +103,9 @@ export const ProfileSubscriptions = () => { {(followingItem) => (
      {isAuthor(followingItem) ? ( - + ) : ( - + )}
      )} diff --git a/src/components/_shared/BadgeSubscribeButton/index.ts b/src/components/_shared/BadgeSubscribeButton/index.ts deleted file mode 100644 index b359ecff..00000000 --- a/src/components/_shared/BadgeSubscribeButton/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { BadgeSubscribeButton } from './BadgeSubscribeButton' diff --git a/src/components/_shared/Button/Button.module.scss b/src/components/_shared/Button/Button.module.scss index 5ab6be16..495c3466 100644 --- a/src/components/_shared/Button/Button.module.scss +++ b/src/components/_shared/Button/Button.module.scss @@ -175,7 +175,7 @@ } } - &.subscribed { + &.followed { background: #fff; color: #000; @@ -192,4 +192,4 @@ } } } -} +} \ No newline at end of file diff --git a/src/components/_shared/BadgeSubscribeButton/BadgeDubscribeButton.module.scss b/src/components/_shared/FollowingButton/FollowingButton.module.scss similarity index 100% rename from src/components/_shared/BadgeSubscribeButton/BadgeDubscribeButton.module.scss rename to src/components/_shared/FollowingButton/FollowingButton.module.scss diff --git a/src/components/_shared/BadgeSubscribeButton/BadgeSubscribeButton.tsx b/src/components/_shared/FollowingButton/FollowingButton.tsx similarity index 78% rename from src/components/_shared/BadgeSubscribeButton/BadgeSubscribeButton.tsx rename to src/components/_shared/FollowingButton/FollowingButton.tsx index e1d15773..a973364c 100644 --- a/src/components/_shared/BadgeSubscribeButton/BadgeSubscribeButton.tsx +++ b/src/components/_shared/FollowingButton/FollowingButton.tsx @@ -2,35 +2,36 @@ import { clsx } from 'clsx' import { Show, createMemo } from 'solid-js' import { useLocalize } from '../../../context/localize' import { Button } from '../Button' -import stylesButton from '../Button/Button.module.scss' import { CheckButton } from '../CheckButton' import { Icon } from '../Icon' -import styles from './BadgeDubscribeButton.module.scss' + +import stylesButton from '../Button/Button.module.scss' +import styles from './FollowingButton.module.scss' type Props = { class?: string - isSubscribed: boolean - minimizeSubscribeButton?: boolean + isFollowed: boolean + minimize?: boolean action: () => void iconButtons?: boolean - actionMessageType?: 'subscribe' | 'unsubscribe' + actionMessageType?: 'follow' | 'unfollow' } -export const BadgeSubscribeButton = (props: Props) => { +export const FollowingButton = (props: Props) => { const { t } = useLocalize() const inActionText = createMemo(() => { - return props.actionMessageType === 'subscribe' ? t('Subscribing...') : t('Unsubscribing...') + return props.actionMessageType === 'follow' ? t('Following...') : t('Unfollowing...') }) return (
      } + when={!props.minimize} + fallback={} > { value={ @@ -47,7 +48,7 @@ export const BadgeSubscribeButton = (props: Props) => { isSubscribeButton={true} class={clsx(styles.actionButton, { [styles.iconed]: props.iconButtons, - [stylesButton.subscribed]: props.isSubscribed, + [stylesButton.followed]: props.isFollowed, })} /> } @@ -76,7 +77,7 @@ export const BadgeSubscribeButton = (props: Props) => { isSubscribeButton={true} class={clsx(styles.actionButton, { [styles.iconed]: props.iconButtons, - [stylesButton.subscribed]: props.isSubscribed, + [stylesButton.followed]: props.isFollowed, })} /> diff --git a/src/components/_shared/FollowingButton/index.ts b/src/components/_shared/FollowingButton/index.ts new file mode 100644 index 00000000..76cf2618 --- /dev/null +++ b/src/components/_shared/FollowingButton/index.ts @@ -0,0 +1 @@ +export { FollowingButton } from './FollowingButton' diff --git a/src/context/following.tsx b/src/context/following.tsx index 3f42a6f2..ce74d761 100644 --- a/src/context/following.tsx +++ b/src/context/following.tsx @@ -1,30 +1,27 @@ -import { Accessor, JSX, createContext, createEffect, createSignal, useContext } from 'solid-js' +import { Accessor, JSX, createContext, createEffect, createSignal, on, useContext } from 'solid-js' import { createStore } from 'solid-js/store' import { apiClient } from '../graphql/client/core' -import { Author, AuthorFollowsResult, Community, FollowingEntity, Topic } from '../graphql/schema/core.gen' +import { Author, AuthorFollowsResult, FollowingEntity } from '../graphql/schema/core.gen' import { useSession } from './session' -export type SubscriptionsData = { - topics?: Topic[] - authors?: Author[] - communities?: Community[] -} - -type SubscribeAction = { slug: string; type: 'subscribe' | 'unsubscribe' } +type FollowingData = { slug: string; type: 'follow' | 'unfollow' } interface FollowingContextType { loading: Accessor + followers: Accessor - subscriptions: AuthorFollowsResult - setSubscriptions: (subscriptions: AuthorFollowsResult) => void - setFollowing: (what: FollowingEntity, slug: string, value: boolean) => void - loadSubscriptions: () => void + setFollows: (follows: AuthorFollowsResult) => void + + following: Accessor + changeFollowing: (what: FollowingEntity, slug: string, value: boolean) => void + + follows: AuthorFollowsResult + loadFollows: () => void + follow: (what: FollowingEntity, slug: string) => Promise unfollow: (what: FollowingEntity, slug: string) => Promise - // followers: Accessor - subscribeInAction?: Accessor } const FollowingContext = createContext() @@ -42,7 +39,7 @@ const EMPTY_SUBSCRIPTIONS: AuthorFollowsResult = { export const FollowingProvider = (props: { children: JSX.Element }) => { const [loading, setLoading] = createSignal(false) const [followers, setFollowers] = createSignal([]) - const [subscriptions, setSubscriptions] = createStore(EMPTY_SUBSCRIPTIONS) + const [follows, setFollows] = createStore(EMPTY_SUBSCRIPTIONS) const { author, session } = useSession() const fetchData = async () => { @@ -51,7 +48,7 @@ export const FollowingProvider = (props: { children: JSX.Element }) => { if (apiClient.private) { console.debug('[context.following] fetching subs data...') const result = await apiClient.getAuthorFollows({ user: session()?.user.id }) - setSubscriptions(result || EMPTY_SUBSCRIPTIONS) + setFollows(result || EMPTY_SUBSCRIPTIONS) } } catch (error) { console.info('[context.following] cannot get subs', error) @@ -60,59 +57,65 @@ export const FollowingProvider = (props: { children: JSX.Element }) => { } } - createEffect(() => { - console.info('[context.following] subs:', subscriptions) - }) - - const [subscribeInAction, setSubscribeInAction] = createSignal() + const [following, setFollowing] = createSignal() const follow = async (what: FollowingEntity, slug: string) => { if (!author()) return - setSubscribeInAction({ slug, type: 'subscribe' }) + setFollowing({ slug, type: 'follow' }) try { - const subscriptionData = await apiClient.follow({ what, slug }) - setSubscriptions((prevSubscriptions) => { - if (!prevSubscriptions[what]) prevSubscriptions[what] = [] - prevSubscriptions[what].push(subscriptionData) - return prevSubscriptions + const result = await apiClient.follow({ what, slug }) + setFollows((subs) => { + if (result.authors) subs['authors'] = result.authors || [] + if (result.topics) subs['topics'] = result.topics || [] + return subs }) } catch (error) { console.error(error) } finally { - setSubscribeInAction() // Сбрасываем состояние действия подписки. + setFollowing() // Сбрасываем состояние действия подписки. } } const unfollow = async (what: FollowingEntity, slug: string) => { if (!author()) return - setSubscribeInAction({ slug: slug, type: 'unsubscribe' }) + setFollowing({ slug: slug, type: 'unfollow' }) try { - await apiClient.unfollow({ what, slug }) + const result = await apiClient.unfollow({ what, slug }) + setFollows((subs) => { + if (result.authors) subs['authors'] = result.authors || [] + if (result.topics) subs['topics'] = result.topics || [] + return subs + }) } catch (error) { console.error(error) } finally { - setSubscribeInAction() + setFollowing() } } - createEffect(() => { - if (author()) { - try { - const appdata = session()?.user.app_data - if (appdata) { - const { authors, followers, topics } = appdata - setSubscriptions({ authors, topics }) - setFollowers(followers) - if (!authors) fetchData() + createEffect( + on( + () => author(), + (a) => { + if (a?.id) { + try { + const appdata = session()?.user.app_data + if (appdata) { + const { authors, followers, topics } = appdata + setFollows({ authors, topics }) + setFollowers(followers) + if (!authors) fetchData() + } + } catch (e) { + console.error(e) + } } - } catch (e) { - console.error(e) - } - } - }) + }, + ), + ) - const setFollowing = (what: FollowingEntity, slug: string, value = true) => { - setSubscriptions((prevSubscriptions) => { - const updatedSubs = { ...prevSubscriptions } + const changeFollowing = (what: FollowingEntity, slug: string, value = true) => { + setFollows((fff) => { + const updatedSubs = { ...fff } if (!updatedSubs[what]) updatedSubs[what] = [] if (value) { const exists = updatedSubs[what]?.some((entity) => entity.slug === slug) @@ -133,15 +136,14 @@ export const FollowingProvider = (props: { children: JSX.Element }) => { const value: FollowingContextType = { loading, - subscriptions, - setSubscriptions, - setFollowing, + follows, + setFollows, + following, + changeFollowing, followers, - loadSubscriptions: fetchData, + loadFollows: fetchData, follow, unfollow, - // followers, - subscribeInAction, } return {props.children} diff --git a/src/graphql/mutation/core/follow.ts b/src/graphql/mutation/core/follow.ts index 528dfd46..7b5de7ab 100644 --- a/src/graphql/mutation/core/follow.ts +++ b/src/graphql/mutation/core/follow.ts @@ -6,7 +6,24 @@ export default gql` error authors { id + name slug + pic + bio + stat { + followers + shouts + comments + } + } + topics { + body + slug + stat { + shouts + authors + followers + } } } } diff --git a/src/graphql/mutation/core/unfollow.ts b/src/graphql/mutation/core/unfollow.ts index 763b49d7..572b85fa 100644 --- a/src/graphql/mutation/core/unfollow.ts +++ b/src/graphql/mutation/core/unfollow.ts @@ -3,6 +3,27 @@ export default gql` mutation UnfollowMutation($what: FollowingEntity!, $slug: String!) { unfollow(what: $what, slug: $slug) { error + authors { + id + name + slug + pic + bio + stat { + followers + shouts + comments + } + } + topics { + body + slug + stat { + shouts + authors + followers + } + } } } ` diff --git a/src/pages/types.ts b/src/pages/types.ts index dc4d7132..3877a434 100644 --- a/src/pages/types.ts +++ b/src/pages/types.ts @@ -53,4 +53,4 @@ export type UploadedFile = { originalFilename?: string } -export type SubscriptionFilter = 'all' | 'authors' | 'topics' | 'communities' +export type FollowsFilter = 'all' | 'authors' | 'topics' | 'communities' diff --git a/vite.config.ts b/vite.config.ts index f50a5bab..2b50f82e 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -14,8 +14,9 @@ const cssModuleHMR = () => { const { modules } = context modules.forEach((module) => { - if (module.id.includes('.module.scss')) { + if (module.id.includes('.scss') || module.id.includes('.css')) { module.isSelfAccepting = true + module.accept() } }) },