From db8b53f9bdaaeb92a73711886faad041fa3cd012 Mon Sep 17 00:00:00 2001 From: dufok Date: Wed, 25 Sep 2024 10:21:08 -0300 Subject: [PATCH] debug: back to dev version. Investigate UserPage Artcicle Render --- src/routes/[slug]/[...tab].tsx | 57 +++------------------------------- 1 file changed, 4 insertions(+), 53 deletions(-) diff --git a/src/routes/[slug]/[...tab].tsx b/src/routes/[slug]/[...tab].tsx index dfac04fb..e71bd611 100644 --- a/src/routes/[slug]/[...tab].tsx +++ b/src/routes/[slug]/[...tab].tsx @@ -6,7 +6,6 @@ import { Loading } from '~/components/_shared/Loading' import { gaIdentity } from '~/config' import { useLocalize } from '~/context/localize' import { getShout } from '~/graphql/api/public' -import { useTopics } from '~/context/topics' // Import Topics context import type { Author, Reaction, Shout, Topic } from '~/graphql/schema/core.gen' import { initGA, loadGAScript } from '~/utils/ga' import { descFromBody, keywordsFromTopics } from '~/utils/meta' @@ -45,76 +44,30 @@ export type SlugPageProps = { } export default function ArticlePage(props: RouteSectionProps) { - const { topicEntities, loadTopics } = useTopics() // Get topics context - const slug = props.params.slug - - // Handle author page if slug starts with '@' - if (slug.startsWith('@')) { + if (props.params.slug.startsWith('@')) { console.debug('[routes] [slug]/[...tab] starts with @, render as author page') const patchedProps = { ...props, params: { ...props.params, - slug: slug.slice(1) + slug: props.params.slug.slice(1, props.params.slug.length) } } as RouteSectionProps return } - // Handle topic page if slug starts with '!' - if (slug.startsWith('!')) { + if (props.params.slug.startsWith('!')) { console.debug('[routes] [slug]/[...tab] starts with !, render as topic page') - - const topicSlug = slug.slice(1) // Remove '!' from slug - const topic = topicEntities()[topicSlug] // Check if the topic is already loaded - - // If the topic is not loaded, fetch topics - if (!topic) { - onMount(async () => { - console.debug('Loading topics for the first time...') - await loadTopics() // Load topics if not already available - }) - - return // Show a loading state while fetching the topics - } - const patchedProps = { ...props, params: { ...props.params, - slug: topicSlug + slug: props.params.slug.slice(1, props.params.slug.length) } } as RouteSectionProps return } - // Handle topic pages without '!' or '@' - if (!slug.startsWith('@') && !slug.startsWith('!')) { - console.debug('[routes] [slug]/[...tab] regular topic page') - - const topic = topicEntities()[slug] // Check if the topic is already loaded - - // If the topic is not loaded, trigger topic loading - if (!topic) { - onMount(async () => { - console.debug('Topic not found, loading topics...') - await loadTopics() - }) - - return // Show a loading state while fetching the topics - } - - const patchedProps = { - ...props, - params: { - ...props.params, - slug - } - } as RouteSectionProps - return - } - - // ArticlePage logic for rendering articles if neither `@` nor `!` is in the slug function ArticlePage(props: RouteSectionProps) { const loc = useLocation() const { t } = useLocalize() @@ -175,6 +128,4 @@ export default function ArticlePage(props: RouteSectionProps) { ) } - return -}