1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-22 14:44:21 +00:00

Configure SWR fallback in the event page

This commit is contained in:
Steffo 2022-07-19 19:04:29 +02:00
parent 02d7251b16
commit ee6a082f66
Signed by: steffo
GPG key ID: 6965406171929D01

View file

@ -25,12 +25,16 @@ import { swrMultiplexer } from '../../components/generic/loading/swr'
import { LoadingMain, LoadingInline } from '../../components/generic/loading/renderers' import { LoadingMain, LoadingInline } from '../../components/generic/loading/renderers'
import { ViewNotice } from '../../components/generic/views/notice' import { ViewNotice } from '../../components/generic/views/notice'
import { ErrorBlock } from '../../components/generic/errors/renderers' import { ErrorBlock } from '../../components/generic/errors/renderers'
import { database } from '../../utils/prismaClient'
export async function getServerSideProps(context: NextPageContext) { export async function getServerSideProps(context: NextPageContext) {
const slug = context.query.slug as string
return { return {
props: { props: {
slug: context.query.slug, slug,
event: await database.event.findUnique({ where: { slug } }),
...(await serverSideTranslations(context.locale ?? "it-IT", ["common"])) ...(await serverSideTranslations(context.locale ?? "it-IT", ["common"]))
} }
} }
@ -38,13 +42,14 @@ export async function getServerSideProps(context: NextPageContext) {
type PageEventProps = { type PageEventProps = {
slug: string slug: string,
event: Event,
} }
const PageEvent: NextPage<PageEventProps> = ({ slug }) => { const PageEvent: NextPage<PageEventProps> = ({ slug, event }) => {
const { t } = useTranslation() const { t } = useTranslation()
const swrHook = useSWR<Event>(`/api/events/${slug}`) const swrHook = useSWR<Event>(`/api/events/${slug}`, { fallback: event })
const [auth,] = useDefinedContext(AuthContext) const [auth,] = useDefinedContext(AuthContext)
const axios = useAxios() const axios = useAxios()