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 && }