fmt
This commit is contained in:
parent
f4f4e80816
commit
e7bcb4c6d4
|
@ -40,8 +40,10 @@ export const AllAuthors = (props: Props) => {
|
|||
// filter
|
||||
const [searchQuery, setSearchQuery] = createSignal('')
|
||||
const [filteredAuthors, setFilteredAuthors] = createSignal<Author[]>([])
|
||||
createEffect(() =>
|
||||
authors() && setFilteredAuthors((_prev: Author[]) => dummyFilter(authors(), searchQuery(), lang()) as Author[])
|
||||
createEffect(
|
||||
() =>
|
||||
authors() &&
|
||||
setFilteredAuthors((_prev: Author[]) => dummyFilter(authors(), searchQuery(), lang()) as Author[])
|
||||
)
|
||||
|
||||
// sort by
|
||||
|
|
|
@ -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<Shout> => {
|
||||
const shoutLoader = getShout({ slug })
|
||||
const shout = await shoutLoader()
|
||||
|
@ -22,7 +28,6 @@ const fetchShout = async (slug: string): Promise<Shout> => {
|
|||
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) => {
|
||||
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 }))
|
||||
},
|
||||
{ defer: true }
|
||||
)
|
||||
)
|
||||
|
||||
return (
|
||||
<ErrorBoundary fallback={() => <HttpStatusCode code={404} />}>
|
||||
|
|
|
@ -26,14 +26,14 @@ export const route = {
|
|||
const by = query.by
|
||||
const isAll = !by || by === 'name'
|
||||
return {
|
||||
authors: isAll && await fetchAllAuthors(),
|
||||
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<AllAuthorsData>)
|
|||
})
|
||||
|
||||
// update context when data is loaded
|
||||
createEffect(on([data, () => addAuthors],
|
||||
([data, aa])=> {
|
||||
if(data && aa) {
|
||||
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}
|
||||
))
|
||||
},
|
||||
{ defer: true }
|
||||
)
|
||||
)
|
||||
|
||||
return (
|
||||
<PageLayout withPadding={true} title={`${t('Discours')} :: ${t('All authors')}`}>
|
||||
|
@ -71,7 +75,8 @@ export default function AllAuthorsPage(props: RouteSectionProps<AllAuthorsData>)
|
|||
isLoaded={Boolean(data()?.authors)}
|
||||
authors={data()?.authors || []}
|
||||
topFollowedAuthors={data()?.topFollowedAuthors}
|
||||
topWritingAuthors={data()?.topShoutsAuthors}/>
|
||||
topWritingAuthors={data()?.topShoutsAuthors}
|
||||
/>
|
||||
</Suspense>
|
||||
</ReactionsProvider>
|
||||
</PageLayout>
|
||||
|
|
Loading…
Reference in New Issue
Block a user