From bd4fedc6c727806c72feb1cc469bff4f18b5d2d3 Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 16 Apr 2024 07:01:18 +0300 Subject: [PATCH] preloaded-author-fix --- src/components/Views/Author/Author.tsx | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index 870d4e5c..22fdf134 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -53,32 +53,26 @@ export const AuthorView = (props: Props) => { const [commented, setCommented] = createSignal() const modal = MODALS[searchParams().m] - // current author createEffect(async () => { - await loadAuthor({ slug: props.authorSlug }) - }) - createEffect(() => { if (props.authorSlug && session()?.user?.app_data?.profile?.slug === props.authorSlug) { - console.info('my own profile') + console.info('preloaded 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) - } } }) createEffect(async () => { - if (author()?.id && !author().stat) { - const a = await loadAuthor({ slug: '', author_id: author().id }) + if(Object.keys(authorEntities()).includes(props.authorSlug) && !author()?.id) { + // use preloaded author + const a = authorEntities()[props.authorSlug] + setAuthor(a) + console.debug('[AuthorView] preloaded author:', a) + } else if(props.authorSlug || (author()?.id && !author().stat)) { + // load author + const a = await loadAuthor({ slug: props.authorSlug, author_id: author()?.id }) + setAuthor(a) console.debug('[AuthorView] loaded author:', a) } })