From e2aef26685f97ee7682dc5ec4202162201a5abb8 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 17 Jul 2022 04:28:46 +0200 Subject: [PATCH] Make button to save changes actually do that --- pages/events/[slug].tsx | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/pages/events/[slug].tsx b/pages/events/[slug].tsx index 6ebc477..be0b278 100644 --- a/pages/events/[slug].tsx +++ b/pages/events/[slug].tsx @@ -7,7 +7,7 @@ import { Postcard } from '../../components/postcard/changer' import { ViewEvent } from '../../components/events/views/event' import useSWR from 'swr' import { Event } from '@prisma/client' -import { EditableText } from '../../components/generic/editable/inputs' +import { EditableFilePicker, EditableText } from '../../components/generic/editable/inputs' import { EditingContext, EditingMode } from '../../components/generic/editable/base' import { useCallback, useContext, useState } from 'react' import { ToolBar } from '../../components/generic/toolbar/bar' @@ -17,6 +17,8 @@ import { WIPBanner } from '../../components/generic/wip/banner' import { AuthContext } from '../../components/auth/base' import { useDefinedContext } from '../../utils/definedContext' import { asleep } from '../../utils/asleep' +import { ViewContent } from '../../components/generic/views/content' +import { useAxios } from '../../components/auth/requests' export async function getServerSideProps(context: NextPageContext) { @@ -38,51 +40,48 @@ const PageEvent: NextPage = ({ slug }) => { const { t } = useTranslation() const { data, error, mutate } = useSWR(`/api/events/${slug}`) const [auth, _setAuth] = useDefinedContext(AuthContext) + const axios = useAxios() const displayTitle = data?.name ?? slug const displayPostcard = data?.postcard ?? defaultPostcard const displayDescription = data?.description ?? "" - const saveEdits = useCallback( + const save = useCallback( async () => { - await asleep(1000) - mutate() + await axios.patch(`/api/events/${slug}`, data) + mutate(data) }, - [] + [axios, data] ) - return <> {displayTitle} - {t("siteTitle")} - (EditingMode.VIEW)}> - + mutate(async state => state ? { ...state, name: e.target.value } : undefined, { revalidate: false })} /> - } - postcard={<>} - description={<> + } + content={<> mutate(async state => state ? { ...state, description: e.target.value } : undefined, { revalidate: false })} /> } - daterange={<>} /> {data && auth?.userId === data?.creatorId && }