@@ -3,16 +3,18 @@ import {useMapStore} from '@/app/store/mapStore';
33import { saveMap } from '@/app/utils/api/apiHandlers/saveMap' ;
44import { DocumentMetadata } from '@/app/utils/api/apiHandlers/types' ;
55import { DEFAULT_MAP_METADATA } from '@/app/utils/language' ;
6- import { Button , Flex , Select , Text , TextArea } from '@radix-ui/themes' ;
6+ import { Blockquote , Box , Button , Flex , Select , Text , TextArea } from '@radix-ui/themes' ;
77import { Input } from 'postcss' ;
88import { useEffect , useState } from 'react' ;
99
1010export const MetadataPanel = ( ) => {
11+ const isEditing = useMapStore ( state => state . isEditing ) ;
1112 const mapMetadata = useMapMetadata ( ) ;
1213 const numDistricts = useMapStore ( state => state . mapDocument ?. num_districts ) ;
1314 const [ innerFormState , setInnerFormState ] = useState < DocumentMetadata > (
1415 mapMetadata ?? DEFAULT_MAP_METADATA
1516 ) ;
17+ const [ loadingMessage , setLoadingMessage ] = useState ( '' ) ;
1618 const missingDistrictComments = Array . from ( { length : numDistricts || 0 } , ( _ , i ) => i + 1 ) . filter (
1719 i => ! innerFormState . district_comments ?. [ i ]
1820 ) ;
@@ -22,50 +24,82 @@ export const MetadataPanel = () => {
2224 } , [ mapMetadata ] ) ;
2325
2426 const handleMetadataChange = async ( updates : Partial < DocumentMetadata > ) => {
25- await saveMap ( {
27+ setLoadingMessage ( 'Saving...' ) ;
28+ const r = await saveMap ( {
2629 ...( mapMetadata || DEFAULT_MAP_METADATA ) ,
2730 ...updates ,
2831 } ) ;
32+ if ( r ) {
33+ setLoadingMessage ( 'Saved!' ) ;
34+ } else {
35+ setLoadingMessage ( 'Failed to save' ) ;
36+ }
37+ setTimeout ( ( ) => {
38+ setLoadingMessage ( '' ) ;
39+ } , 2000 ) ;
2940 } ;
30- console . log ( '!!!' , innerFormState ) ;
3141
3242 return (
33- < Flex direction = "column" gap = "2" >
43+ < Flex
44+ direction = "column"
45+ gap = "2"
46+ className = { `relative ${ loadingMessage ?. length ? 'pointer-events-none' : '' } ` }
47+ >
48+ { ! ! loadingMessage ?. length && (
49+ < Box className = "absolute top-0 left-0 w-full h-full bg-white/90 flex items-center justify-center" >
50+ < Text > { loadingMessage } </ Text >
51+ </ Box >
52+ ) }
3453 < Flex direction = "column" gap = "2" >
3554 < Text > Plan Comments</ Text >
36- < TextArea
37- value = { innerFormState ?. description || '' }
38- onChange = { e => setInnerFormState ( { ...innerFormState , district_comments : e . target . value } ) }
39- />
40- </ Flex >
41- < Flex direction = "row" gap = "2" >
42- < Button
43- onClick = { ( ) =>
44- handleMetadataChange ( {
45- description : innerFormState . description ,
46- district_comments : innerFormState . district_comments ,
47- } )
48- }
49- color = "green"
50- >
51- Save
52- </ Button >
53- < Button onClick = { ( ) => setInnerFormState ( mapMetadata ?? DEFAULT_MAP_METADATA ) } color = "red" >
54- Reset
55- </ Button >
55+ { isEditing ? (
56+ < TextArea
57+ value = { innerFormState ?. description || '' }
58+ onChange = { e => setInnerFormState ( { ...innerFormState , description : e . target . value } ) }
59+ />
60+ ) : (
61+ < Blockquote > { innerFormState ?. description || '' } </ Blockquote >
62+ ) }
5663 </ Flex >
64+ { isEditing && (
65+ < Flex direction = "row" gap = "2" >
66+ < Button
67+ onClick = { ( ) =>
68+ handleMetadataChange ( {
69+ description : innerFormState . description ,
70+ district_comments : innerFormState . district_comments ,
71+ } )
72+ }
73+ color = "green"
74+ >
75+ Save
76+ </ Button >
77+ < Button
78+ onClick = { ( ) => setInnerFormState ( mapMetadata ?? DEFAULT_MAP_METADATA ) }
79+ color = "red"
80+ >
81+ Reset
82+ </ Button >
83+ </ Flex >
84+ ) }
5785 < Flex direction = "column" gap = "2" >
5886 < Text > District Comments</ Text >
59- { Object . keys ( innerFormState . district_comments || { } ) . map ( district => (
60- < DistrictCommentRow
61- key = { district }
62- district = { Number ( district ) }
63- innerFormState = { innerFormState }
64- setInnerFormState = { setInnerFormState }
65- numDistricts = { numDistricts || 0 }
66- />
67- ) ) }
68- { missingDistrictComments . length > 0 && (
87+ { Object . keys ( innerFormState . district_comments || { } ) . map ( district =>
88+ isEditing ? (
89+ < DistrictCommentRow
90+ key = { district }
91+ district = { Number ( district ) }
92+ innerFormState = { innerFormState }
93+ setInnerFormState = { setInnerFormState }
94+ numDistricts = { numDistricts || 0 }
95+ />
96+ ) : (
97+ < Blockquote >
98+ < b > { district } :</ b > { innerFormState . district_comments ?. [ Number ( district ) ] || '' }
99+ </ Blockquote >
100+ )
101+ ) }
102+ { missingDistrictComments . length > 0 && isEditing && (
69103 < Button
70104 onClick = { ( ) =>
71105 setInnerFormState ( {
0 commit comments