404-fix
This commit is contained in:
parent
878f0036ab
commit
ec1aacc010
|
@ -56,18 +56,20 @@ export const loadShouts = (options: LoadShoutsOptions) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadReactions = (options: QueryLoad_Reactions_ByArgs) => {
|
export const loadReactions = (options: QueryLoad_Reactions_ByArgs) => {
|
||||||
|
const kind = options.by?.comment ? 'comments' : options.by?.rating ? 'votes' : 'reactions'
|
||||||
|
const allorone = options.by?.shout ? `shout-${options.by.shout}` : 'all'
|
||||||
const page = `${options.offset || 0}-${(options?.limit || 0) + (options.offset || 0)}`
|
const page = `${options.offset || 0}-${(options?.limit || 0) + (options.offset || 0)}`
|
||||||
const filter = new URLSearchParams(options.by as Record<string, string>)
|
const filter = new URLSearchParams(options.by as Record<string, string>)
|
||||||
console.debug(options)
|
// console.debug(options)
|
||||||
return cache(async () => {
|
return cache(async () => {
|
||||||
const resp = await defaultClient.query(loadReactionsByQuery, options).toPromise()
|
const resp = await defaultClient.query(loadReactionsByQuery, options).toPromise()
|
||||||
const result = resp?.data?.load_reactions_by
|
const result = resp?.data?.load_reactions_by
|
||||||
if (result) return result as Reaction[]
|
if (result) return result as Reaction[]
|
||||||
}, `reactions-${filter}-${page}`)
|
}, `${allorone}-${kind}-${filter}-${page}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getShout = (options: QueryGet_ShoutArgs) => {
|
export const getShout = (options: QueryGet_ShoutArgs) => {
|
||||||
// console.debug('[lib.api] get shout cached fetcher returned', defaultClient)
|
console.debug('[lib.api] get shout options', options)
|
||||||
return cache(
|
return cache(
|
||||||
async () => {
|
async () => {
|
||||||
const resp = await defaultClient.query(loadReactionsByQuery, { ...options }).toPromise()
|
const resp = await defaultClient.query(loadReactionsByQuery, { ...options }).toPromise()
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
import { HttpStatusCode } from '@solidjs/start'
|
|
||||||
import { onMount } from 'solid-js'
|
|
||||||
import { FourOuFourView } from '../components/Views/FourOuFour'
|
|
||||||
import { PageLayout } from '../components/_shared/PageLayout'
|
|
||||||
import { useLocalize } from '../context/localize'
|
|
||||||
|
|
||||||
export default () => {
|
|
||||||
const { t } = useLocalize()
|
|
||||||
onMount(() => console.info('404 page'))
|
|
||||||
return (
|
|
||||||
<PageLayout isHeaderFixed={false} hideFooter={true} title={t('Nothing is here')}>
|
|
||||||
<FourOuFourView />
|
|
||||||
<HttpStatusCode code={404} />
|
|
||||||
</PageLayout>
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,61 +1,47 @@
|
||||||
import {
|
import { RouteDefinition, RouteSectionProps, createAsync, useLocation, useParams } from '@solidjs/router'
|
||||||
RouteDefinition,
|
|
||||||
RouteSectionProps,
|
|
||||||
createAsync,
|
|
||||||
redirect,
|
|
||||||
useLocation,
|
|
||||||
useParams
|
|
||||||
} from '@solidjs/router'
|
|
||||||
import { HttpStatusCode } from '@solidjs/start'
|
import { HttpStatusCode } from '@solidjs/start'
|
||||||
import { ErrorBoundary, Show, createEffect, createMemo, createSignal, on, onMount } from 'solid-js'
|
import {
|
||||||
|
ErrorBoundary,
|
||||||
|
Show,
|
||||||
|
Suspense,
|
||||||
|
createEffect,
|
||||||
|
createMemo,
|
||||||
|
createSignal,
|
||||||
|
on,
|
||||||
|
onMount
|
||||||
|
} from 'solid-js'
|
||||||
|
import { FourOuFourView } from '~/components/Views/FourOuFour'
|
||||||
import { Loading } from '~/components/_shared/Loading'
|
import { Loading } from '~/components/_shared/Loading'
|
||||||
import { gaIdentity } from '~/config'
|
import { gaIdentity } from '~/config'
|
||||||
import { useFeed } from '~/context/feed'
|
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
import { getShout } from '~/graphql/api/public'
|
import { getShout } from '~/graphql/api/public'
|
||||||
import type { Shout } from '~/graphql/schema/core.gen'
|
import type { Reaction, Shout } from '~/graphql/schema/core.gen'
|
||||||
import { initGA, loadGAScript } from '~/utils/ga'
|
import { initGA, loadGAScript } from '~/utils/ga'
|
||||||
import { getArticleKeywords } from '~/utils/meta'
|
import { getArticleKeywords } from '~/utils/meta'
|
||||||
import { FullArticle } from '../components/Article/FullArticle'
|
import { FullArticle } from '../components/Article/FullArticle'
|
||||||
import { PageLayout } from '../components/_shared/PageLayout'
|
import { PageLayout } from '../components/_shared/PageLayout'
|
||||||
import { ReactionsProvider } from '../context/reactions'
|
import { ReactionsProvider } from '../context/reactions'
|
||||||
|
|
||||||
const fetchShout = async (slug: string): Promise<Shout> => {
|
const fetchShout = async (slug: string): Promise<Shout | undefined> => {
|
||||||
const shoutLoader = getShout({ slug })
|
const shoutLoader = getShout({ slug })
|
||||||
const shout = await shoutLoader()
|
const result = await shoutLoader()
|
||||||
if (!shout) {
|
return result
|
||||||
throw new Error('Shout not found')
|
|
||||||
}
|
|
||||||
return shout
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const route: RouteDefinition = {
|
export const route: RouteDefinition = {
|
||||||
load: async ({ params }) => {
|
load: async ({ params }) => ({
|
||||||
try {
|
article: await fetchShout(params.slug)
|
||||||
return await fetchShout(params.slug)
|
})
|
||||||
} catch (error) {
|
|
||||||
console.error('Error loading shout:', error)
|
|
||||||
throw new Response(null, {
|
|
||||||
status: 404,
|
|
||||||
statusText: 'Not Found'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (props: RouteSectionProps<{ article: Shout }>) => {
|
export default (
|
||||||
|
props: RouteSectionProps<{ article?: Shout; comments?: Reaction[]; votes?: Reaction[] }>
|
||||||
|
) => {
|
||||||
const params = useParams()
|
const params = useParams()
|
||||||
const loc = useLocation()
|
const loc = useLocation()
|
||||||
const { articleEntities } = useFeed()
|
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
const [scrollToComments, setScrollToComments] = createSignal<boolean>(false)
|
const [scrollToComments, setScrollToComments] = createSignal<boolean>(false)
|
||||||
|
const article = createAsync(async () => props.data.article || (await fetchShout(params.slug)))
|
||||||
const article = createAsync(async () => {
|
|
||||||
if (params.slug && articleEntities?.()) {
|
|
||||||
return articleEntities()?.[params.slug] || props.data.article || (await fetchShout(params.slug))
|
|
||||||
}
|
|
||||||
throw redirect('/404', { status: 404 })
|
|
||||||
})
|
|
||||||
|
|
||||||
const title = createMemo(
|
const title = createMemo(
|
||||||
() => `${article()?.authors?.[0]?.name || t('Discours')} :: ${article()?.title || ''}`
|
() => `${article()?.authors?.[0]?.name || t('Discours')} :: ${article()?.title || ''}`
|
||||||
|
@ -76,7 +62,7 @@ export default (props: RouteSectionProps<{ article: Shout }>) => {
|
||||||
on(
|
on(
|
||||||
article,
|
article,
|
||||||
(a?: Shout) => {
|
(a?: Shout) => {
|
||||||
if (!a) return
|
if (!a?.id) return
|
||||||
window?.gtag?.('event', 'page_view', {
|
window?.gtag?.('event', 'page_view', {
|
||||||
page_title: a.title,
|
page_title: a.title,
|
||||||
page_location: window?.location.href || '',
|
page_location: window?.location.href || '',
|
||||||
|
@ -88,21 +74,31 @@ export default (props: RouteSectionProps<{ article: Shout }>) => {
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ErrorBoundary fallback={() => <HttpStatusCode code={404} />}>
|
<ErrorBoundary fallback={() => <HttpStatusCode code={500} />}>
|
||||||
<Show when={article()?.id} fallback={<Loading />}>
|
<Suspense fallback={<Loading />}>
|
||||||
<PageLayout
|
<Show
|
||||||
title={title()}
|
when={!article()?.id}
|
||||||
desc={getArticleKeywords(article() as Shout)}
|
fallback={
|
||||||
headerTitle={article()?.title || ''}
|
<PageLayout isHeaderFixed={false} hideFooter={true} title={t('Nothing is here')}>
|
||||||
slug={article()?.slug}
|
<FourOuFourView />
|
||||||
cover={article()?.cover || ''}
|
<HttpStatusCode code={404} />
|
||||||
scrollToComments={(value) => setScrollToComments(value)}
|
</PageLayout>
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<ReactionsProvider>
|
<PageLayout
|
||||||
<FullArticle article={article() as Shout} scrollToComments={scrollToComments()} />
|
title={title()}
|
||||||
</ReactionsProvider>
|
desc={getArticleKeywords(article() as Shout)}
|
||||||
</PageLayout>
|
headerTitle={article()?.title || ''}
|
||||||
</Show>
|
slug={article()?.slug}
|
||||||
|
cover={article()?.cover || ''}
|
||||||
|
scrollToComments={(value) => setScrollToComments(value)}
|
||||||
|
>
|
||||||
|
<ReactionsProvider>
|
||||||
|
<FullArticle article={article() as Shout} scrollToComments={scrollToComments()} />
|
||||||
|
</ReactionsProvider>
|
||||||
|
</PageLayout>
|
||||||
|
</Show>
|
||||||
|
</Suspense>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user