Skip to content

A local-first personal finance app

Set theme-color at App level instead of per page (#3521)

Joel Jeremy Marquez92980ab55bbd
diff --git a/packages/desktop-client/src/components/FinancesApp.tsx b/packages/desktop-client/src/components/FinancesApp.tsx
index c6d71930ef..b585d5d30e 100644
--- a/packages/desktop-client/src/components/FinancesApp.tsx
+++ b/packages/desktop-client/src/components/FinancesApp.tsx
@@ -16,6 +16,7 @@ import * as undo from 'loot-core/src/platform/client/undo';
import { useAccounts } from '../hooks/useAccounts';
import { useLocalPref } from '../hooks/useLocalPref';
+import { useMetaThemeColor } from '../hooks/useMetaThemeColor';
import { useNavigate } from '../hooks/useNavigate';
import { useResponsive } from '../ResponsiveProvider';
import { theme } from '../style';
@@ -76,6 +77,9 @@ function RouterBehaviors() {
}
export function FinancesApp() {
+ const { isNarrowWidth } = useResponsive();
+ useMetaThemeColor(isNarrowWidth ? theme.mobileViewTheme : null);
+
const dispatch = useDispatch();
const { t } = useTranslation();
diff --git a/packages/desktop-client/src/components/manager/ConfigServer.tsx b/packages/desktop-client/src/components/manager/ConfigServer.tsx
index fcc6193216..d8c1727e04 100644
--- a/packages/desktop-client/src/components/manager/ConfigServer.tsx
+++ b/packages/desktop-client/src/components/manager/ConfigServer.tsx
@@ -10,7 +10,6 @@ import {
import { useActions } from '../../hooks/useActions';
import { useGlobalPref } from '../../hooks/useGlobalPref';
import { useNavigate } from '../../hooks/useNavigate';
-import { useSetThemeColor } from '../../hooks/useSetThemeColor';
import { theme } from '../../style';
import { Button, ButtonWithLoading } from '../common/Button2';
import { BigInput } from '../common/Input';
@@ -22,7 +21,6 @@ import { useServerURL, useSetServerURL } from '../ServerContext';
import { Title } from './subscribe/common';
export function ConfigServer() {
- useSetThemeColor(theme.mobileConfigServerViewTheme);
const { t } = useTranslation();
const { createBudget, signOut, loggedIn } = useActions();
const navigate = useNavigate();
diff --git a/packages/desktop-client/src/components/manager/ManagementApp.jsx b/packages/desktop-client/src/components/manager/ManagementApp.jsx
index 4c17797af4..b9550088c6 100644
--- a/packages/desktop-client/src/components/manager/ManagementApp.jsx
+++ b/packages/desktop-client/src/components/manager/ManagementApp.jsx
@@ -8,6 +8,8 @@ import {
setAppState,
} from 'loot-core/client/actions';
+import { useMetaThemeColor } from '../../hooks/useMetaThemeColor';
+import { useResponsive } from '../../ResponsiveProvider';
import { theme } from '../../style';
import { tokens } from '../../tokens';
import { AppBackground } from '../AppBackground';
@@ -52,6 +54,9 @@ function Version() {
}
export function ManagementApp() {
+ const { isNarrowWidth } = useResponsive();
+ useMetaThemeColor(isNarrowWidth ? theme.mobileConfigServerViewTheme : null);
+
const files = useSelector(state => state.budgets.allFiles);
const isLoading = useSelector(state => state.app.loadingText !== null);
const userData = useSelector(state => state.user.data);
diff --git a/packages/desktop-client/src/components/mobile/accounts/Account.tsx b/packages/desktop-client/src/components/mobile/accounts/Account.tsx
index 47c2beb950..7940ad6222 100644
--- a/packages/desktop-client/src/components/mobile/accounts/Account.tsx
+++ b/packages/desktop-client/src/components/mobile/accounts/Account.tsx
@@ -2,9 +2,7 @@ import React from 'react';
import { useParams } from 'react-router-dom';
import { useAccount } from '../../../hooks/useAccount';
-import { useSetThemeColor } from '../../../hooks/useSetThemeColor';
import { useSyncedPref } from '../../../hooks/useSyncedPref';
-import { theme } from '../../../style';
import { AccountTransactions } from './AccountTransactions';
@@ -15,8 +13,6 @@ export function Account() {
const { id: accountId } = useParams();
- useSetThemeColor(theme.mobileViewTheme);
-
const account = useAccount(accountId!);
return (
diff --git a/packages/desktop-client/src/components/mobile/accounts/Accounts.jsx b/packages/desktop-client/src/components/mobile/accounts/Accounts.jsx
index 56bde3b833..6084b3713d 100644
--- a/packages/desktop-client/src/components/mobile/accounts/Accounts.jsx
+++ b/packages/desktop-client/src/components/mobile/accounts/Accounts.jsx
@@ -7,7 +7,6 @@ import * as queries from 'loot-core/src/client/queries';
import { useAccounts } from '../../../hooks/useAccounts';
import { useFailedAccounts } from '../../../hooks/useFailedAccounts';
import { useNavigate } from '../../../hooks/useNavigate';
-import { useSetThemeColor } from '../../../hooks/useSetThemeColor';
import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { SvgAdd } from '../../../icons/v1';
import { theme, styles } from '../../../style';
@@ -249,8 +248,6 @@ export function Accounts() {
dispatch(syncAndDownload());
};
- useSetThemeColor(theme.mobileViewTheme);
-
return (
<View style={{ flex: 1 }}>
<AccountList
diff --git a/packages/desktop-client/src/components/mobile/budget/Category.tsx b/packages/desktop-client/src/components/mobile/budget/Category.tsx
index 768c3281c2..2df60c545b 100644
--- a/packages/desktop-client/src/components/mobile/budget/Category.tsx
+++ b/packages/desktop-client/src/components/mobile/budget/Category.tsx
@@ -4,14 +4,11 @@ import { useParams, useSearchParams } from 'react-router-dom';
import * as monthUtils from 'loot-core/src/shared/months';
import { useCategories } from '../../../hooks/useCategories';
-import { useSetThemeColor } from '../../../hooks/useSetThemeColor';
import { useSyncedPref } from '../../../hooks/useSyncedPref';
-import { theme } from '../../../style';
import { CategoryTransactions } from './CategoryTransactions';
export function Category() {
- useSetThemeColor(theme.mobileViewTheme);
const [_numberFormat] = useSyncedPref('numberFormat');
const numberFormat = _numberFormat || 'comma-dot';
const [hideFraction] = useSyncedPref('hideFraction');
diff --git a/packages/desktop-client/src/components/mobile/budget/index.tsx b/packages/desktop-client/src/components/mobile/budget/index.tsx
index 11ccb144b0..20d233753e 100644
--- a/packages/desktop-client/src/components/mobile/budget/index.tsx
+++ b/packages/desktop-client/src/components/mobile/budget/index.tsx
@@ -23,7 +23,6 @@ import * as monthUtils from 'loot-core/src/shared/months';
import { useCategories } from '../../../hooks/useCategories';
import { useLocalPref } from '../../../hooks/useLocalPref';
-import { useSetThemeColor } from '../../../hooks/useSetThemeColor';
import { useSyncedPref } from '../../../hooks/useSyncedPref';
import { AnimatedLoading } from '../../../icons/AnimatedLoading';
import { theme } from '../../../style';
@@ -39,8 +38,6 @@ function isBudgetType(input?: string): input is 'rollover' | 'report' {
}
export function Budget() {
- useSetThemeColor(theme.mobileViewTheme);
-
const { list: categories, grouped: categoryGroups } = useCategories();
const [budgetTypePref] = useSyncedPref('budgetType');
const budgetType = isBudgetType(budgetTypePref) ? budgetTypePref : 'rollover';
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx
index b21dfbd3b4..a08bf42a38 100644
--- a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx
+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx
@@ -45,7 +45,6 @@ import { useCategories } from '../../../hooks/useCategories';
import { useDateFormat } from '../../../hooks/useDateFormat';
import { useNavigate } from '../../../hooks/useNavigate';
import { usePayees } from '../../../hooks/usePayees';
-import { useSetThemeColor } from '../../../hooks/useSetThemeColor';
import {
SingleActiveEditFormProvider,
useSingleActiveEditForm,
@@ -1015,7 +1014,6 @@ function TransactionEditUnconnected({
const [fetchedTransactions, setFetchedTransactions] = useState([]);
const adding = useRef(false);
const deleted = useRef(false);
- useSetThemeColor(theme.mobileViewTheme);
useEffect(() => {
async function fetchTransaction() {
diff --git a/packages/desktop-client/src/components/settings/index.tsx b/packages/desktop-client/src/components/settings/index.tsx
index 61c1b19145..e2439ab98a 100644
--- a/packages/desktop-client/src/components/settings/index.tsx
+++ b/packages/desktop-client/src/components/settings/index.tsx
@@ -10,7 +10,6 @@ import { useFeatureFlag } from '../../hooks/useFeatureFlag';
import { useGlobalPref } from '../../hooks/useGlobalPref';
import { useLatestVersion, useIsOutdated } from '../../hooks/useLatestVersion';
import { useMetadataPref } from '../../hooks/useMetadataPref';
-import { useSetThemeColor } from '../../hooks/useSetThemeColor';
import { useResponsive } from '../../ResponsiveProvider';
import { theme } from '../../style';
import { tokens } from '../../tokens';
@@ -139,7 +138,6 @@ export function Settings() {
const { isNarrowWidth } = useResponsive();
- useSetThemeColor(theme.mobileViewTheme);
return (
<Page
header="Settings"
diff --git a/packages/desktop-client/src/hooks/useSetThemeColor.ts b/packages/desktop-client/src/hooks/useMetaThemeColor.ts
similarity index 81%
rename from packages/desktop-client/src/hooks/useSetThemeColor.ts
rename to packages/desktop-client/src/hooks/useMetaThemeColor.ts
index 17bcc3c838..1ce2a49e21 100644
--- a/packages/desktop-client/src/hooks/useSetThemeColor.ts
+++ b/packages/desktop-client/src/hooks/useMetaThemeColor.ts
@@ -3,9 +3,11 @@ import { useEffect } from 'react';
const VAR_STRING_REGEX = /^var\((--.*)\)$/;
-export function useSetThemeColor(color: string) {
+export function useMetaThemeColor(color?: string) {
useEffect(() => {
- setThemeColor(getPropertyValueFromVarString(color));
+ if (color) {
+ setThemeColor(getPropertyValueFromVarString(color));
+ }
}, [color]);
}
diff --git a/upcoming-release-notes/3521.md b/upcoming-release-notes/3521.md
new file mode 100644
index 0000000000..d309047ee2
--- /dev/null
+++ b/upcoming-release-notes/3521.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [joel-jeremy]
+---
+
+Cleanup: Set theme-color at App level instead of per page