diff --git a/pages/api/events/[slug].ts b/pages/api/events/[slug].ts index 5fb2dfc..597c29f 100644 --- a/pages/api/events/[slug].ts +++ b/pages/api/events/[slug].ts @@ -18,10 +18,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< } const which = { - slug: req.query.slug + slug: req.query.slug, } const update = { - name: req.body.name + name: req.body.name, + postcard: req.body.postcard ?? null, } await restInPeace(req, res, { diff --git a/pages/api/events/index.ts b/pages/api/events/index.ts index e820ebe..959127e 100644 --- a/pages/api/events/index.ts +++ b/pages/api/events/index.ts @@ -19,7 +19,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< const create = { slug: cryptoRandomString({ length: 12, type: "url-safe" }), creatorId: user.id, - name: req.body.name + name: req.body.name, + postcard: req.body.postcard ?? null, } await restInPeace(req, res, { diff --git a/pages/events/[slug].tsx b/pages/events/[slug].tsx index f6a1df5..8dbf97a 100644 --- a/pages/events/[slug].tsx +++ b/pages/events/[slug].tsx @@ -3,10 +3,13 @@ import { NextPageContext } from "next"; import { useTranslation } from "next-i18next"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { useRouter } from "next/router"; +import { useEffect } from "react"; import useSWR from "swr"; import { ErrorInline } from "../../components/ErrorInline"; import { Loading } from "../../components/Loading"; +import { PostcardContext } from "../../contexts/postcard"; import {useEventDetail} from "../../hooks/useEventDetail" +import { useDefinedContext } from "../../utils/definedContext"; import { database } from "../../utils/prismaClient"; @@ -37,6 +40,17 @@ type PageEventDetailProps = { export default function PageEventDetail({event}: PageEventDetailProps) { const {t} = useTranslation() + const [_, setPostcard] = useDefinedContext(PostcardContext) + + useEffect( + () => { + console.debug(event.postcard) + if(event.postcard) { + setPostcard(event.postcard) + } + }, + [event] + ) return (
diff --git a/pages/index.tsx b/pages/index.tsx index 9d52770..1eee8f1 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -5,6 +5,9 @@ import { LoginContext } from '../contexts/login'; import { useDefinedContext } from '../utils/definedContext'; import { ActionLoginTelegram } from '../components/ActionLoginTelegram'; import { ActionEventList } from '../components/ActionEventList'; +import { PostcardContext } from '../contexts/postcard'; +import defaultPostcard from "../public/postcards/adi-goldstein-Hli3R6LKibo-unsplash.jpg" +import { useEffect } from 'react'; export async function getStaticProps(context: NextPageContext) { @@ -18,7 +21,15 @@ export async function getStaticProps(context: NextPageContext) { export default function PageIndex() { const { t } = useTranslation() - const [login, _] = useDefinedContext(LoginContext) + const [login, ] = useDefinedContext(LoginContext) + const [, setPostcard] = useDefinedContext(PostcardContext) + + useEffect( + () => { + setPostcard(defaultPostcard) + }, + [] + ) return (
diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 27829cc..7d877f0 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -83,4 +83,6 @@ model Event { creator User @relation(fields: [creatorId], references: [id]) /// The name of the event. name String + /// The URL to the postcard of the event. + postcard String? }