diff --git a/package.json b/package.json index 5e79d11f..1da95480 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "hygen": "HYGEN_TMPLS=gen hygen", "postinstall": "npm run codegen && npx patch-package", "check:code": "npx @biomejs/biome check src --log-kind=compact --verbose", - "check:code:fix": "npx @biomejs/biome check src --log-kind=compact --verbose --apply-unsafe", + "check:code:fix": "npx @biomejs/biome check src --log-kind=compact", "lint": "npm run lint:code && stylelint **/*.{scss,css}", "lint:code": "npx @biomejs/biome lint src --log-kind=compact --verbose", "lint:code:fix": "npx @biomejs/biome lint src --apply-unsafe --log-kind=compact --verbose", diff --git a/src/components/Author/AuthorCard/AuthorCard.tsx b/src/components/Author/AuthorCard/AuthorCard.tsx index 75f23639..5fedd3e5 100644 --- a/src/components/Author/AuthorCard/AuthorCard.tsx +++ b/src/components/Author/AuthorCard/AuthorCard.tsx @@ -134,7 +134,9 @@ export const AuthorCard = (props: Props) => { )}
- {t('SubscriberWithCount', { count: props.followers.length ?? 0 })} + {t('SubscriberWithCount', { + count: props.followers.length ?? 0, + })}
@@ -169,7 +171,9 @@ export const AuthorCard = (props: Props) => { }}
- {t('SubscriptionWithCount', { count: props?.following.length ?? 0 })} + {t('SubscriptionWithCount', { + count: props?.following.length ?? 0, + })}
@@ -234,7 +238,9 @@ export const AuthorCard = (props: Props) => { title={props.author.name} description={props.author.bio} imageUrl={props.author.pic} - shareUrl={getShareUrl({ pathname: `/author/${props.author.slug}` })} + shareUrl={getShareUrl({ + pathname: `/author/${props.author.slug}`, + })} trigger={ {props.following.length} -
  • +
  • @@ -284,7 +298,11 @@ export const AuthorCard = (props: Props) => { {props.following.filter((s) => 'name' in s).length}
  • -
  • +
  • diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index c7515382..0c6a958a 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -7,6 +7,7 @@ import { For, Match, Show, Switch, createEffect, createMemo, createSignal, onMou import { useFollowing } from '../../../context/following' import { useLocalize } from '../../../context/localize' +import { useSession } from '../../../context/session' import { apiClient } from '../../../graphql/client/core' import { router, useRouter } from '../../../stores/router' import { loadShouts, useArticlesStore } from '../../../stores/zine/articles' @@ -30,32 +31,47 @@ import styles from './Author.module.scss' type Props = { authorSlug: string + shouts?: Shout[] + author?: Author } export const PRERENDERED_ARTICLES_COUNT = 12 const LOAD_MORE_PAGE_SIZE = 9 export const AuthorView = (props: Props) => { const { t } = useLocalize() - const { loadSubscriptions } = useFollowing() - const { sortedArticles } = useArticlesStore() - const { authorEntities } = useAuthorsStore() + const { subscriptions, followers: myFollowers, loadSubscriptions } = useFollowing() + const { session } = useSession() + const { sortedArticles } = useArticlesStore({ shouts: props.shouts }) + const { authorEntities } = useAuthorsStore({ authors: [props.author] }) const { page: getPage, searchParams } = useRouter() const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) const [isBioExpanded, setIsBioExpanded] = createSignal(false) - const [followers, setFollowers] = createSignal([]) - const [following, setFollowing] = createSignal>([]) + const [author, setAuthor] = createSignal() + const [followers, setFollowers] = createSignal([]) + const [following, setFollowing] = createSignal>([]) // flat AuthorFollowsResult const [showExpandBioControl, setShowExpandBioControl] = createSignal(false) const [commented, setCommented] = createSignal() const modal = MODALS[searchParams().m] // current author - const [author, setAuthor] = createSignal() createEffect(() => { - try { - const a = authorEntities()[props.authorSlug] - setAuthor(a) - } catch (error) { - console.debug(error) + if (props.authorSlug) { + if (session()?.user?.app_data?.profile?.slug === props.authorSlug) { + console.info('my own profile') + const { profile, authors, topics } = session().user.app_data + setFollowers(myFollowers) + setAuthor(profile) + setFollowing([...authors, ...topics]) + } + } else { + try { + const a = authorEntities()[props.authorSlug] + setAuthor(a) + // TODO: add following data retrieval + console.debug('[Author] expecting following data fetched') + } catch (error) { + console.debug(error) + } } }) @@ -166,31 +182,53 @@ export const AuthorView = (props: Props) => { }> <>
    - +
      -
    • - +
    • + {t('Publications')} {author().stat.shouts}
    • -
    • - +
    • + {t('Comments')} {author().stat.comments}
    • -
    • +
    • checkBioHeight()} - href={getPagePath(router, 'authorAbout', { slug: props.authorSlug })} + href={getPagePath(router, 'authorAbout', { + slug: props.authorSlug, + })} > {t('Profile')} diff --git a/src/components/Views/ProfileSubscriptions/ProfileSubscriptions.tsx b/src/components/Views/ProfileSubscriptions/ProfileSubscriptions.tsx index 6e1b4d8d..51f27325 100644 --- a/src/components/Views/ProfileSubscriptions/ProfileSubscriptions.tsx +++ b/src/components/Views/ProfileSubscriptions/ProfileSubscriptions.tsx @@ -1,6 +1,7 @@ import { clsx } from 'clsx' import { For, Show, createEffect, createSignal, onMount } from 'solid-js' +import { useFollowing } from '../../../context/following' import { useLocalize } from '../../../context/localize' import { useSession } from '../../../context/session' import { apiClient } from '../../../graphql/client/core' @@ -20,41 +21,32 @@ import stylesSettings from '../../../styles/FeedSettings.module.scss' export const ProfileSubscriptions = () => { const { t, lang } = useLocalize() - const { author } = useSession() + const { author, session } = useSession() + const { subscriptions } = useFollowing() const [following, setFollowing] = createSignal>([]) const [filtered, setFiltered] = createSignal>([]) const [subscriptionFilter, setSubscriptionFilter] = createSignal('all') const [searchQuery, setSearchQuery] = createSignal('') - const fetchSubscriptions = async () => { - try { - const slug = author()?.slug - const authorFollows = await apiClient.getAuthorFollows({ slug }) - setFollowing([...authorFollows['authors']]) - setFiltered([...authorFollows['authors'], ...authorFollows['topics']]) - } catch (error) { - console.error('[fetchSubscriptions] :', error) - throw error - } - } - createEffect(() => { - if (following()) { + const { authors, topics } = subscriptions + if (authors || topics) { + const fdata = [...(authors || []), ...(topics || [])] + setFollowing(fdata) if (subscriptionFilter() === 'authors') { - setFiltered(following().filter((s) => 'name' in s)) + setFiltered(fdata.filter((s) => 'name' in s)) } else if (subscriptionFilter() === 'topics') { - setFiltered(following().filter((s) => 'title' in s)) + setFiltered(fdata.filter((s) => 'title' in s)) } else { - setFiltered(following()) + setFiltered(fdata) } } - if (searchQuery()) { - setFiltered(dummyFilter(following(), searchQuery(), lang())) - } }) - onMount(async () => { - await fetchSubscriptions() + createEffect(() => { + if (searchQuery()) { + setFiltered(dummyFilter(following(), searchQuery(), lang())) + } }) return ( @@ -73,17 +65,29 @@ export const ProfileSubscriptions = () => {

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

      }>
        -
      • +
      • -
      • +
      • -
      • +
      • diff --git a/src/context/following.tsx b/src/context/following.tsx index 1b0aa059..ad93eaaf 100644 --- a/src/context/following.tsx +++ b/src/context/following.tsx @@ -2,12 +2,13 @@ import { Accessor, JSX, createContext, createEffect, createSignal, useContext } import { createStore } from 'solid-js/store' import { apiClient } from '../graphql/client/core' -import { AuthorFollowsResult, FollowingEntity } from '../graphql/schema/core.gen' +import { Author, AuthorFollowsResult, FollowingEntity } from '../graphql/schema/core.gen' import { useSession } from './session' interface FollowingContextType { loading: Accessor + followers: Accessor> subscriptions: AuthorFollowsResult setSubscriptions: (subscriptions: AuthorFollowsResult) => void setFollowing: (what: FollowingEntity, slug: string, value: boolean) => void @@ -31,6 +32,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 { author, session } = useSession() @@ -77,8 +79,14 @@ export const FollowingProvider = (props: { children: JSX.Element }) => { createEffect(() => { if (author()) { - console.debug('[context.following] author update detect') - fetchData() + try { + const { authors, followers, topics } = session().user.app_data + setSubscriptions({ authors, topics }) + setFollowers(followers) + if (!authors) fetchData() + } catch (e) { + console.error(e) + } } }) @@ -116,6 +124,7 @@ export const FollowingProvider = (props: { children: JSX.Element }) => { setSubscriptions, isOwnerSubscribed, setFollowing, + followers, loadSubscriptions: fetchData, follow, unfollow, diff --git a/src/context/session.tsx b/src/context/session.tsx index 73659a6c..67bd5a93 100644 --- a/src/context/session.tsx +++ b/src/context/session.tsx @@ -199,6 +199,7 @@ export const SessionProvider = (props: { } onCleanup(() => clearTimeout(minuteLater)) + const authorData = async () => { const u = session()?.user return u ? (await apiClient.getAuthorId({ user: u.id.trim() })) || null : null @@ -217,7 +218,15 @@ export const SessionProvider = (props: { apiClient.connect(token) inboxClient.connect(token) } - if (!author()) loadAuthor() + + try { + const { profile } = session().user.app_data + setAuthor(profile) + addAuthors([profile]) + if (!profile) loadAuthor() + } catch (e) { + console.error(e) + } setIsSessionLoaded(true) } @@ -263,7 +272,6 @@ export const SessionProvider = (props: { () => { props.onStateChangeCallback(session()) }, - { defer: true }, ), )