Skip to content

Commit 4bf6743

Browse files
committed
Move opened state to form
1 parent bc049bb commit 4bf6743

File tree

2 files changed

+56
-54
lines changed

2 files changed

+56
-54
lines changed

src/components/PreferencesModal/StorageTab.tsx

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,6 @@ const StorageEditPage = ({ storage }: StorageEditPageProps) => {
6969
setEditingName(false)
7070
}, [storage.id, db, newName])
7171

72-
const [convertPouchFormIsFolded, setConvertPouchFormIsFolded] = useState(true)
73-
74-
const openConvertPouchForm = useCallback(() => {
75-
setConvertPouchFormIsFolded(false)
76-
}, [])
77-
78-
const foldConvertPouchForm = useCallback(() => {
79-
setConvertPouchFormIsFolded(true)
80-
}, [])
81-
8272
return (
8373
<div>
8474
<h2>Storage Name</h2>
@@ -135,21 +125,10 @@ const StorageEditPage = ({ storage }: StorageEditPageProps) => {
135125
{storage.type === 'pouch' && appIsElectron && (
136126
<>
137127
<hr />
138-
139-
<FormHeading depth={2}>Convert File System based Storage</FormHeading>
140-
{convertPouchFormIsFolded ? (
141-
<FormGroup>
142-
<FormSecondaryButton onClick={openConvertPouchForm}>
143-
Convert
144-
</FormSecondaryButton>
145-
</FormGroup>
146-
) : (
147-
<ConvertPouchStorageForm
148-
storageId={storage.id}
149-
storageName={storage.name}
150-
closeForm={foldConvertPouchForm}
151-
/>
152-
)}
128+
<ConvertPouchStorageForm
129+
storageId={storage.id}
130+
storageName={storage.name}
131+
/>
153132
</>
154133
)}
155134
<hr />

src/components/organisms/ConvertPouchStorageForm.tsx

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
FormPrimaryButton,
77
FormBlockquote,
88
FormSecondaryButton,
9+
FormHeading,
910
} from '../atoms/form'
1011
import FormFolderSelector from '../atoms/FormFolderSelector'
1112
import { useDb } from '../../lib/db'
@@ -19,22 +20,30 @@ import { usePreferences } from '../../lib/preferences'
1920
interface ConvertPouchStorageProps {
2021
storageId: string
2122
storageName: string
22-
closeForm: () => void
2323
}
2424

2525
const ConvertPouchStorage = ({
2626
storageId,
2727
storageName,
28-
closeForm,
2928
}: ConvertPouchStorageProps) => {
30-
const [newStorageName, setNewStorageName] = useState(
31-
`${storageName} - Converted`
32-
)
29+
const { push } = useRouter()
3330
const { setClosed } = usePreferences()
34-
const [newStorageLocation, setNewStorageLocation] = useState('')
3531
const { storageMap, createStorage } = useDb()
32+
const [newStorageLocation, setNewStorageLocation] = useState('')
3633
const [errorMessage, setErrorMessage] = useState<string | null>(null)
37-
const { push } = useRouter()
34+
const [newStorageName, setNewStorageName] = useState('')
35+
const [opened, setOpened] = useState(false)
36+
37+
const openForm = useCallback(() => {
38+
setNewStorageName(`${storageName} - Converted`)
39+
setNewStorageLocation('')
40+
setErrorMessage(null)
41+
setOpened(true)
42+
}, [storageName])
43+
44+
const closeForm = useCallback(() => {
45+
setOpened(false)
46+
}, [])
3847

3948
const updateNewStorageName = useCallback(
4049
(event: ChangeEvent<HTMLInputElement>) => {
@@ -113,29 +122,43 @@ const ConvertPouchStorage = ({
113122

114123
return (
115124
<>
116-
<FormBlockquote variant={errorMessage == null ? 'primary' : 'danger'}>
117-
{errorMessage == null
118-
? 'This operation will clone data to File System based Storage.'
119-
: errorMessage}
120-
</FormBlockquote>
125+
<FormHeading depth={2}>Convert File System based Storage</FormHeading>
126+
{!opened ? (
127+
<FormGroup>
128+
<FormSecondaryButton onClick={openForm}>Convert</FormSecondaryButton>
129+
</FormGroup>
130+
) : (
131+
<>
132+
<FormBlockquote variant={errorMessage == null ? 'primary' : 'danger'}>
133+
{errorMessage == null
134+
? 'This operation will clone data to File System based Storage.'
135+
: errorMessage}
136+
</FormBlockquote>
121137

122-
<FormGroup>
123-
<FormLabel>Converted Storage Name</FormLabel>
124-
<FormTextInput value={newStorageName} onChange={updateNewStorageName} />
125-
</FormGroup>
126-
<FormGroup>
127-
<FormLabel>Converted Storage Location</FormLabel>
128-
<FormFolderSelector
129-
value={newStorageLocation}
130-
setValue={setNewStorageLocation}
131-
/>
132-
</FormGroup>
133-
<FormGroup>
134-
<FormPrimaryButton onClick={cloneAndConvertStorage}>
135-
Convert to File System based Storage
136-
</FormPrimaryButton>
137-
<FormSecondaryButton onClick={closeForm}>Cancel</FormSecondaryButton>
138-
</FormGroup>
138+
<FormGroup>
139+
<FormLabel>Converted Storage Name</FormLabel>
140+
<FormTextInput
141+
value={newStorageName}
142+
onChange={updateNewStorageName}
143+
/>
144+
</FormGroup>
145+
<FormGroup>
146+
<FormLabel>Converted Storage Location</FormLabel>
147+
<FormFolderSelector
148+
value={newStorageLocation}
149+
setValue={setNewStorageLocation}
150+
/>
151+
</FormGroup>
152+
<FormGroup>
153+
<FormPrimaryButton onClick={cloneAndConvertStorage}>
154+
Convert to File System based Storage
155+
</FormPrimaryButton>
156+
<FormSecondaryButton onClick={closeForm}>
157+
Cancel
158+
</FormSecondaryButton>
159+
</FormGroup>
160+
</>
161+
)}
139162
</>
140163
)
141164
}

0 commit comments

Comments
 (0)