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

[WIP] Add privacy filter for mobile/small screens #4510

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions packages/desktop-client/src/components/FinancesApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useAccounts } from '../hooks/useAccounts';
import { useLocalPref } from '../hooks/useLocalPref';
import { useMetaThemeColor } from '../hooks/useMetaThemeColor';
import { useNavigate } from '../hooks/useNavigate';
import { useSyncedPref } from '../hooks/useSyncedPref';
import { useSelector, useDispatch } from '../redux';
import { theme } from '../style';
import { getIsOutdated, getLatestVersion } from '../util/versions';
Expand Down Expand Up @@ -84,12 +85,67 @@ function RouterBehaviors() {
return null;
}

function checkForShake(isNarrowWidth, isPrivacyEnabled, setPrivacyEnabledPref) {
if (!isNarrowWidth) {
return;
}

let lastX = null,
lastY = null,
lastZ = null;
const shakeThreshold = 15;
let timeout = 0;

const handler = event => {
const { x, y, z } = event.accelerationIncludingGravity;
timeout = Math.max(0, timeout - event.interval);

if (timeout === 0) {
if (!x || !y || !z) return;

if (lastX !== null && lastY !== null && lastZ !== null) {
const deltaX = Math.abs(lastX - x);
const deltaY = Math.abs(lastY - y);
const deltaZ = Math.abs(lastZ - z);

if (
deltaX > shakeThreshold ||
deltaY > shakeThreshold ||
deltaZ > shakeThreshold
) {
isPrivacyEnabled = !isPrivacyEnabled;
setPrivacyEnabledPref(String(isPrivacyEnabled));
timeout = 1000;
}
}
}

lastX = x;
lastY = y;
lastZ = z;
};

window.addEventListener('devicemotion', handler);
return () => window.removeEventListener('devicemotion', handler);
}

