diff --git a/src/routes/topic/[slug]/[...tab].tsx b/src/routes/topic/[slug]/[...tab].tsx index aa33a40b..edb033d5 100644 --- a/src/routes/topic/[slug]/[...tab].tsx +++ b/src/routes/topic/[slug]/[...tab].tsx @@ -40,19 +40,29 @@ export type TopicPageProps = { articles?: Shout[]; topics: Topic[]; authors?: Au export default function TopicPage(props: RouteSectionProps) { const { t } = useLocalize() const { addTopics } = useTopics() - const topics = createAsync(async () => props.data.topics || (await fetchAllTopics()) || []) + const [loadingError, setLoadingError] = createSignal(false) + + // all topics + const topics = createAsync(async () => { + const result = props.data.topics || (await fetchAllTopics()) + if (!result) setLoadingError(true) + return result + }) + + // current topic's shouts const articles = createAsync(async () => { const result = (await props.data).articles || (await fetchTopicShouts(props.params.slug)) - setShoutsLoaded(true) - return result || [] + if (!result) setLoadingError(true) + return result }) + + // current topic's data const [topic, setTopic] = createSignal() const [title, setTitle] = createSignal('') const [desc, setDesc] = createSignal('') const [cover, setCover] = createSignal('') - const [shoutsLoaded, setShoutsLoaded] = createSignal(false) createEffect(on([topics, () => window], ([ttt, win]) => { - if (ttt) { + if (ttt && win) { // console.debug('all topics:', ttt) ttt && addTopics(ttt) const tpc = ttt.find((x) => x.slug === props.params.slug) @@ -67,7 +77,9 @@ export default function TopicPage(props: RouteSectionProps) { setCover(() => topic()?.pic ? getImageUrl(topic()?.pic || '', { width: 1200 }) : '/logo.png' ) - if (win) window?.gtag?.('event', 'page_view', { + + // views google counter increment + window?.gtag?.('event', 'page_view', { page_title: tpc.title, page_location: window?.location.href, page_path: window?.location.pathname @@ -77,7 +89,7 @@ export default function TopicPage(props: RouteSectionProps) { return (