Skip to content

Commit

Permalink
Merge pull request #4232 from nulib/4119-delete-vtt
Browse files Browse the repository at this point in the history
Require confirmation to delete WebVTT
  • Loading branch information
kdid authored Oct 23, 2024
2 parents e998276 + c8eaafc commit 227354f
Showing 1 changed file with 39 additions and 16 deletions.
55 changes: 39 additions & 16 deletions app/assets/js/components/Work/Tabs/Structure/WebVTTModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function WorkTabsStructureWebVTTModal({ isActive }) {
const [parseErrors, setParseErrors] = React.useState();
const workState = useWorkState();
const [webVttValue, setWebVttValue] = React.useState("");
const [confirmDelete, setConfirmDelete] = React.useState(false);
const params = useParams();
const workId = params.id;

Expand All @@ -34,7 +35,7 @@ function WorkTabsStructureWebVTTModal({ isActive }) {
if (graphQLErrors?.length > 0) {
errorStrings = graphQLErrors.map(
({ message, details }) =>
`${message}: ${details && details.title ? details.title : ""}`
`${message}: ${details && details.title ? details.title : ""}`,
);
}
toastWrapper("is-danger", errorStrings.join(" \n "));
Expand Down Expand Up @@ -65,6 +66,7 @@ function WorkTabsStructureWebVTTModal({ isActive }) {
dispatch({ type: "toggleWebVttModal", fileSetId: null });
setParseErrors(null);
setWebVttValue("");
setConfirmDelete(false);
};

const handleSubmit = (structuralMetadata) => {
Expand All @@ -76,6 +78,12 @@ function WorkTabsStructureWebVTTModal({ isActive }) {
});
};

const handleDelete = () => {
setConfirmDelete(true);
setParseErrors("Are you sure you want to delete this WebVTT structure?");
setWebVttValue("");
};

return (
<div
className={classNames(["modal"], {
Expand All @@ -95,6 +103,12 @@ function WorkTabsStructureWebVTTModal({ isActive }) {
</header>

<section className="modal-card-body">
{confirmDelete && (
<Notification isDanger>
Are you sure you want to delete this WebVTT structure?
</Notification>
)}

{webVttValue?.trim().length > 0 &&
(parseErrors ? (
<Notification isDanger>{parseErrors.message}</Notification>
Expand All @@ -107,34 +121,43 @@ function WorkTabsStructureWebVTTModal({ isActive }) {
placeholder="Enter WebVTT text here"
ref={textAreaRef}
rows="10"
style={{ whiteSpace: "pre-wrap" }}
style={{
whiteSpace: "pre-wrap",
display: confirmDelete ? "none" : "block",
}}
value={webVttValue}
/>
</section>
<footer className="modal-card-foot buttons is-justify-content-space-between">
{webVttValue?.trim().length > 0 && (
{webVttValue?.trim().length > 0 && !confirmDelete && (
<Button
isText
onClick={() => handleSubmit({})}
onClick={() => handleDelete()}
css={{ backgroundColor: "transparent" }}
>
Delete WebVTT
</Button>
)}
<div className="is-flex is-justify-content-flex-end is-flex-grow-1">
<Button onClick={handleClose}>Cancel</Button>
<Button
isPrimary
onClick={() =>
handleSubmit({
type: "WEBVTT",
value: webVttValue,
})
}
disabled={parseErrors}
>
Submit
</Button>
{confirmDelete ? (
<Button isPrimary onClick={() => handleSubmit({})}>
Yes, delete
</Button>
) : (
<Button
isPrimary
onClick={() =>
handleSubmit({
type: "WEBVTT",
value: webVttValue,
})
}
disabled={parseErrors}
>
Submit
</Button>
)}
</div>
</footer>
</div>
Expand Down

0 comments on commit 227354f

Please sign in to comment.