Skip to content

Commit 3099841

Browse files
authored
Allow for multiple templates to be saved rather than just the last one (#224)
1 parent af429b9 commit 3099841

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

OCR/frontend/src/pages/SaveTemplate.tsx

+32-20
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { Label, TextInput } from "@trussworks/react-uswds";
2-
import { Divider } from "../components/Divider";
3-
import { UploadHeader } from "../components/Header";
4-
import { Stepper } from "../components/Stepper";
5-
import { AnnotateStep } from "../utils/constants";
6-
import { useNavigate } from "react-router-dom";
7-
import { useAnnotationContext } from "../contexts/AnnotationContext";
8-
import { useFiles, File, Page } from "../contexts/FilesContext";
1+
import {Label, TextInput} from "@trussworks/react-uswds";
2+
import {Divider} from "../components/Divider";
3+
import {UploadHeader} from "../components/Header";
4+
import {Stepper} from "../components/Stepper";
5+
import {AnnotateStep} from "../utils/constants";
6+
import {useNavigate} from "react-router-dom";
7+
import {useAnnotationContext} from "../contexts/AnnotationContext";
8+
import {useFiles, File, Page} from "../contexts/FilesContext";
99

1010
export const SaveTemplate = () => {
1111
const navigate = useNavigate();
12-
const { fields, setDescription, setName, name, description, annotatedImages} = useAnnotationContext()
13-
const { addFile } = useFiles();
14-
12+
const {fields, setDescription, setName, name, description, annotatedImages} = useAnnotationContext()
13+
const {addFile} = useFiles();
14+
1515
const handleSubmit = () => {
1616
const pages: Page[] = fields.map((field, index) => {
1717
return {
@@ -26,26 +26,38 @@ export const SaveTemplate = () => {
2626

2727
}
2828
addFile(tempFile)
29-
localStorage.setItem('templates', JSON.stringify([tempFile]))
29+
let existingTemplates = []
30+
try {
31+
const data = localStorage.getItem('templates');
32+
if (data) {
33+
existingTemplates = JSON.parse(data);
34+
}
35+
36+
} catch {
37+
console.error("Invalid information found in templates, it will be overwritten")
38+
}
39+
localStorage.setItem('templates', JSON.stringify([...existingTemplates, tempFile]))
3040
navigate('/')
3141
}
32-
return (
33-
<div className="display-flex flex-column flex-justify-start width-full height-full padding-1 padding-top-2" data-testid="save-template-page">
42+
return (
43+
<div className="display-flex flex-column flex-justify-start width-full height-full padding-1 padding-top-2"
44+
data-testid="save-template-page">
3445
<UploadHeader
3546
title="Save template"
3647
onBack={() => navigate("/new-template/annotate")}
3748
onSubmit={handleSubmit}
3849
/>
39-
<Divider margin="0px" />
50+
<Divider margin="0px"/>
4051
<div className="display-flex flex-justify-center padding-top-4">
41-
<Stepper currentStep={AnnotateStep.Save} />
52+
<Stepper currentStep={AnnotateStep.Save}/>
4253
</div>
43-
<Divider margin="0px" />
44-
<div className="display-flex flex-column flex-align-center flex-justify-start flex-align-center height-full width-full padding-2 bg-primary-lighter">
45-
<h1 style={{ width: '500px' }} data-testid="save-template-title">
54+
<Divider margin="0px"/>
55+
<div
56+
className="display-flex flex-column flex-align-center flex-justify-start flex-align-center height-full width-full padding-2 bg-primary-lighter">
57+
<h1 style={{width: '500px'}} data-testid="save-template-title">
4658
Save segmentation as a template
4759
</h1>
48-
<div style={{ width: '500px' }} data-testid="save-template-form">
60+
<div style={{width: '500px'}} data-testid="save-template-form">
4961
<div className="display-flex flex-column flex-align-self-center">
5062
<div className="display-flex flex-column flex-align-start width-full">
5163
<Label htmlFor="segmentation-template-name">

0 commit comments

Comments
 (0)