1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-23 15:14:23 +00:00
festa/components/events/toolbar/toolToggleEditing.tsx

62 lines
1.8 KiB
TypeScript
Raw Normal View History

import { faAsterisk, faPencil, faSave } from "@fortawesome/free-solid-svg-icons"
2022-06-11 03:08:49 +00:00
import { useTranslation } from "next-i18next"
2022-07-20 11:26:34 +00:00
import { UsePromise, usePromise, UsePromiseStatus } from "../../generic/loading/promise"
2022-06-11 03:08:49 +00:00
import { FestaIcon } from "../../generic/renderers/fontawesome"
import { Tool } from "../../generic/toolbar/tool"
import cursor from "../../../styles/cursor.module.css"
import mood from "../../../styles/mood.module.css"
2022-07-19 18:25:11 +00:00
import { Dispatch } from "react"
2022-06-11 03:08:49 +00:00
2022-07-16 17:21:42 +00:00
export type ToolToggleEditingProps = {
2022-07-19 18:25:11 +00:00
editing: boolean,
setEditing: Dispatch<boolean>,
2022-07-20 11:26:34 +00:00
save: UsePromise<void, void>,
2022-07-16 17:21:42 +00:00
}
2022-06-11 03:08:49 +00:00
/**
2022-07-19 18:25:11 +00:00
* ToolBar {@link Tool} which allows the user to start editing an event and then save their changes.
2022-06-11 03:08:49 +00:00
*/
2022-07-20 11:26:34 +00:00
export function ToolToggleEditing({ editing, setEditing, save }: ToolToggleEditingProps) {
2022-06-11 03:08:49 +00:00
const { t } = useTranslation()
2022-07-20 11:26:34 +00:00
if (save.status === UsePromiseStatus.PENDING) {
return (
<Tool
aria-label={t("toolToggleEditingSaving")}
disabled
className={cursor.loadingBlocking}
>
<FestaIcon icon={faAsterisk} spin />
</Tool>
)
}
2022-07-19 18:25:11 +00:00
else if (editing) {
2022-06-11 03:08:49 +00:00
return (
<Tool
aria-label={t("toolToggleEditingSave")}
2022-07-16 17:21:42 +00:00
onClick={() => {
2022-07-20 11:26:34 +00:00
save.run()
2022-07-19 18:25:11 +00:00
setEditing(false)
2022-07-16 17:21:42 +00:00
}}
className={mood.positive}
2022-06-11 03:08:49 +00:00
>
<FestaIcon icon={faSave} />
2022-06-11 03:08:49 +00:00
</Tool>
)
}
else {
return (
<Tool
aria-label={t("toolToggleEditingEdit")}
2022-07-16 17:21:42 +00:00
onClick={() => {
2022-07-19 18:25:11 +00:00
setEditing(true)
2022-07-16 17:21:42 +00:00
}}
2022-06-11 03:08:49 +00:00
>
<FestaIcon icon={faPencil} />
</Tool>
)
}
}