mirror of
https://github.com/Steffo99/festa.git
synced 2024-12-22 22:54:22 +00:00
Progress on the event page
This commit is contained in:
parent
c820429d42
commit
0e092a36ca
1 changed files with 19 additions and 3 deletions
|
@ -9,11 +9,13 @@ import useSWR from 'swr'
|
||||||
import { Event } from '@prisma/client'
|
import { Event } from '@prisma/client'
|
||||||
import { EditableText } from '../../components/generic/editable/inputs'
|
import { EditableText } from '../../components/generic/editable/inputs'
|
||||||
import { EditingContext, EditingMode } from '../../components/generic/editable/base'
|
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 { ToolBar } from '../../components/generic/toolbar/bar'
|
||||||
import { ToolToggleEditing } from '../../components/events/toolbar/toolToggleEditing'
|
import { ToolToggleEditing } from '../../components/events/toolbar/toolToggleEditing'
|
||||||
import { ToolToggleVisibility } from '../../components/postcard/toolbar/toolToggleVisibility'
|
import { ToolToggleVisibility } from '../../components/postcard/toolbar/toolToggleVisibility'
|
||||||
import { WIPBanner } from '../../components/generic/wip/banner'
|
import { WIPBanner } from '../../components/generic/wip/banner'
|
||||||
|
import { AuthContext } from '../../components/auth/base'
|
||||||
|
import { useDefinedContext } from '../../utils/definedContext'
|
||||||
|
|
||||||
|
|
||||||
export async function getServerSideProps(context: NextPageContext) {
|
export async function getServerSideProps(context: NextPageContext) {
|
||||||
|
@ -33,12 +35,20 @@ type PageEventProps = {
|
||||||
|
|
||||||
const PageEvent: NextPage<PageEventProps> = ({ slug }) => {
|
const PageEvent: NextPage<PageEventProps> = ({ slug }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { data, error } = useSWR<Event>(`/api/events/${slug}`)
|
const { data, error, mutate } = useSWR<Event>(`/api/events/${slug}`)
|
||||||
|
const [auth, _setAuth] = useDefinedContext(AuthContext)
|
||||||
|
|
||||||
const displayTitle = data?.name ?? slug
|
const displayTitle = data?.name ?? slug
|
||||||
const displayPostcard = data?.postcard ?? defaultPostcard
|
const displayPostcard = data?.postcard ?? defaultPostcard
|
||||||
const displayDescription = data?.description ?? ""
|
const displayDescription = data?.description ?? ""
|
||||||
|
|
||||||
|
const saveEdits = useCallback(
|
||||||
|
() => {
|
||||||
|
mutate()
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<Head>
|
<Head>
|
||||||
|
@ -54,19 +64,25 @@ const PageEvent: NextPage<PageEventProps> = ({ slug }) => {
|
||||||
title={<>
|
title={<>
|
||||||
<EditableText
|
<EditableText
|
||||||
value={displayTitle}
|
value={displayTitle}
|
||||||
|
onChange={e => mutate(async state => state ? { ...state, name: e.target.value } : undefined, { revalidate: false })}
|
||||||
/>
|
/>
|
||||||
</>}
|
</>}
|
||||||
postcard={<></>}
|
postcard={<></>}
|
||||||
description={<>
|
description={<>
|
||||||
<EditableText
|
<EditableText
|
||||||
value={displayDescription}
|
value={displayDescription}
|
||||||
|
onChange={e => mutate(async state => state ? { ...state, description: e.target.value } : undefined, { revalidate: false })}
|
||||||
/>
|
/>
|
||||||
</>}
|
</>}
|
||||||
daterange={<></>}
|
daterange={<></>}
|
||||||
/>
|
/>
|
||||||
<ToolBar vertical="vadapt" horizontal="right">
|
<ToolBar vertical="vadapt" horizontal="right">
|
||||||
<ToolToggleEditing />
|
|
||||||
<ToolToggleVisibility />
|
<ToolToggleVisibility />
|
||||||
|
{data && auth?.userId === data?.creatorId &&
|
||||||
|
<ToolToggleEditing
|
||||||
|
onEditEnd={saveEdits}
|
||||||
|
/>
|
||||||
|
}
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
</EditingContext.Provider>
|
</EditingContext.Provider>
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in a new issue