TagSpaces is an offline, open source, document manager with tagging support
chore: improving usability of the export/import functionality
Ilian Sapundshiev567cff3cc9be
diff --git a/src/renderer/components/LocationManager.tsx b/src/renderer/components/LocationManager.tsxindex 7ddc255cf..aea5f5c39 100644--- a/src/renderer/components/LocationManager.tsx+++ b/src/renderer/components/LocationManager.tsx@@ -19,7 +19,8 @@import LocationView from '-/components/LocationView';import TsButton from '-/components/TsButton';import { useCreateEditLocationDialogContext } from '-/components/dialogs/hooks/useCreateEditLocationDialogContext';-import ExportImportDialog from '-/components/dialogs/ExportImportDialog';+import { SettingsTab } from '-/components/dialogs/SettingsDialog';+import { useSettingsDialogContext } from '-/components/dialogs/hooks/useSettingsDialogContext';import LocationContextMenu from '-/components/menus/LocationContextMenu';import LocationManagerMenu from '-/components/menus/LocationManagerMenu';import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';@@ -46,14 +47,12 @@ function LocationManager(props: Props) {locationDirectoryContextMenuAnchorEl,} = useCurrentLocationContext();const { openCreateEditLocationDialog } = useCreateEditLocationDialogContext();+ const { openSettingsDialog } = useSettingsDialogContext();const locations: TS.Location[] = useSelector(getLocations);const [wSpaceLocations, setWSpaceLocations] =useState<TS.Location[]>(locations);const fileInputRef = useRef<HTMLInputElement>(null);- const [isExportLocationsDialogOpened, setExportLocationsDialogOpened] =- useState<boolean>(false);- const [importFile, setImportFile] = useState<File>(undefined);const workSpacesContext = Pro?.contextProviders?.WorkSpacesContext? useContext<TS.WorkSpacesContextData>(@@ -79,7 +78,13 @@ function LocationManager(props: Props) {function handleFileInputChange(selection: any) {const target = selection.currentTarget;const file = target.files[0];- setImportFile(file);+ if (file) {+ openSettingsDialog(SettingsTab.BackupRestore, {+ mode: 'import',+ scope: 'locations',+ importFile: file,+ });+ }target.value = null;}@@ -118,7 +123,12 @@ function LocationManager(props: Props) {importLocations={() => {fileInputRef.current.click();}}- exportLocations={() => setExportLocationsDialogOpened(true)}+ exportLocations={() =>+ openSettingsDialog(SettingsTab.BackupRestore, {+ mode: 'export',+ scope: 'locations',+ })+ }showCreateLocationDialog={() => {setSelectedLocation(undefined);openCreateEditLocationDialog();@@ -206,23 +216,6 @@ function LocationManager(props: Props) {type="file"onChange={handleFileInputChange}/>- {isExportLocationsDialogOpened && (- <ExportImportDialog- open={isExportLocationsDialogOpened}- mode="export"- scope="locations"- onClose={() => setExportLocationsDialogOpened(false)}- />- )}- {importFile && (- <ExportImportDialog- open={Boolean(importFile)}- mode="import"- scope="locations"- importFile={importFile}- onClose={() => setImportFile(undefined)}- />- )}</Box>);}diff --git a/src/renderer/components/StoredSearches.tsx b/src/renderer/components/StoredSearches.tsxindex 3cd371de2..98ab1b1c5 100644--- a/src/renderer/components/StoredSearches.tsx+++ b/src/renderer/components/StoredSearches.tsx@@ -52,7 +52,8 @@ import { useTranslation } from 'react-i18next';import { connect } from 'react-redux';import { bindActionCreators } from 'redux';import { Pro } from '../pro';-import ExportImportDialog from './dialogs/ExportImportDialog';+import { SettingsTab } from './dialogs/SettingsDialog';+import { useSettingsDialogContext } from './dialogs/hooks/useSettingsDialogContext';import SidePanelTitle from './SidePanelTitle';interface Props {@@ -90,10 +91,8 @@ function StoredSearches(props: Props) {const [bookmarksMenuAnchorEl, setBookmarksMenuAnchorEl] =useState<null | HTMLElement>(null);- const [isExportSearchesDialogOpened, setExportSearchesDialogOpened] =- useState<boolean>(false);+ const { openSettingsDialog } = useSettingsDialogContext();- const [importFile, setImportFile] = useState<File>(undefined);const fileInputRef = useRef<HTMLInputElement>(null);const menuHistoryKey = useRef<string>(undefined);const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);@@ -109,7 +108,13 @@ function StoredSearches(props: Props) {function handleFileInputChange(selection: any) {const target = selection.currentTarget;const file = target.files[0];- setImportFile(file);+ if (file) {+ openSettingsDialog(SettingsTab.BackupRestore, {+ mode: 'import',+ scope: 'searches',+ importFile: file,+ });+ }target.value = null;}@@ -190,7 +195,10 @@ function StoredSearches(props: Props) {open={Boolean(searchMenuAnchorEl)}onClose={handleCloseSearchMenu}exportSearches={() => {- setExportSearchesDialogOpened(true);+ openSettingsDialog(SettingsTab.BackupRestore, {+ mode: 'export',+ scope: 'searches',+ });}}importSearches={() => {fileInputRef.current.click();@@ -500,23 +508,6 @@ function StoredSearches(props: Props) {type="file"onChange={handleFileInputChange}/>- {isExportSearchesDialogOpened && (- <ExportImportDialog- open={isExportSearchesDialogOpened}- mode="export"- scope="searches"- onClose={() => setExportSearchesDialogOpened(false)}- />- )}- {importFile && (- <ExportImportDialog- open={Boolean(importFile)}- mode="import"- scope="searches"- importFile={importFile}- onClose={() => setImportFile(undefined)}- />- )}</Box>);}diff --git a/src/renderer/components/dialogs/ExportImportDialog.tsx b/src/renderer/components/dialogs/ExportImportDialog.tsxdeleted file mode 100644index e6059d361..000000000--- a/src/renderer/components/dialogs/ExportImportDialog.tsx+++ /dev/null@@ -1,75 +0,0 @@-/**- * TagSpaces - universal file and folder organizer- * Copyright (C) 2017-present TagSpaces GmbH- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License (version 3) as- * published by the Free Software Foundation.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <https://www.gnu.org/licenses/>.- *- */--import DraggablePaper from '-/components/DraggablePaper';-import ExportImportPanel from '-/components/dialogs/ExportImportPanel';-import TsDialogTitle from '-/components/dialogs/components/TsDialogTitle';-import { TransferSection } from '-/services/export-import-utils';-import Dialog from '@mui/material/Dialog';-import DialogContent from '@mui/material/DialogContent';-import Paper from '@mui/material/Paper';-import { useTheme } from '@mui/material/styles';-import useMediaQuery from '@mui/material/useMediaQuery';-import { useTranslation } from 'react-i18next';--type Props = {- open: boolean;- mode: 'export' | 'import';- scope?: TransferSection;- importFile?: File;- onClose: () => void;-};--function ExportImportDialog(props: Props) {- const { open, mode, scope, importFile, onClose } = props;- const { t } = useTranslation();- const theme = useTheme();- const smallScreen = useMediaQuery(theme.breakpoints.down('md'));-- return (- <Dialog- open={open}- onClose={onClose}- fullScreen={smallScreen}- keepMounted- PaperComponent={smallScreen ? Paper : DraggablePaper}- scroll="paper"- >- <TsDialogTitle- dialogTitle={- mode === 'export'- ? t('core:startExportButton')- : t('core:startImportButton')- }- closeButtonTestId="closeExportImportTID"- onClose={onClose}- />- <DialogContent sx={{ minWidth: smallScreen ? 'unset' : '420px' }}>- <ExportImportPanel- mode={mode}- scope={scope}- importFile={importFile}- onDone={onClose}- onCancel={onClose}- />- </DialogContent>- </Dialog>- );-}--export default ExportImportDialog;diff --git a/src/renderer/components/dialogs/ExportImportPanel.tsx b/src/renderer/components/dialogs/ExportImportPanel.tsxindex 65f0d2d80..653a17aac 100644--- a/src/renderer/components/dialogs/ExportImportPanel.tsx+++ b/src/renderer/components/dialogs/ExportImportPanel.tsx@@ -49,12 +49,13 @@ import {import { prepareTagGroupsForExport } from '-/services/taglibrary-utils';import { TS } from '-/tagspaces.namespace';import { CommonLocation } from '-/utils/CommonLocation';+import Box from '@mui/material/Box';import Checkbox from '@mui/material/Checkbox';-import Divider from '@mui/material/Divider';import FormControl from '@mui/material/FormControl';import FormControlLabel from '@mui/material/FormControlLabel';import FormHelperText from '@mui/material/FormHelperText';import LinearProgress from '@mui/material/LinearProgress';+import ListItemText from '@mui/material/ListItemText';import Typography from '@mui/material/Typography';import { EXPORT_VERSION } from '-/services/export-import-utils';import { useEffect, useMemo, useState } from 'react';@@ -603,145 +604,183 @@ function ExportImportPanel(props: Props) {: importSelectionEmpty;return (- <div data-tid="unifiedExportImportPanelTID">- <Typography sx={{ marginBottom: '8px' }}>- {mode === 'export'- ? t('core:selectWhatToExport')- : t('core:selectWhatToImport')}- </Typography>-- {ALL_SECTIONS.map(renderSection)}-- {mode === 'export' && (- <>- <Divider sx={{ margin: '8px 0' }} />- <FormControl fullWidth>- <FormControlLabel- labelPlacement="start"- sx={{- marginLeft: 0,- marginRight: 0,- justifyContent: 'space-between',- }}- control={- <TsSwitch- checked={encrypt}- onClick={() => setEncrypt(!encrypt)}- data-tid="encryptExportTID"- />- }- label={t('core:encryptExport')}- />- </FormControl>- {credentialsInSelection && !encrypt && (- <FormHelperText sx={{ color: 'error.main' }}>- {t('core:disableEncryptionWarning')}- </FormHelperText>- )}- {credentialsInSelection && encrypt && (- <FormHelperText>{t('core:encryptionRecommended')}</FormHelperText>- )}- {encrypt && (- <>- <FormControl fullWidth sx={{ paddingTop: '10px' }}>- <TsTextField- name="exportPassword"- autoFocus- slotProps={{- input: { autoCorrect: 'off', autoCapitalize: 'none' },- }}- label={t('core:aesPassword')}- type="password"- onChange={(event: any) =>- setExportPassword(event.target.value)- }- updateValue={(value: string) => setExportPassword(value)}- retrieveValue={() => exportPassword}- data-tid="exportPasswordTID"- />- </FormControl>- {exportPassword.length > 0 && (- <div- data-tid="passwordStrengthTID"- style={{ marginTop: 4, marginBottom: 4 }}- >- <LinearProgress- variant="determinate"- value={(pwStrength.score / 4) * 100}- color={- pwStrength.label === 'weak'- ? 'error'- : pwStrength.label === 'fair'- ? 'warning'- : pwStrength.label === 'good'- ? 'info'- : 'success'- }- sx={{ borderRadius: AppConfig.defaultCSSRadius }}- />- <Typography- variant="caption"- sx={{- color: passwordTooWeak ? 'error.main' : 'text.secondary',- }}- >- {t('core:passwordStrength')}:{' '}- {t('core:pwStrength_' + pwStrength.label)}- </Typography>- </div>- )}- {passwordTooWeak && (- <FormHelperText sx={{ color: 'error.main' }}>- {t('core:passwordTooWeak')}- </FormHelperText>- )}- <FormControl fullWidth error={passwordMismatch}>- <TsTextField- name="retypePassword"- slotProps={{- input: { autoCorrect: 'off', autoCapitalize: 'none' },- }}- label={t('core:retypePassword')}- type="password"- onChange={(event: any) =>- setRetypePassword(event.target.value)- }- data-tid="retypePasswordTID"- />- </FormControl>- {passwordMismatch && (- <FormHelperText sx={{ color: 'error.main' }}>- {t('core:retypePasswordDiffError')}- </FormHelperText>- )}- </>- )}- </>- )}-- <div- style={{- marginTop: 16,- display: 'flex',- justifyContent: 'flex-end',- gap: AppConfig.defaultSpaceBetweenButtons,+ <Box+ data-tid="unifiedExportImportPanelTID"+ sx={{+ display: 'flex',+ flexDirection: 'column',+ height: '100%',+ minHeight: 0,+ paddingX: 2,+ paddingTop: 1,+ paddingBottom: 1,+ }}+ >+ {/* Sticky header: the real action buttons + encryption controls stay+ pinned while the section list below scrolls. */}+ <Box+ data-tid="exportImportHeaderTID"+ sx={{+ flexShrink: 0,+ backgroundColor: 'background.paper',+ borderBottom: 1,+ borderColor: 'divider',+ paddingBottom: 1,+ marginBottom: 1,}}>- <TsButton onClick={onCancel} data-tid="cancelExportImportTID">- {t('core:cancel')}- </TsButton>- <TsButton- onClick={mode === 'export' ? handleExport : handleImport}- data-tid="exportImportConfirmTID"- variant="contained"- disabled={confirmDisabled || busy}+ <div+ style={{+ display: 'flex',+ alignItems: 'flex-start',+ justifyContent: 'space-between',+ gap: AppConfig.defaultSpaceBetweenButtons,+ }}>- {mode === 'export'- ? t('core:startExportButton')- : t('core:startImportButton')}- </TsButton>- </div>- </div>+ <ListItemText+ primary={t('core:exportImportTitle')}+ secondary={+ mode === 'export'+ ? t('core:selectWhatToExport')+ : t('core:selectWhatToImport')+ }+ />+ <div+ style={{+ display: 'flex',+ flexShrink: 0,+ gap: AppConfig.defaultSpaceBetweenButtons,+ }}+ >+ <TsButton onClick={onCancel} data-tid="cancelExportImportTID">+ {t('core:cancel')}+ </TsButton>+ <TsButton+ onClick={mode === 'export' ? handleExport : handleImport}+ data-tid="exportImportConfirmTID"+ variant="contained"+ disabled={confirmDisabled || busy}+ >+ {mode === 'export'+ ? t('core:startExportButton')+ : t('core:startImportButton')}+ </TsButton>+ </div>+ </div>++ {mode === 'export' && (+ <>+ <FormControl fullWidth>+ <FormControlLabel+ labelPlacement="start"+ sx={{+ marginLeft: 0,+ marginRight: 0,+ justifyContent: 'space-between',+ }}+ control={+ <TsSwitch+ checked={encrypt}+ onClick={() => setEncrypt(!encrypt)}+ data-tid="encryptExportTID"+ />+ }+ label={t('core:encryptExport')}+ />+ </FormControl>+ {credentialsInSelection && !encrypt && (+ <FormHelperText sx={{ color: 'error.main' }}>+ {t('core:disableEncryptionWarning')}+ </FormHelperText>+ )}+ {credentialsInSelection && encrypt && (+ <FormHelperText>{t('core:encryptionRecommended')}</FormHelperText>+ )}+ {encrypt && (+ <>+ <FormControl fullWidth sx={{ paddingTop: '10px' }}>+ <TsTextField+ name="exportPassword"+ autoFocus+ slotProps={{+ input: { autoCorrect: 'off', autoCapitalize: 'none' },+ }}+ label={t('core:aesPassword')}+ type="password"+ onChange={(event: any) =>+ setExportPassword(event.target.value)+ }+ updateValue={(value: string) => setExportPassword(value)}+ retrieveValue={() => exportPassword}+ data-tid="exportPasswordTID"+ />+ </FormControl>+ {exportPassword.length > 0 && (+ <div+ data-tid="passwordStrengthTID"+ style={{ marginTop: 4, marginBottom: 4 }}+ >+ <LinearProgress+ variant="determinate"+ value={(pwStrength.score / 4) * 100}+ color={+ pwStrength.label === 'weak'+ ? 'error'+ : pwStrength.label === 'fair'+ ? 'warning'+ : pwStrength.label === 'good'+ ? 'info'+ : 'success'+ }+ sx={{ borderRadius: AppConfig.defaultCSSRadius }}+ />+ <Typography+ variant="caption"+ sx={{+ color: passwordTooWeak+ ? 'error.main'+ : 'text.secondary',+ }}+ >+ {t('core:passwordStrength')}:{' '}+ {t('core:pwStrength_' + pwStrength.label)}+ </Typography>+ </div>+ )}+ {passwordTooWeak && (+ <FormHelperText sx={{ color: 'error.main' }}>+ {t('core:passwordTooWeak')}+ </FormHelperText>+ )}+ <FormControl fullWidth error={passwordMismatch}>+ <TsTextField+ name="retypePassword"+ slotProps={{+ input: { autoCorrect: 'off', autoCapitalize: 'none' },+ }}+ label={t('core:retypePassword')}+ type="password"+ onChange={(event: any) =>+ setRetypePassword(event.target.value)+ }+ data-tid="retypePasswordTID"+ />+ </FormControl>+ {passwordMismatch && (+ <FormHelperText sx={{ color: 'error.main' }}>+ {t('core:retypePasswordDiffError')}+ </FormHelperText>+ )}+ </>+ )}+ </>+ )}+ </Box>++ <Box sx={{ flex: 1, minHeight: 0, overflowY: 'auto' }}>+ {ALL_SECTIONS.map(renderSection)}+ </Box>+ </Box>);}diff --git a/src/renderer/components/dialogs/SettingsDialog.tsx b/src/renderer/components/dialogs/SettingsDialog.tsxindex c7bfb87f7..dd758576f 100644--- a/src/renderer/components/dialogs/SettingsDialog.tsx+++ b/src/renderer/components/dialogs/SettingsDialog.tsx@@ -37,6 +37,7 @@ import SettingsPerspectives from '-/components/dialogs/components/SettingsPerspeimport SettingsTemplates from '-/components/dialogs/components/SettingsTemplates';import TsDialogActions from '-/components/dialogs/components/TsDialogActions';import TsDialogTitle from '-/components/dialogs/components/TsDialogTitle';+import type { TransferSection } from '-/services/export-import-validators';import { openURLExternally } from '-/services/utils-io';import ArticleIcon from '@mui/icons-material/Article';import Dialog from '@mui/material/Dialog';@@ -61,16 +62,28 @@ export enum SettingsTab {AI = 'ai',}+/**+ * Lets callers (e.g. the Locations menu) open Settings directly on the Backup+ * tab and immediately start an export/import scoped to one section, instead of+ * spawning a separate dialog.+ */+export type SettingsBackupIntent = {+ mode: 'export' | 'import';+ scope?: TransferSection;+ importFile?: File;+};+interface Props {open: boolean;tab?: SettingsTab;+ backup?: SettingsBackupIntent;classes?: any;onClose: () => void;}function SettingsDialog(props: Props) {const { t } = useTranslation();- const { open, onClose, tab } = props;+ const { open, onClose, tab, backup } = props;const [currentTab, setCurrentTab] = useState<SettingsTab>(tab || SettingsTab.General,);@@ -229,7 +242,9 @@ function SettingsDialog(props: Props) {{currentTab === SettingsTab.KeyBindings && <SettingsKeyBindings />}{currentTab === SettingsTab.Extensions && <SettingsExtensions />}{currentTab === SettingsTab.Perspectives && <SettingsPerspectives />}- {currentTab === SettingsTab.BackupRestore && <SettingsBackupRestore />}+ {currentTab === SettingsTab.BackupRestore && (+ <SettingsBackupRestore backup={backup} />+ )}{currentTab === SettingsTab.AI && (<SettingsAI closeSettings={onClose} />)}diff --git a/src/renderer/components/dialogs/components/SettingsBackupRestore.tsx b/src/renderer/components/dialogs/components/SettingsBackupRestore.tsxindex 9d91fe86a..231ed764e 100644--- a/src/renderer/components/dialogs/components/SettingsBackupRestore.tsx+++ b/src/renderer/components/dialogs/components/SettingsBackupRestore.tsx@@ -19,22 +19,43 @@import AppConfig from '-/AppConfig';import { ExportIcon, ImportIcon } from '-/components/CommonIcons';import TsButton from '-/components/TsButton';+import type { SettingsBackupIntent } from '-/components/dialogs/SettingsDialog';import ExportImportPanel from '-/components/dialogs/ExportImportPanel';+import type { TransferSection } from '-/services/export-import-validators';+import Box from '@mui/material/Box';import List from '@mui/material/List';import ListItem from '@mui/material/ListItem';import ListItemText from '@mui/material/ListItemText';-import { useRef, useState } from 'react';+import { useEffect, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';-function SettingsBackupRestore() {+type Props = {+ /** When set (e.g. opened from the Locations menu), jump straight into a+ * scoped export/import instead of showing the Export/Import buttons. */+ backup?: SettingsBackupIntent;+};++function SettingsBackupRestore(props: Props) {+ const { backup } = props;const { t } = useTranslation();const fileInputRef = useRef<HTMLInputElement>(null);- const [mode, setMode] = useState<'export' | 'import'>(undefined);- const [importFile, setImportFile] = useState<File>(undefined);+ const [mode, setMode] = useState<'export' | 'import'>(backup?.mode);+ const [importFile, setImportFile] = useState<File>(backup?.importFile);+ const [scope, setScope] = useState<TransferSection>(backup?.scope);++ // Apply a (possibly new) intent if Settings is reopened with one.+ useEffect(() => {+ if (backup) {+ setMode(backup.mode);+ setImportFile(backup.importFile);+ setScope(backup.scope);+ }+ }, [backup]);const reset = () => {setMode(undefined);setImportFile(undefined);+ setScope(undefined);};function handleFileInputChange(selection: any) {@@ -48,49 +69,53 @@ function SettingsBackupRestore() {}return (- <List+ <Boxsx={{- overflowX: 'hidden',- overflowY: 'auto',+ display: 'flex',+ flexDirection: 'column',height: 'calc(100% - 18px)',+ overflow: 'hidden',}}>- <ListItem>- <ListItemText- primary={t('core:exportImportTitle')}- secondary={t('core:selectWhatToExport')}- />- <TsButton- data-tid="settingsExportTID"- startIcon={<ExportIcon />}- onClick={() => {- setImportFile(undefined);- setMode('export');- }}- >- {t('core:startExportButton')}- </TsButton>- <TsButton- data-tid="settingsImportTID"- startIcon={<ImportIcon />}- sx={{ marginLeft: AppConfig.defaultSpaceBetweenButtons }}- onClick={() => fileInputRef.current?.click()}- >- {t('core:startImportButton')}- </TsButton>- </ListItem>- {mode && (- <ListItem>- <div style={{ width: '100%' }}>- <ExportImportPanel- key={mode + (importFile ? importFile.name : '')}- mode={mode}- importFile={importFile}- onDone={reset}- onCancel={reset}+ {!mode && (+ <List sx={{ overflowX: 'hidden', overflowY: 'auto' }}>+ <ListItem>+ <ListItemText+ primary={t('core:exportImportTitle')}+ secondary={t('core:selectWhatToExport')}/>- </div>- </ListItem>+ <TsButton+ data-tid="settingsExportTID"+ startIcon={<ExportIcon />}+ onClick={() => {+ setImportFile(undefined);+ setMode('export');+ }}+ >+ {t('core:startExportButton')}+ </TsButton>+ <TsButton+ data-tid="settingsImportTID"+ startIcon={<ImportIcon />}+ sx={{ marginLeft: AppConfig.defaultSpaceBetweenButtons }}+ onClick={() => fileInputRef.current?.click()}+ >+ {t('core:startImportButton')}+ </TsButton>+ </ListItem>+ </List>+ )}+ {mode && (+ <Box sx={{ flex: 1, minHeight: 0 }}>+ <ExportImportPanel+ key={mode + (scope || '') + (importFile ? importFile.name : '')}+ mode={mode}+ scope={scope}+ importFile={importFile}+ onDone={reset}+ onCancel={reset}+ />+ </Box>)}<inputstyle={{ display: 'none' }}@@ -99,7 +124,7 @@ function SettingsBackupRestore() {type="file"onChange={handleFileInputChange}/>- </List>+ </Box>);}diff --git a/src/renderer/components/dialogs/hooks/SettingsDialogContextProvider.tsx b/src/renderer/components/dialogs/hooks/SettingsDialogContextProvider.tsxindex 3a7c76650..01159e98f 100644--- a/src/renderer/components/dialogs/hooks/SettingsDialogContextProvider.tsx+++ b/src/renderer/components/dialogs/hooks/SettingsDialogContextProvider.tsx@@ -25,10 +25,16 @@ import React, {} from 'react';import LoadingLazy from '-/components/LoadingLazy';import AppConfig from '-/AppConfig';-import { SettingsTab } from '-/components/dialogs/SettingsDialog';+import {+ SettingsBackupIntent,+ SettingsTab,+} from '-/components/dialogs/SettingsDialog';type SettingsDialogContextData = {- openSettingsDialog: (tab?: SettingsTab) => void;+ openSettingsDialog: (+ tab?: SettingsTab,+ backup?: SettingsBackupIntent,+ ) => void;closeSettingsDialog: () => void;};@@ -49,6 +55,7 @@ export const SettingsDialogContextProvider = ({children,}: SettingsDialogContextProviderProps) => {const currentTab = useRef<SettingsTab>(SettingsTab.General);+ const backupIntent = useRef<SettingsBackupIntent>(undefined);const open = useRef<boolean>(false);const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);@@ -69,8 +76,12 @@ export const SettingsDialogContextProvider = ({}}, []);- function openDialog(tab: SettingsTab = SettingsTab.General) {+ function openDialog(+ tab: SettingsTab = SettingsTab.General,+ backup?: SettingsBackupIntent,+ ) {currentTab.current = tab;+ backupIntent.current = backup;open.current = true;forceUpdate();}@@ -78,6 +89,7 @@ export const SettingsDialogContextProvider = ({function closeDialog() {open.current = false;currentTab.current = SettingsTab.General;+ backupIntent.current = undefined;forceUpdate();}@@ -101,6 +113,7 @@ export const SettingsDialogContextProvider = ({<SettingsDialogAsyncopen={open.current}tab={currentTab.current}+ backup={backupIntent.current}onClose={closeDialog}/>{children}diff --git a/src/renderer/components/menus/TagLibraryMenu.tsx b/src/renderer/components/menus/TagLibraryMenu.tsxindex 9b25a8a44..3e75521bf 100644--- a/src/renderer/components/menus/TagLibraryMenu.tsx+++ b/src/renderer/components/menus/TagLibraryMenu.tsx@@ -26,6 +26,8 @@ import {} from '-/components/CommonIcons';import { ProLabel, ProTooltip } from '-/components/HelperComponents';import TsMenuList from '-/components/TsMenuList';+import { SettingsTab } from '-/components/dialogs/SettingsDialog';+import { useSettingsDialogContext } from '-/components/dialogs/hooks/useSettingsDialogContext';import { useEditedTagLibraryContext } from '-/hooks/useEditedTagLibraryContext';import { Pro } from '-/pro';import { getSaveTagInLocation } from '-/reducers/settings';@@ -36,10 +38,9 @@ import ListItemText from '@mui/material/ListItemText';import Menu from '@mui/material/Menu';import MenuItem from '@mui/material/MenuItem';import Links from 'assets/links';-import { useRef, useState } from 'react';+import { useRef } from 'react';import { useTranslation } from 'react-i18next';import { useSelector } from 'react-redux';-import ExportImportDialog from '../dialogs/ExportImportDialog';interface Props {classes?: any;@@ -52,15 +53,17 @@ interface Props {function TagLibraryMenu(props: Props) {const { t } = useTranslation();const { refreshTagLibrary } = useEditedTagLibraryContext();+ const { openSettingsDialog } = useSettingsDialogContext();const saveTagInLocation: boolean = useSelector(getSaveTagInLocation);const fileInput = useRef<HTMLInputElement>(null);- const [isExportTagGroupsOpened, setExportTagGroupsOpened] = useState(false);- const [importFile, setImportFile] = useState<File>(undefined);function handleExportTagGroup() {props.onClose();- setExportTagGroupsOpened(true);+ openSettingsDialog(SettingsTab.BackupRestore, {+ mode: 'export',+ scope: 'tagGroups',+ });}function handleImportTagGroup() {@@ -72,30 +75,17 @@ function TagLibraryMenu(props: Props) {const target = selection.currentTarget;const file = target.files[0];if (file) {- setImportFile(file);+ openSettingsDialog(SettingsTab.BackupRestore, {+ mode: 'import',+ scope: 'tagGroups',+ importFile: file,+ });}target.value = null;}return (<Box sx={{ overflowY: 'hidden' }}>- {isExportTagGroupsOpened && (- <ExportImportDialog- open={isExportTagGroupsOpened}- mode="export"- scope="tagGroups"- onClose={() => setExportTagGroupsOpened(false)}- />- )}- {importFile && (- <ExportImportDialog- open={Boolean(importFile)}- mode="import"- scope="tagGroups"- importFile={importFile}- onClose={() => setImportFile(undefined)}- />- )}<Menu anchorEl={props.anchorEl} open={props.open} onClose={props.onClose}><TsMenuList><MenuItem