mirror of
https://github.com/Steffo99/festa.git
synced 2024-12-22 22:54:22 +00:00
Update event page with new sparkly things
This commit is contained in:
parent
8e5e3aacaa
commit
7717dfc3c7
2 changed files with 14 additions and 24 deletions
|
@ -20,6 +20,7 @@ import { useAxios } from '../../components/auth/requests'
|
||||||
import { faAsterisk } from '@fortawesome/free-solid-svg-icons'
|
import { faAsterisk } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { FestaIcon } from '../../components/generic/renderers/fontawesome'
|
import { FestaIcon } from '../../components/generic/renderers/fontawesome'
|
||||||
import { usePromise, UsePromiseStatus } from '../../components/generic/loading/promise'
|
import { usePromise, UsePromiseStatus } from '../../components/generic/loading/promise'
|
||||||
|
import { EditingContextProvider } from '../../components/generic/editable/provider'
|
||||||
|
|
||||||
|
|
||||||
export async function getServerSideProps(context: NextPageContext) {
|
export async function getServerSideProps(context: NextPageContext) {
|
||||||
|
@ -38,35 +39,21 @@ type PageEventProps = {
|
||||||
|
|
||||||
|
|
||||||
const PageEvent: NextPage<PageEventProps> = ({ slug }) => {
|
const PageEvent: NextPage<PageEventProps> = ({ slug }) => {
|
||||||
const { t } =
|
const { t } = useTranslation()
|
||||||
useTranslation()
|
const { data, isValidating, mutate } = useSWR<Event>(`/api/events/${slug}`)
|
||||||
|
const [auth,] = useDefinedContext(AuthContext)
|
||||||
const { data, isValidating, mutate } =
|
const axios = useAxios()
|
||||||
useSWR<Event>(`/api/events/${slug}`)
|
|
||||||
|
|
||||||
const [auth, _setAuth] =
|
|
||||||
useDefinedContext(AuthContext)
|
|
||||||
|
|
||||||
const axios =
|
|
||||||
useAxios()
|
|
||||||
|
|
||||||
const { run: patchEditsToAPI, status: patchStatus } =
|
|
||||||
usePromise<Event, Event>((d) => axios.patch(`/api/events/${slug}`, d))
|
|
||||||
|
|
||||||
const isLoading = isValidating || patchStatus === UsePromiseStatus.PENDING
|
|
||||||
|
|
||||||
const save = useCallback(
|
const save = useCallback(
|
||||||
async () => {
|
async () => {
|
||||||
|
|
||||||
if (data === undefined) {
|
if (data === undefined) {
|
||||||
console.warn("[PageEvent] Tried to save while no data was available.")
|
console.warn("[PageEvent] Tried to save while no data was available.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
patchEditsToAPI(data)
|
await axios.patch(`/api/events/${slug}`, data)
|
||||||
mutate(data)
|
mutate(data)
|
||||||
|
console.debug("[PageEvent] Saved updated data successfully!")
|
||||||
console.info("[PageEvent] Saved successfully!")
|
|
||||||
},
|
},
|
||||||
[axios, data]
|
[axios, data]
|
||||||
)
|
)
|
||||||
|
@ -79,19 +66,20 @@ const PageEvent: NextPage<PageEventProps> = ({ slug }) => {
|
||||||
src={data?.postcard || defaultPostcard}
|
src={data?.postcard || defaultPostcard}
|
||||||
/>
|
/>
|
||||||
<WIPBanner />
|
<WIPBanner />
|
||||||
<EditingContext.Provider value={useState<EditingMode>(EditingMode.VIEW)}>
|
<EditingContextProvider>
|
||||||
<ViewContent
|
<ViewContent
|
||||||
title={
|
title={
|
||||||
<EditableText
|
<EditableText
|
||||||
value={data?.name ?? slug}
|
value={data?.name ?? slug}
|
||||||
onChange={e => mutate(async state => state ? { ...state, name: e.target.value } : undefined, { revalidate: false })}
|
onChange={e => mutate(async state => state ? { ...state, name: e.target.value } : undefined, { revalidate: false })}
|
||||||
viewPrefix={isLoading ? <><FestaIcon icon={faAsterisk} spin /> </> : undefined}
|
placeholder={t("eventTitlePlaceholder")}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
content={
|
content={
|
||||||
<EditableMarkdown
|
<EditableMarkdown
|
||||||
value={data?.description ?? ""}
|
value={data?.description ?? ""}
|
||||||
onChange={e => mutate(async state => state ? { ...state, description: e.target.value } : undefined, { revalidate: false })}
|
onChange={e => mutate(async state => state ? { ...state, description: e.target.value } : undefined, { revalidate: false })}
|
||||||
|
placeholder={t("eventDescriptionPlaceholder")}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
@ -103,7 +91,7 @@ const PageEvent: NextPage<PageEventProps> = ({ slug }) => {
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
</EditingContext.Provider>
|
</EditingContextProvider>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,5 +17,7 @@
|
||||||
"landingEventsCreateRejected": "Creazione dell'evento fallita:",
|
"landingEventsCreateRejected": "Creazione dell'evento fallita:",
|
||||||
"landingEventsCreateFulfilled": "Evento creato con successo! Trasferimento alla pagina dell'evento in corso...",
|
"landingEventsCreateFulfilled": "Evento creato con successo! Trasferimento alla pagina dell'evento in corso...",
|
||||||
"toolToggleEditingSave": "Salva modifiche",
|
"toolToggleEditingSave": "Salva modifiche",
|
||||||
"toolToggleEditingEdit": "Modifica"
|
"toolToggleEditingEdit": "Modifica",
|
||||||
|
"eventNamePlaceholder": "Nome evento",
|
||||||
|
"eventDescriptionPlaceholder": "Descrizione evento in **Markdown**"
|
||||||
}
|
}
|
Loading…
Reference in a new issue