2022-07-18 04:10:33 +00:00
|
|
|
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"
|
2022-07-18 04:10:33 +00:00
|
|
|
import cursor from "../../../styles/cursor.module.css"
|
2022-07-18 22:42:56 +00:00
|
|
|
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) {
|
2022-07-18 04:10:33 +00:00
|
|
|
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
|
2022-07-18 03:06:39 +00:00
|
|
|
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
|
|
|
}}
|
2022-07-18 22:42:56 +00:00
|
|
|
className={mood.positive}
|
2022-06-11 03:08:49 +00:00
|
|
|
>
|
2022-07-18 03:06:39 +00:00
|
|
|
<FestaIcon icon={faSave} />
|
2022-06-11 03:08:49 +00:00
|
|
|
</Tool>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (
|
|
|
|
<Tool
|
2022-07-18 03:06:39 +00:00
|
|
|
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>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|