diff --git a/src/components/Views/AllAuthors/AllAuthors.tsx b/src/components/Views/AllAuthors/AllAuthors.tsx index bca831e2..3cadd431 100644 --- a/src/components/Views/AllAuthors/AllAuthors.tsx +++ b/src/components/Views/AllAuthors/AllAuthors.tsx @@ -40,8 +40,10 @@ export const AllAuthors = (props: Props) => { // filter const [searchQuery, setSearchQuery] = createSignal('') const [filteredAuthors, setFilteredAuthors] = createSignal([]) - createEffect(() => - authors() && setFilteredAuthors((_prev: Author[]) => dummyFilter(authors(), searchQuery(), lang()) as Author[]) + createEffect( + () => + authors() && + setFilteredAuthors((_prev: Author[]) => dummyFilter(authors(), searchQuery(), lang()) as Author[]) ) // sort by diff --git a/src/routes/[slug].tsx b/src/routes/[slug].tsx index 353f5a27..04f11939 100644 --- a/src/routes/[slug].tsx +++ b/src/routes/[slug].tsx @@ -1,4 +1,11 @@ -import { RouteDefinition, RouteSectionProps, createAsync, redirect, useLocation, useParams } from '@solidjs/router' +import { + RouteDefinition, + RouteSectionProps, + createAsync, + redirect, + useLocation, + useParams +} from '@solidjs/router' import { HttpStatusCode } from '@solidjs/start' import { ErrorBoundary, Show, createEffect, createMemo, createSignal, on, onMount } from 'solid-js' import { Loading } from '~/components/_shared/Loading' @@ -12,7 +19,6 @@ import { FullArticle } from '../components/Article/FullArticle' import { PageLayout } from '../components/_shared/PageLayout' import { ReactionsProvider } from '../context/reactions' - const fetchShout = async (slug: string): Promise => { const shoutLoader = getShout({ slug }) const shout = await shoutLoader() @@ -22,7 +28,6 @@ const fetchShout = async (slug: string): Promise => { return shout } - export const route: RouteDefinition = { load: async ({ params }) => { try { @@ -46,12 +51,14 @@ export default (props: RouteSectionProps<{ article: Shout }>) => { const article = createAsync(async () => { if (params.slug && articleEntities?.()) { - return articleEntities()?.[params.slug] || props.data.article || await fetchShout(params.slug) + return articleEntities()?.[params.slug] || props.data.article || (await fetchShout(params.slug)) } throw redirect('/404', { status: 404 }) }) - const title = createMemo(() => `${article()?.authors?.[0]?.name || t('Discours')} :: ${article()?.title || ''}`) + const title = createMemo( + () => `${article()?.authors?.[0]?.name || t('Discours')} :: ${article()?.title || ''}` + ) onMount(async () => { if (gaIdentity && article()?.id) { @@ -64,14 +71,20 @@ export default (props: RouteSectionProps<{ article: Shout }>) => { } }) - createEffect(on(article, (a?: Shout) => { - if (!a) return - window?.gtag?.('event', 'page_view', { - page_title: a.title, - page_location: window?.location.href || '', - page_path: loc.pathname - }) - }, { defer: true })) + createEffect( + on( + article, + (a?: Shout) => { + if (!a) return + window?.gtag?.('event', 'page_view', { + page_title: a.title, + page_location: window?.location.href || '', + page_path: loc.pathname + }) + }, + { defer: true } + ) + ) return ( }> diff --git a/src/routes/author/(all-authors).tsx b/src/routes/author/(all-authors).tsx index 6f3a983d..55c4015a 100644 --- a/src/routes/author/(all-authors).tsx +++ b/src/routes/author/(all-authors).tsx @@ -23,17 +23,17 @@ const fetchAllAuthors = async () => { export const route = { load: async ({ location: { query } }: RouteLoadFuncArgs) => { - const by = query.by - const isAll = !by || by === 'name' - return { - authors: isAll && await fetchAllAuthors(), - topFollowedAuthors: await fetchAuthorsWithStat(10, 'followers'), - topShoutsAuthors: await fetchAuthorsWithStat(10, 'shouts') - } as AllAuthorsData + const by = query.by + const isAll = !by || by === 'name' + return { + authors: isAll && (await fetchAllAuthors()), + topFollowedAuthors: await fetchAuthorsWithStat(10, 'followers'), + topShoutsAuthors: await fetchAuthorsWithStat(10, 'shouts') + } as AllAuthorsData } } satisfies RouteDefinition -type AllAuthorsData = { authors: Author[], topFollowedAuthors: Author[], topShoutsAuthors: Author[] } +type AllAuthorsData = { authors: Author[]; topFollowedAuthors: Author[]; topShoutsAuthors: Author[] } // addAuthors to context @@ -52,16 +52,20 @@ export default function AllAuthorsPage(props: RouteSectionProps) }) // update context when data is loaded - createEffect(on([data, () => addAuthors], - ([data, aa])=> { - if(data && aa) { - aa(data.authors as Author[]) - aa(data.topFollowedAuthors as Author[]) - aa(data.topShoutsAuthors as Author[]) - console.debug('[routes.author] added all authors:', data.authors) - } - }, { defer: true} - )) + createEffect( + on( + [data, () => addAuthors], + ([data, aa]) => { + if (data && aa) { + aa(data.authors as Author[]) + aa(data.topFollowedAuthors as Author[]) + aa(data.topShoutsAuthors as Author[]) + console.debug('[routes.author] added all authors:', data.authors) + } + }, + { defer: true } + ) + ) return ( @@ -71,7 +75,8 @@ export default function AllAuthorsPage(props: RouteSectionProps) isLoaded={Boolean(data()?.authors)} authors={data()?.authors || []} topFollowedAuthors={data()?.topFollowedAuthors} - topWritingAuthors={data()?.topShoutsAuthors}/> + topWritingAuthors={data()?.topShoutsAuthors} + />