Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:electron: Move file settings to the file management area #3584

Merged
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f5c2f8e
move settings to the file management area
MikesGlitch Sep 24, 2024
212a79e
more settings
MikesGlitch Sep 25, 2024
1015428
giving users option to automatically move files when changing dir
MikesGlitch Sep 25, 2024
847fbde
trueee
MikesGlitch Sep 25, 2024
2d50348
updates
MikesGlitch Sep 26, 2024
7b7f26b
does this fix the type issue
MikesGlitch Sep 26, 2024
2470bf8
weird
MikesGlitch Sep 26, 2024
f030f06
translating
MikesGlitch Sep 26, 2024
ed17ca1
release notes
MikesGlitch Sep 26, 2024
f02837c
release notes
MikesGlitch Sep 26, 2024
f964dcd
Merge branch 'master' of https://github.com/MikesGlitch/actual into e…
MikesGlitch Sep 26, 2024
f66d481
a bit extra safety
MikesGlitch Sep 26, 2024
02388a2
updating wording
MikesGlitch Sep 26, 2024
8b001eb
parameterising backup params
MikesGlitch Sep 27, 2024
4cbbde1
text update
MikesGlitch Sep 27, 2024
3e18430
parameterise vals
MikesGlitch Sep 27, 2024
cc98557
Merge branch 'master' into electron/file-management-settings
MikesGlitch Sep 27, 2024
0eec5dc
add a notification to ensure the user knows the dir has changed
MikesGlitch Sep 29, 2024
8ec29e2
Merge branch 'actualbudget:master' into electron/file-management-sett…
MikesGlitch Oct 3, 2024
9365eb2
merge
MikesGlitch Oct 4, 2024
e206d9e
Merge branch 'master' into electron/file-management-settings
MikesGlitch Oct 4, 2024
9856b40
Merge branch 'master' into electron/file-management-settings
MikesGlitch Oct 4, 2024
ca7e59b
pencil icon to save real estate
MikesGlitch Oct 6, 2024
a9668f9
ordering
MikesGlitch Oct 6, 2024
36ad9db
Rename 3500.md to 3584.md
MikesGlitch Oct 6, 2024
82113f7
Merge branch 'master' into electron/file-management-settings
MikesGlitch Oct 6, 2024
eb80512
Update packages/desktop-client/src/components/manager/BudgetList.tsx
MikesGlitch Oct 6, 2024
11f9b09
conflict
MikesGlitch Oct 6, 2024
39e68c7
Merge branch 'master' into electron/file-management-settings
MikesGlitch Oct 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/desktop-client/src/browser-preload.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ global.Actual = {
setTheme: theme => {
window.__actionsForMenu.saveGlobalPrefs({ theme });
},

moveBudgetDirectory: () => {},
};

