Skip to content

Commit 47676d5

Browse files
committed
Replace DefaultDirectoryPicker with FormPathInputComponent in PreferencesTab
1 parent 7106f76 commit 47676d5

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

apps/studio/src/modules/user-settings/components/preferences-tab.tsx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { SupportedLocale } from '@studio/common/lib/locale';
22
import { useI18n } from '@wordpress/react-i18n';
33
import { useCallback, useEffect, useRef, useState } from 'react';
44
import Button from 'src/components/button';
5+
import { FormPathInputComponent } from 'src/components/form-path-input';
6+
import { useFeatureFlags } from 'src/hooks/use-feature-flags';
57
import { isWindowsStore } from 'src/lib/app-globals';
68
import { getIpcApi } from 'src/lib/get-ipc-api';
79
import { ColorSchemePicker } from 'src/modules/user-settings/components/color-scheme-picker';
@@ -26,7 +28,7 @@ import {
2628
useGetStudioCliIsInstalledQuery,
2729
useSaveStudioCliIsInstalledMutation,
2830
} from 'src/stores/installed-apps-api';
29-
import { DefaultDirectoryPicker } from './default-directory-picker';
31+
import { SettingsFormField } from './settings-form-field';
3032

3133
export const PreferencesTab = ( { onClose }: { onClose: () => void } ) => {
3234
const { __ } = useI18n();
@@ -51,7 +53,6 @@ export const PreferencesTab = ( { onClose }: { onClose: () => void } ) => {
5153
const [ storedDefaultSiteDirectory, setStoredDefaultSiteDirectory ] = useState< string >();
5254
const [ defaultSiteDirectory, setDefaultSiteDirectory ] = useState< string >();
5355
const [ isLoadingDefaultSiteDirectory, setIsLoadingDefaultSiteDirectory ] = useState( true );
54-
const [ isSelectingDefaultDirectory, setIsSelectingDefaultDirectory ] = useState( false );
5556

5657
const wasSavedRef = useRef( false );
5758
const dirtyColorSchemeRef = useRef( dirtyColorScheme );
@@ -143,17 +144,12 @@ export const PreferencesTab = ( { onClose }: { onClose: () => void } ) => {
143144
}, [] );
144145

145146
const handleChangeDefaultDirectory = async () => {
146-
setIsSelectingDefaultDirectory( true );
147-
try {
148-
const response = await getIpcApi().showOpenFolderDialog(
149-
__( 'Select default site directory' ),
150-
defaultSiteDirectory ?? ''
151-
);
152-
if ( response?.path ) {
153-
setDefaultSiteDirectory( response.path );
154-
}
155-
} finally {
156-
setIsSelectingDefaultDirectory( false );
147+
const response = await getIpcApi().showOpenFolderDialog(
148+
__( 'Select default site directory' ),
149+
defaultSiteDirectory ?? ''
150+
);
151+
if ( response?.path ) {
152+
setDefaultSiteDirectory( response.path );
157153
}
158154
};
159155

@@ -172,12 +168,13 @@ export const PreferencesTab = ( { onClose }: { onClose: () => void } ) => {
172168
{ ! isWindowsStore() && (
173169
<StudioCliToggle value={ isCliInstalledSelection } onChange={ setDirtyIsCliInstalled } />
174170
) }
175-
<DefaultDirectoryPicker
176-
directory={ defaultSiteDirectory }
177-
isLoading={ isLoadingDefaultSiteDirectory }
178-
isSelecting={ isSelectingDefaultDirectory }
179-
onPick={ handleChangeDefaultDirectory }
180-
/>
171+
<SettingsFormField label={ __( 'Default site directory' ) }>
172+
<FormPathInputComponent
173+
value={ isLoadingDefaultSiteDirectory ? __( 'Loading...' ) : defaultSiteDirectory ?? '' }
174+
onClick={ handleChangeDefaultDirectory }
175+
doesPathContainWordPress={ false }
176+
/>
177+
</SettingsFormField>
181178
<div className="mt-auto pt-2 flex justify-end gap-3">
182179
<Button
183180
variant="tertiary"

0 commit comments

Comments
 (0)