Skip to content

A local-first personal finance app

Fix: update toolbar server status on sync (#4075)

Pierre Payetcdbf3e06c197
diff --git a/packages/desktop-client/src/components/LoggedInUser.tsx b/packages/desktop-client/src/components/LoggedInUser.tsx
index 0e715c5a10..73dc30557a 100644
--- a/packages/desktop-client/src/components/LoggedInUser.tsx
+++ b/packages/desktop-client/src/components/LoggedInUser.tsx
@@ -3,6 +3,7 @@ import { Trans, useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';
import { closeBudget, getUserData, signOut } from 'loot-core/client/actions';
+import { listen } from 'loot-core/src/platform/client/fetch';
import { type RemoteFile, type SyncedLocalFile } from 'loot-core/types/file';
import { type TransObjectLiteral } from 'loot-core/types/util';
@@ -52,14 +53,41 @@ export function LoggedInUser({
const currentFile = remoteFiles.find(f => f.cloudFileId === cloudFileId);
const hasSyncedPrefs = useSelector(state => state.prefs.synced);
- useEffect(() => {
- async function init() {
+ const initializeUserData = async () => {
+ try {
await dispatch(getUserData());
+ } catch (error) {
+ console.error('Failed to initialize user data:', error);
+ } finally {
+ setLoading(false);
}
+ };
- init().then(() => setLoading(false));
+ useEffect(() => {
+ initializeUserData();
}, []);
+ useEffect(() => {
+ return listen('sync-event', ({ type }) => {
+ if (type === 'start') {
+ setLoading(true);
+
+ return;
+ }
+
+ const shouldReinitialize =
+ userData &&
+ ((type === 'success' && userData.offline) ||
+ (type === 'error' && !userData.offline));
+
+ if (shouldReinitialize) {
+ initializeUserData();
+ } else {
+ setLoading(false);
+ }
+ });
+ }, [userData]);
+
async function onCloseBudget() {
await dispatch(closeBudget());
}
diff --git a/upcoming-release-notes/4075.md b/upcoming-release-notes/4075.md
new file mode 100644
index 0000000000..3fa781252a
--- /dev/null
+++ b/upcoming-release-notes/4075.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [p-payet]
+---
+
+Fix to ensure that the toolbar's server status updates correctly during synchronization