-
-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add bulk delete mutation --------- Co-authored-by: WithoutPants <[email protected]>
- Loading branch information
1 parent
6ad0951
commit 7f83494
Showing
16 changed files
with
479 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
ui/v2.5/src/components/Scenes/DeleteSceneMarkersDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React, { useState } from "react"; | ||
import { useSceneMarkersDestroy } from "src/core/StashService"; | ||
import * as GQL from "src/core/generated-graphql"; | ||
import { ModalComponent } from "src/components/Shared/Modal"; | ||
import { useToast } from "src/hooks/Toast"; | ||
import { useIntl } from "react-intl"; | ||
import { faTrashAlt } from "@fortawesome/free-solid-svg-icons"; | ||
|
||
interface IDeleteSceneMarkersDialogProps { | ||
selected: GQL.SceneMarkerDataFragment[]; | ||
onClose: (confirmed: boolean) => void; | ||
} | ||
|
||
export const DeleteSceneMarkersDialog: React.FC< | ||
IDeleteSceneMarkersDialogProps | ||
> = (props: IDeleteSceneMarkersDialogProps) => { | ||
const intl = useIntl(); | ||
const singularEntity = intl.formatMessage({ id: "marker" }); | ||
const pluralEntity = intl.formatMessage({ id: "markers" }); | ||
|
||
const header = intl.formatMessage( | ||
{ id: "dialogs.delete_object_title" }, | ||
{ count: props.selected.length, singularEntity, pluralEntity } | ||
); | ||
const toastMessage = intl.formatMessage( | ||
{ id: "toast.delete_past_tense" }, | ||
{ count: props.selected.length, singularEntity, pluralEntity } | ||
); | ||
const message = intl.formatMessage( | ||
{ id: "dialogs.delete_object_desc" }, | ||
{ count: props.selected.length, singularEntity, pluralEntity } | ||
); | ||
|
||
const Toast = useToast(); | ||
const [deleteSceneMarkers] = useSceneMarkersDestroy( | ||
getSceneMarkersDeleteInput() | ||
); | ||
|
||
// Network state | ||
const [isDeleting, setIsDeleting] = useState(false); | ||
|
||
function getSceneMarkersDeleteInput(): GQL.SceneMarkersDestroyMutationVariables { | ||
return { | ||
ids: props.selected.map((marker) => marker.id), | ||
}; | ||
} | ||
|
||
async function onDelete() { | ||
setIsDeleting(true); | ||
try { | ||
await deleteSceneMarkers(); | ||
Toast.success(toastMessage); | ||
props.onClose(true); | ||
} catch (e) { | ||
Toast.error(e); | ||
props.onClose(false); | ||
} | ||
setIsDeleting(false); | ||
} | ||
|
||
return ( | ||
<ModalComponent | ||
show | ||
icon={faTrashAlt} | ||
header={header} | ||
accept={{ | ||
variant: "danger", | ||
onClick: onDelete, | ||
text: intl.formatMessage({ id: "actions.delete" }), | ||
}} | ||
cancel={{ | ||
onClick: () => props.onClose(false), | ||
text: intl.formatMessage({ id: "actions.cancel" }), | ||
variant: "secondary", | ||
}} | ||
isRunning={isDeleting} | ||
> | ||
<p>{message}</p> | ||
</ModalComponent> | ||
); | ||
}; | ||
|
||
export default DeleteSceneMarkersDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.