1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-22 14:44:21 +00:00

Change ToolToggleEditing behaviour to "Edit / Save"

This commit is contained in:
Steffo 2022-07-18 05:06:39 +02:00
parent 2d63ebeaaf
commit ae79116259
Signed by: steffo
GPG key ID: 6965406171929D01
3 changed files with 11 additions and 15 deletions

View file

@ -1,4 +1,4 @@
import { faBinoculars, faPencil } from "@fortawesome/free-solid-svg-icons"
import { faPencil, faSave } from "@fortawesome/free-solid-svg-icons"
import { useTranslation } from "next-i18next"
import { useDefinedContext } from "../../../utils/definedContext"
import { EditingContext, EditingMode } from "../../generic/editable/base"
@ -7,42 +7,36 @@ import { Tool } from "../../generic/toolbar/tool"
export type ToolToggleEditingProps = {
onViewStart?: () => void,
onViewEnd?: () => void,
onEditStart?: () => void,
onEditEnd?: () => void,
save: () => void,
}
/**
* ToolBar {@link Tool} which switches between {@link EditingMode}s of the surrounding context.
*/
export function ToolToggleEditing({ onViewStart, onViewEnd, onEditStart, onEditEnd }: ToolToggleEditingProps) {
export function ToolToggleEditing({ save }: ToolToggleEditingProps) {
const { t } = useTranslation()
const [editing, setEditing] = useDefinedContext(EditingContext)
if (editing === EditingMode.EDIT) {
return (
<Tool
aria-label={t("toggleEditingView")}
aria-label={t("toolToggleEditingSave")}
onClick={() => {
onEditEnd?.()
save()
setEditing(EditingMode.VIEW)
onViewStart?.()
}}
>
<FestaIcon icon={faBinoculars} />
<FestaIcon icon={faSave} />
</Tool>
)
}
else {
return (
<Tool
aria-label={t("toggleEditingEdit")}
aria-label={t("toolToggleEditingEdit")}
onClick={() => {
onViewEnd?.()
setEditing(EditingMode.EDIT)
onEditStart?.()
}}
>
<FestaIcon icon={faPencil} />

View file

@ -99,7 +99,7 @@ const PageEvent: NextPage<PageEventProps> = ({ slug }) => {
<ToolToggleVisibility />
{data && auth?.userId === data?.creatorId &&
<ToolToggleEditing
onEditEnd={save}
save={save}
/>
}
</ToolBar>

View file

@ -15,5 +15,7 @@
"landingEventsCreateSubmitLabel": "Crea evento",
"landingEventsCreatePending": "Creazione dell'evento in corso...",
"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",
"toolToggleEditingEdit": "Modifica"
}