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" ;
9
9
10
10
export const SaveTemplate = ( ) => {
11
11
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
+
15
15
const handleSubmit = ( ) => {
16
16
const pages : Page [ ] = fields . map ( ( field , index ) => {
17
17
return {
@@ -26,26 +26,38 @@ export const SaveTemplate = () => {
26
26
27
27
}
28
28
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 ] ) )
30
40
navigate ( '/' )
31
41
}
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" >
34
45
< UploadHeader
35
46
title = "Save template"
36
47
onBack = { ( ) => navigate ( "/new-template/annotate" ) }
37
48
onSubmit = { handleSubmit }
38
49
/>
39
- < Divider margin = "0px" />
50
+ < Divider margin = "0px" />
40
51
< div className = "display-flex flex-justify-center padding-top-4" >
41
- < Stepper currentStep = { AnnotateStep . Save } />
52
+ < Stepper currentStep = { AnnotateStep . Save } />
42
53
</ 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" >
46
58
Save segmentation as a template
47
59
</ h1 >
48
- < div style = { { width : '500px' } } data-testid = "save-template-form" >
60
+ < div style = { { width : '500px' } } data-testid = "save-template-form" >
49
61
< div className = "display-flex flex-column flex-align-self-center" >
50
62
< div className = "display-flex flex-column flex-align-start width-full" >
51
63
< Label htmlFor = "segmentation-template-name" >
0 commit comments