export function FinancesApp() {
const { isNarrowWidth } = useResponsive();
useMetaThemeColor(isNarrowWidth ? theme.mobileViewTheme : null);

const dispatch = useDispatch();
const { t } = useTranslation();
const [isPrivacyEnabledPref, setPrivacyEnabledPref] =
useSyncedPref('isPrivacyEnabled');
useEffect(
() =>
checkForShake(
isNarrowWidth,
isPrivacyEnabledPref === 'true',
setPrivacyEnabledPref,
),
[isNarrowWidth, isPrivacyEnabledPref],
);

const accounts = useAccounts();
const accountsLoaded = useSelector(state => state.queries.accountsLoaded);
Expand Down
1 change: 1 addition & 0 deletions packages/desktop-client/src/components/Modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ export function Modals() {
onAddCategoryGroup={options.onAddCategoryGroup}
onToggleHiddenCategories={options.onToggleHiddenCategories}
onSwitchBudgetFile={options.onSwitchBudgetFile}
onTogglePrivacyMode={options.onTogglePrivacyMode}
/>
);

Expand Down
5 changes: 0 additions & 5 deletions packages/desktop-client/src/components/PrivacyFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { css } from '@emotion/css';

import { usePrivacyMode } from '../hooks/usePrivacyMode';

import { useResponsive } from './responsive/ResponsiveProvider';

type ConditionalPrivacyFilterProps = {
children: ReactNode;
privacyFilter?: boolean | PrivacyFilterProps;
Expand Down Expand Up @@ -51,11 +49,8 @@ export function PrivacyFilter({
...props
}: PrivacyFilterProps) {
const privacyMode = usePrivacyMode();
// Limit mobile support for now.
const { isNarrowWidth } = useResponsive();
const activate =
privacyMode &&
!isNarrowWidth &&
(!activationFilters ||
activationFilters.every(value =>
typeof value === 'boolean' ? value : value(),
Expand Down
5 changes: 4 additions & 1 deletion packages/desktop-client/src/components/Titlebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type PrivacyButtonProps = {
};

function PrivacyButton({ style }: PrivacyButtonProps) {
const { t } = useTranslation();
const [isPrivacyEnabledPref, setPrivacyEnabledPref] =
useSyncedPref('isPrivacyEnabled');
const isPrivacyEnabled = String(isPrivacyEnabledPref) === 'true';
Expand All @@ -91,7 +92,9 @@ function PrivacyButton({ style }: PrivacyButtonProps) {
return (
<Button
variant="bare"
aria-label={`${isPrivacyEnabled ? 'Disable' : 'Enable'} privacy mode`}
aria-label={
isPrivacyEnabled ? t('Disable privacy mode') : t('Enable privacy mode')
}
onPress={() => setPrivacyEnabledPref(String(!isPrivacyEnabled))}
style={style}
>
Expand Down
10 changes: 10 additions & 0 deletions packages/desktop-client/src/components/mobile/budget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,14 @@ export function Budget() {
[dispatch, onSaveNotes],
);

const [isPrivacyEnabled, setPrivacyEnabledPref] =
useSyncedPref('isPrivacyEnabled');

const onTogglePrivacyMode = useCallback(() => {
setPrivacyEnabledPref(String(isPrivacyEnabled !== 'true'));
dispatch(collapseModals('budget-page-menu'));
}, [dispatch, isPrivacyEnabled, setPrivacyEnabledPref]);

const onSwitchBudgetFile = useCallback(() => {
dispatch(pushModal('budget-list'));
}, [dispatch]);
Expand All @@ -462,13 +470,15 @@ export function Budget() {
onAddCategoryGroup: onOpenNewCategoryGroupModal,
onToggleHiddenCategories,
onSwitchBudgetFile,
onTogglePrivacyMode,
}),
);
}, [
dispatch,
onOpenNewCategoryGroupModal,
onSwitchBudgetFile,
onToggleHiddenCategories,
onTogglePrivacyMode,
]);

if (!categoryGroups || !initialized) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
import { useSelector } from '../../../redux';
import { theme } from '../../../style';
import { makeAmountFullStyle } from '../../budget/util';
import { PrivacyFilter } from '../../PrivacyFilter';

import { lookupName, Status } from './TransactionEdit';

Expand Down Expand Up @@ -278,14 +279,16 @@ export function TransactionListItem({
)}
</View>
<View style={{ justifyContent: 'center' }}>
<Text
style={{
...textStyle,
...makeAmountFullStyle(amount),
}}
>
{integerToCurrency(amount)}
</Text>
<PrivacyFilter>
<Text
style={{
...textStyle,
...makeAmountFullStyle(amount),
}}
>
{integerToCurrency(amount)}
</Text>
</PrivacyFilter>
</View>
</View>
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Menu } from '@actual-app/components/menu';
import { styles } from '@actual-app/components/styles';

import { useLocalPref } from '../../hooks/useLocalPref';
import { useSyncedPref } from '../../hooks/useSyncedPref';
import { theme } from '../../style';
import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';

Expand All @@ -17,6 +18,7 @@ export function BudgetPageMenuModal({
onAddCategoryGroup,
onToggleHiddenCategories,
onSwitchBudgetFile,
onTogglePrivacyMode,
}: BudgetPageMenuModalProps) {
const defaultMenuItemStyle: CSSProperties = {
...styles.mobileMenuItem,
Expand All @@ -38,6 +40,7 @@ export function BudgetPageMenuModal({
onAddCategoryGroup={onAddCategoryGroup}
onToggleHiddenCategories={onToggleHiddenCategories}
onSwitchBudgetFile={onSwitchBudgetFile}
onTogglePrivacyMode={onTogglePrivacyMode}
/>
</>
)}
Expand All @@ -52,15 +55,18 @@ type BudgetPageMenuProps = Omit<
onAddCategoryGroup: () => void;
onToggleHiddenCategories: () => void;
onSwitchBudgetFile: () => void;
onTogglePrivacyMode: () => void;
};

function BudgetPageMenu({
onAddCategoryGroup,
onToggleHiddenCategories,
onSwitchBudgetFile,
onTogglePrivacyMode,
...props
}: BudgetPageMenuProps) {
const [showHiddenCategories] = useLocalPref('budget.showHiddenCategories');
const [isPrivacyEnabled] = useSyncedPref('isPrivacyEnabled');

const onMenuSelect = (name: string) => {
switch (name) {
Expand All @@ -76,6 +82,9 @@ function BudgetPageMenu({
case 'switch-budget-file':
onSwitchBudgetFile?.();
break;
case 'toggle-privacy-filter':
onTogglePrivacyMode?.();
break;
default:
throw new Error(`Unrecognized menu item: ${name}`);
}
Expand All @@ -95,6 +104,13 @@ function BudgetPageMenu({
name: 'toggle-hidden-categories',
text: `${!showHiddenCategories ? t('Show hidden categories') : t('Hide hidden categories')}`,
},
{
name: 'toggle-privacy-filter',
text:
isPrivacyEnabled === 'true'
? t('Disable privacy mode')
: t('Enable privacy mode'),
},
{
name: 'switch-budget-file',
text: t('Switch budget file'),
Expand Down
1 change: 1 addition & 0 deletions packages/loot-core/src/client/state-types/modals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ type FinanceModals = {
onAddCategoryGroup: () => void;
onToggleHiddenCategories: () => void;
onSwitchBudgetFile: () => void;
onTogglePrivacyMode: () => void;
};
'envelope-budget-month-menu': {
month: string;
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/4510.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [rugulous]
---

Enable the privacy filter option on mobile/small screen devices