mirror of
https://github.com/Steffo99/festa.git
synced 2024-12-22 22:54:22 +00:00
Make ToolToggleEditing uninteractable while save is running
This commit is contained in:
parent
8e5221814d
commit
7b2bf7031f
1 changed files with 21 additions and 4 deletions
|
@ -1,24 +1,41 @@
|
||||||
import { faPencil, faSave } from "@fortawesome/free-solid-svg-icons"
|
import { faAsterisk, faPencil, faSave } from "@fortawesome/free-solid-svg-icons"
|
||||||
import { useTranslation } from "next-i18next"
|
import { useTranslation } from "next-i18next"
|
||||||
import { useDefinedContext } from "../../../utils/definedContext"
|
import { useDefinedContext } from "../../../utils/definedContext"
|
||||||
import { EditingContext, EditingMode } from "../../generic/editable/base"
|
import { EditingContext, EditingMode } from "../../generic/editable/base"
|
||||||
|
import { usePromise, UsePromiseStatus } from "../../generic/loading/promise"
|
||||||
import { FestaIcon } from "../../generic/renderers/fontawesome"
|
import { FestaIcon } from "../../generic/renderers/fontawesome"
|
||||||
import { Tool } from "../../generic/toolbar/tool"
|
import { Tool } from "../../generic/toolbar/tool"
|
||||||
|
import cursor from "../../../styles/cursor.module.css"
|
||||||
|
|
||||||
|
|
||||||
export type ToolToggleEditingProps = {
|
export type ToolToggleEditingProps = {
|
||||||
save: () => void,
|
save: () => Promise<void>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ToolBar {@link Tool} which switches between {@link EditingMode}s of the surrounding context.
|
* ToolBar {@link Tool} which switches between {@link EditingMode}s of the surrounding context.
|
||||||
|
*
|
||||||
|
* It calls an async function to save data when switching from edit mode to view mode, preventing the user from switching back again until the data is saved, but allowing them to view the updated resource.
|
||||||
*/
|
*/
|
||||||
export function ToolToggleEditing({ save }: ToolToggleEditingProps) {
|
export function ToolToggleEditing(props: ToolToggleEditingProps) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [editing, setEditing] = useDefinedContext(EditingContext)
|
const [editing, setEditing] = useDefinedContext(EditingContext)
|
||||||
|
|
||||||
if (editing === EditingMode.EDIT) {
|
const { run: save, status: saveStatus } = usePromise<void, void>(props.save)
|
||||||
|
|
||||||
|
if (saveStatus === UsePromiseStatus.PENDING) {
|
||||||
|
return (
|
||||||
|
<Tool
|
||||||
|
aria-label={t("toolToggleEditingSaving")}
|
||||||
|
disabled
|
||||||
|
className={cursor.loadingBlocking}
|
||||||
|
>
|
||||||
|
<FestaIcon icon={faAsterisk} spin />
|
||||||
|
</Tool>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else if (editing === EditingMode.EDIT) {
|
||||||
return (
|
return (
|
||||||
<Tool
|
<Tool
|
||||||
aria-label={t("toolToggleEditingSave")}
|
aria-label={t("toolToggleEditingSave")}
|
||||||
|
|
Loading…
Reference in a new issue