feature: store the last used "Add Torrents" tab

Bug: Flood-UI/flood#329
This commit is contained in:
Jesse Chan
2020-11-14 00:28:50 +08:00
parent 5675bad221
commit 9038177630
7 changed files with 38 additions and 7 deletions

View File

@@ -18,10 +18,23 @@ interface ModalProps {
inverse?: boolean;
actions?: Array<ModalAction>;
tabs?: Record<string, Tab>;
initialTabId?: string;
}
const Modal: FC<ModalProps> = (props: ModalProps) => {
const {alignment, size, orientation, tabsInBody, inverse, className, content, heading, tabs, actions} = props;
const {
alignment,
size,
orientation,
tabsInBody,
inverse,
initialTabId,
className,
content,
heading,
tabs,
actions,
} = props;
const contentWrapperClasses = classnames(
'modal__content__wrapper',
@@ -47,7 +60,7 @@ const Modal: FC<ModalProps> = (props: ModalProps) => {
let headerTabs;
if (tabs) {
const [activeTabId, setActiveTabId] = useState(Object.keys(tabs)[0]);
const [activeTabId, setActiveTabId] = useState(initialTabId ?? Object.keys(tabs)[0]);
const activeTab = tabs[activeTabId];
const contentClasses = classnames('modal__content', activeTab.modalContentClasses);
@@ -114,6 +127,7 @@ Modal.defaultProps = {
content: undefined,
actions: undefined,
tabs: undefined,
initialTabId: undefined,
};
export default Modal;

View File

@@ -120,7 +120,7 @@ const AddTorrentsByCreation: FC = () => {
UIStore.dismissModal();
});
saveAddTorrentsUserPreferences({start: formData.start, destination: formData.sourcePath});
saveAddTorrentsUserPreferences({start: formData.start, destination: formData.sourcePath, tab: 'by-creation'});
}}
isAddingTorrents={isCreatingTorrents}
/>

View File

@@ -84,7 +84,7 @@ const AddTorrentsByFile: FC = () => {
UIStore.dismissModal();
});
saveAddTorrentsUserPreferences({start, destination});
saveAddTorrentsUserPreferences({start, destination, tab: 'by-file'});
}}
isAddingTorrents={isAddingTorrents}
/>

View File

@@ -105,7 +105,7 @@ const AddTorrentsByURL: FC = () => {
UIStore.dismissModal();
});
saveAddTorrentsUserPreferences({start: formData.start, destination: formData.destination});
saveAddTorrentsUserPreferences({start: formData.start, destination: formData.destination, tab: 'by-url'});
}}
isAddingTorrents={isAddingTorrents}
/>

View File

@@ -1,10 +1,11 @@
import {FC} from 'react';
import {useIntl} from 'react-intl';
import AddTorrentsByCreation from './AddTorrentsByCreation';
import AddTorrentsByFile from './AddTorrentsByFile';
import AddTorrentsByURL from './AddTorrentsByURL';
import Modal from '../Modal';
import AddTorrentsByCreation from './AddTorrentsByCreation';
import SettingStore from '../../../stores/SettingStore';
const AddTorrentsModal: FC = () => {
const intl = useIntl();
@@ -36,6 +37,7 @@ const AddTorrentsModal: FC = () => {
id: 'torrents.add.heading',
})}
tabs={tabs}
initialTabId={SettingStore.floodSettings.UITorrentsAddTab}
/>
);
};

View File

@@ -2,7 +2,15 @@ import type {FloodSettings} from '@shared/types/FloodSettings';
import SettingActions from '../actions/SettingActions';
export const saveAddTorrentsUserPreferences = ({start, destination}: {start?: boolean; destination?: string}) => {
export const saveAddTorrentsUserPreferences = ({
start,
destination,
tab,
}: {
start?: FloodSettings['startTorrentsOnLoad'];
destination?: FloodSettings['torrentDestination'];
tab?: FloodSettings['UITorrentsAddTab'];
}) => {
const changedSettings: Partial<FloodSettings> = {};
if (start != null) {
@@ -13,6 +21,10 @@ export const saveAddTorrentsUserPreferences = ({start, destination}: {start?: bo
changedSettings.torrentDestination = destination;
}
if (tab != null) {
changedSettings.UITorrentsAddTab = tab;
}
SettingActions.saveSettings(changedSettings);
};

View File

@@ -32,6 +32,9 @@ export interface FloodSettings {
// Last used download destination
torrentDestination?: string;
// Last used "Add Torrents" tab
UITorrentsAddTab?: 'by-url' | 'by-file' | 'by-creation';
}
export type FloodSetting = keyof FloodSettings;