diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index c55ae33a..0f704d14 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -9,7 +9,7 @@ import { useLocalize } from '../../../context/localize' import { apiClient } from '../../../graphql/client/core' import { router, useRouter } from '../../../stores/router' import { loadShouts, useArticlesStore } from '../../../stores/zine/articles' -import { useAuthorsStore } from '../../../stores/zine/authors' +import { loadAuthor, useAuthorsStore } from '../../../stores/zine/authors' import { getImageUrl } from '../../../utils/getImageUrl' import { getDescription } from '../../../utils/meta' import { restoreScrollPosition, saveScrollPosition } from '../../../utils/scroll' @@ -24,6 +24,7 @@ import { Row3 } from '../../Feed/Row3' import styles from './Author.module.scss' import stylesArticle from '../../Article/Article.module.scss' +import { useSession } from '../../../context/session' type Props = { shouts: Shout[] @@ -38,18 +39,21 @@ export const AuthorView = (props: Props) => { const { t } = useLocalize() const { sortedArticles } = useArticlesStore({ shouts: props.shouts }) const { authorEntities } = useAuthorsStore({ authors: [props.author] }) - const { page: getPage } = useRouter() const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) const [isBioExpanded, setIsBioExpanded] = createSignal(false) const [followers, setFollowers] = createSignal([]) const [following, setFollowing] = createSignal>([]) const [showExpandBioControl, setShowExpandBioControl] = createSignal(false) - + const { + actions: { loadSubscriptions }, + } = useSession() const author = createMemo(() => authorEntities()[props.authorSlug]) + createEffect(async () => { - if (author() && !author().stat) { - await apiClient.getAuthor({ author_id: author().id }) + if (!author()?.stat) { + console.debug(`[AuthorView] updating author...`) + await loadAuthor({ slug: props.authorSlug }) } }) @@ -92,7 +96,7 @@ export const AuthorView = (props: Props) => { try { const { authors, topics } = await fetchSubscriptions() setFollowing([...(authors || []), ...(topics || [])]) - const userSubscribers = await apiClient.getAuthorFollowers({ slug }) + const userSubscribers = await loadSubscriptions() setFollowers(userSubscribers) } catch (error) { console.error('[AuthorView] error:', error) diff --git a/src/context/profile.tsx b/src/context/profile.tsx index 55363636..58b03c29 100644 --- a/src/context/profile.tsx +++ b/src/context/profile.tsx @@ -33,8 +33,6 @@ export const ProfileFormProvider = (props: { children: JSX.Element }) => { const { author } = useSession() const [form, setForm] = createStore({}) - const currentSlug = createMemo(() => author()?.slug) - const submit = async (profile: ProfileInput) => { const response = await apiClient.updateProfile(profile) if (response.error) { @@ -44,9 +42,8 @@ export const ProfileFormProvider = (props: { children: JSX.Element }) => { } createEffect(async () => { - if (!currentSlug()) return - try { - const currentAuthor = await loadAuthor({ slug: currentSlug() }) + if (author()) { + const currentAuthor = author() setForm({ name: currentAuthor.name, slug: currentAuthor.slug, @@ -55,10 +52,9 @@ export const ProfileFormProvider = (props: { children: JSX.Element }) => { pic: userpicUrl(currentAuthor.pic), links: currentAuthor.links, }) - } catch (error) { - console.error(error) } }) + const updateFormField = (fieldName: string, value: string, remove?: boolean) => { if (fieldName === 'links') { if (remove) { diff --git a/src/pages/author.page.server.ts b/src/pages/author.page.server.ts index d588d06f..41cd96ed 100644 --- a/src/pages/author.page.server.ts +++ b/src/pages/author.page.server.ts @@ -8,7 +8,7 @@ import { apiClient } from '../graphql/client/core' export const onBeforeRender = async (pageContext: PageContext) => { const { slug } = pageContext.routeParams - + console.debug(`[author.page] detected author in route: @${slug}`) const author = await apiClient.getAuthor({ slug }) if (!author) {