function inputFocused(e) {
Expand Down
12 changes: 12 additions & 0 deletions packages/desktop-client/src/components/Modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ import { HoldBufferModal } from './modals/HoldBufferModal';
import { ImportTransactionsModal } from './modals/ImportTransactionsModal';
import { KeyboardShortcutModal } from './modals/KeyboardShortcutModal';
import { LoadBackupModal } from './modals/LoadBackupModal';
import { ConfirmChangeDocumentDirModal } from './modals/manager/ConfirmChangeDocumentDir';
import { DeleteFileModal } from './modals/manager/DeleteFileModal';
import { FilesSettingsModal } from './modals/manager/FilesSettingsModal';
import { ImportActualModal } from './modals/manager/ImportActualModal';
import { ImportModal } from './modals/manager/ImportModal';
import { ImportYNAB4Modal } from './modals/manager/ImportYNAB4Modal';
Expand Down Expand Up @@ -573,6 +575,16 @@ export function Modals() {
return <DeleteFileModal key={name} file={options.file} />;
case 'import':
return <ImportModal key={name} />;
case 'files-settings':
return <FilesSettingsModal key={name} />;
case 'confirm-change-document-dir':
return (
<ConfirmChangeDocumentDirModal
key={name}
currentBudgetDirectory={options.currentBudgetDirectory}
newDirectory={options.newDirectory}
/>
);
case 'import-ynab4':
return <ImportYNAB4Modal key={name} />;
case 'import-ynab5':
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export const Information = ({ style, children }: ScopedAlertProps) => {
color={theme.pageTextLight}
backgroundColor="transparent"
style={{
...style,
boxShadow: 'none',
padding: 5,
...style,
MikesGlitch marked this conversation as resolved.
Show resolved Hide resolved
}}
>
{children}
Expand Down
40 changes: 38 additions & 2 deletions packages/desktop-client/src/components/manager/BudgetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
loadBudget,
pushModal,
} from 'loot-core/client/actions';
import { isNonProductionEnvironment } from 'loot-core/src/shared/environment';
import {
isElectron,
isNonProductionEnvironment,
} from 'loot-core/src/shared/environment';
import {
type File,
type LocalFile,
Expand All @@ -26,6 +29,7 @@ import { AnimatedLoading } from '../../icons/AnimatedLoading';
import {
SvgCloudCheck,
SvgCloudDownload,
SvgCog,
SvgDotsHorizontalTriple,
SvgFileDouble,
} from '../../icons/v1';
Expand Down Expand Up @@ -324,12 +328,33 @@ function RefreshButton({
);
}

function SettingsButton({ onOpenSettings }: { onOpenSettings: () => void }) {
const { t } = useTranslation();

return (
<View>
<Button
variant="bare"
aria-label={t('Settings')}
onPress={() => {
onOpenSettings();
}}
style={{ padding: 10 }}
>
<SvgCog style={{ width: 18, height: 18 }} />
</Button>
</View>
);
}

MikesGlitch marked this conversation as resolved.
Show resolved Hide resolved
function BudgetListHeader({
quickSwitchMode,
onRefresh,
onOpenSettings,
}: {
quickSwitchMode: boolean;
onRefresh: () => void;
onOpenSettings: () => void;
}) {
return (
<View
Expand All @@ -346,7 +371,17 @@ function BudgetListHeader({
>
<Trans>Files</Trans>
</Text>
{!quickSwitchMode && <RefreshButton onRefresh={onRefresh} />}
{!quickSwitchMode && (
<View
style={{
flexDirection: 'row',
gap: '0.2rem',
}}
>
<RefreshButton onRefresh={onRefresh} />
{isElectron() && <SettingsButton onOpenSettings={onOpenSettings} />}
</View>
)}
</View>
);
}
Expand Down Expand Up @@ -425,6 +460,7 @@ export function BudgetList({ showHeader = true, quickSwitchMode = false }) {
<BudgetListHeader
quickSwitchMode={quickSwitchMode}
onRefresh={refresh}
onOpenSettings={() => dispatch(pushModal('files-settings'))}
/>
)}
<BudgetFiles
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
import React, { useCallback, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';

import { addNotification } from 'loot-core/client/actions';

import { useGlobalPref } from '../../../hooks/useGlobalPref';
import { theme, styles } from '../../../style';
import { Information } from '../../alerts';
import { Button, ButtonWithLoading } from '../../common/Button2';
import { Modal, ModalCloseButton, ModalHeader } from '../../common/Modal';
import { Text } from '../../common/Text';
import { View } from '../../common/View';
import { Checkbox } from '../../forms';

function DirectoryDisplay({ directory }: { directory: string }) {
return (
<View style={{ flexDirection: 'row', gap: '0.5rem', width: '100%' }}>
<Text
title={directory}
style={{
backgroundColor: theme.pageBackground,
padding: '5px 10px',
borderRadius: 4,
overflow: 'auto',
whiteSpace: 'nowrap',
width: '100%',
...styles.horizontalScrollbar,
'::-webkit-scrollbar': {
height: '8px',
},
}}
MikesGlitch marked this conversation as resolved.
Show resolved Hide resolved
>
{directory}
</Text>
</View>
);
}

export function ConfirmChangeDocumentDirModal({
currentBudgetDirectory,
newDirectory,
}: {
currentBudgetDirectory: string;
newDirectory: string;
}) {
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
const [moveFiles, setMoveFiles] = useState(false);
const { t } = useTranslation();
const dispatch = useDispatch();

const restartElectronServer = useCallback(() => {
globalThis.window.Actual?.restartElectronServer();
}, []);

const [_documentDir, setDocumentDirPref] = useGlobalPref(
'documentDir',
restartElectronServer,
);

const moveDirectory = async (close: () => void) => {
setError('');
setLoading(true);
try {
if (moveFiles) {
await globalThis.window.Actual?.moveBudgetDirectory(
currentBudgetDirectory,
newDirectory,
);
}

setDocumentDirPref(newDirectory);

dispatch(
addNotification({
type: 'message',
message: t('Actual’s data directory successfully changed.'),
}),
);
close();
} catch (error) {
console.error('There was an error changing your directory', error);
setError(
t(
'There was an error changing your directory, please check the directory and try again.',
),
);
} finally {
setLoading(false);
}
};

return (
<Modal name="confirm-change-document-dir">
{({ state: { close } }) => (
<>
<ModalHeader
title={t('Are you sure?')}
rightContent={<ModalCloseButton onPress={close} />}
/>
<View
style={{
padding: 15,
gap: 15,
paddingTop: 0,
paddingBottom: 25,
maxWidth: 550,
lineHeight: '1.5em',
}}
>
<View
style={{
gap: 15,
backgroundColor: theme.pillBackground,
alignSelf: 'flex-start',
alignItems: 'flex-start',
padding: 15,
borderRadius: 4,
border: '1px solid ' + theme.pillBorderDark,
width: '100%',
}}
>
<Text>
<Trans>
You are about to change Actual’s data directory from:
</Trans>
</Text>
<DirectoryDisplay directory={currentBudgetDirectory} />
<Text>
<Trans>To:</Trans>
</Text>
<DirectoryDisplay directory={newDirectory} />
<label
htmlFor="moveFiles"
style={{
userSelect: 'none',
flexDirection: 'row',
gap: '0.5rem',
display: 'flex',
alignItems: 'center',
}}
>
<Checkbox
id="moveFiles"
name="moveFiles"
checked={moveFiles}
onChange={() => setMoveFiles(!moveFiles)}
/>
<Trans>Move files to new directory</Trans>
</label>
{moveFiles && (
<Information style={{ color: theme.warningText, padding: 0 }}>
<Trans>
Files in the destination folder with the same name will be
overwritten.
</Trans>
</Information>
)}

{!moveFiles && (
<Information style={{ padding: 0 }}>
<Trans>
Your files won’t be moved. You can manually move them to the
folder.
</Trans>
</Information>
)}

{error && <Text style={{ color: theme.errorText }}>{error}</Text>}
</View>
<View
style={{
gap: '1rem',
flexDirection: 'row',
justifyContent: 'center',
}}
>
<Button
variant="normal"
style={{
padding: '10px 30px',
fontSize: 14,
alignSelf: 'center',
}}
onPress={close}
>
<Trans>Cancel</Trans>
</Button>
<ButtonWithLoading
variant="primary"
isLoading={loading}
style={{
padding: '10px 30px',
fontSize: 14,
alignSelf: 'center',
}}
onPress={() => moveDirectory(close)}
>
<Trans>Change Directory</Trans>
</ButtonWithLoading>
</View>
</View>
</>
)}
</Modal>
);
}
Loading
Loading