From 0e092a36caef6aa86626dd82f370f12f949ee972 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 16 Jul 2022 20:02:03 +0200 Subject: [PATCH] Progress on the event page --- pages/events/[slug].tsx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/pages/events/[slug].tsx b/pages/events/[slug].tsx index 4637f02..1f933ea 100644 --- a/pages/events/[slug].tsx +++ b/pages/events/[slug].tsx @@ -9,11 +9,13 @@ import useSWR from 'swr' import { Event } from '@prisma/client' import { EditableText } from '../../components/generic/editable/inputs' import { EditingContext, EditingMode } from '../../components/generic/editable/base' -import { useState } from 'react' +import { useCallback, useContext, useState } from 'react' import { ToolBar } from '../../components/generic/toolbar/bar' import { ToolToggleEditing } from '../../components/events/toolbar/toolToggleEditing' import { ToolToggleVisibility } from '../../components/postcard/toolbar/toolToggleVisibility' import { WIPBanner } from '../../components/generic/wip/banner' +import { AuthContext } from '../../components/auth/base' +import { useDefinedContext } from '../../utils/definedContext' export async function getServerSideProps(context: NextPageContext) { @@ -33,12 +35,20 @@ type PageEventProps = { const PageEvent: NextPage = ({ slug }) => { const { t } = useTranslation() - const { data, error } = useSWR(`/api/events/${slug}`) + const { data, error, mutate } = useSWR(`/api/events/${slug}`) + const [auth, _setAuth] = useDefinedContext(AuthContext) const displayTitle = data?.name ?? slug const displayPostcard = data?.postcard ?? defaultPostcard const displayDescription = data?.description ?? "" + const saveEdits = useCallback( + () => { + mutate() + }, + [] + ) + return <> @@ -54,19 +64,25 @@ const PageEvent: NextPage = ({ slug }) => { title={<> mutate(async state => state ? { ...state, name: e.target.value } : undefined, { revalidate: false })} /> } postcard={<>} description={<> mutate(async state => state ? { ...state, description: e.target.value } : undefined, { revalidate: false })} /> } daterange={<>} /> - + {data && auth?.userId === data?.creatorId && + + }