Skip to content

Commit

Permalink
🐛 fix uncategorized transaction banner flashing on load (#2273)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatissJanis authored Jan 23, 2024
1 parent 5d28bc0 commit 9dfd6ce
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 23 deletions.
64 changes: 41 additions & 23 deletions packages/desktop-client/src/components/Titlebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import React, {
createContext,
useState,
Expand Down Expand Up @@ -61,7 +60,14 @@ export type TitlebarContextValue = {
subscribe: (listener: Listener) => () => void;
};

export const TitlebarContext = createContext<TitlebarContextValue>(null);
export const TitlebarContext = createContext<TitlebarContextValue>({
sendEvent() {
throw new Error('TitlebarContext not initialized');
},
subscribe() {
throw new Error('TitlebarContext not initialized');
},
});

type TitlebarProviderProps = {
children?: ReactNode;
Expand All @@ -88,26 +94,32 @@ export function TitlebarProvider({ children }: TitlebarProviderProps) {
}

function UncategorizedButton() {
const count = useSheetValue(queries.uncategorizedCount());
const count: number | null = useSheetValue(queries.uncategorizedCount());
if (count === null || count <= 0) {
return null;
}

return (
count !== 0 && (
<Link
variant="button"
type="bare"
to="/accounts/uncategorized"
style={{
color: theme.errorText,
}}
>
{count} uncategorized {count === 1 ? 'transaction' : 'transactions'}
</Link>
)
<Link
variant="button"
type="bare"
to="/accounts/uncategorized"
style={{
color: theme.errorText,
}}
>
{count} uncategorized {count === 1 ? 'transaction' : 'transactions'}
</Link>
);
}

function PrivacyButton({ style }) {
type PrivacyButtonProps = {
style?: CSSProperties;
};

function PrivacyButton({ style }: PrivacyButtonProps) {
const isPrivacyEnabled = useSelector(
state => state.prefs.local.isPrivacyEnabled,
state => state.prefs.local?.isPrivacyEnabled,
);
const { savePrefs } = useActions();

Expand All @@ -134,11 +146,13 @@ type SyncButtonProps = {
isMobile?: boolean;
};
function SyncButton({ style, isMobile = false }: SyncButtonProps) {
const cloudFileId = useSelector(state => state.prefs.local.cloudFileId);
const cloudFileId = useSelector(state => state.prefs.local?.cloudFileId);
const { sync } = useActions();

const [syncing, setSyncing] = useState(false);
const [syncState, setSyncState] = useState(null);
const [syncState, setSyncState] = useState<
null | 'offline' | 'local' | 'disabled' | 'error'
>(null);

useEffect(() => {
const unlisten = listen('sync-event', ({ type, subtype, syncDisabled }) => {
Expand Down Expand Up @@ -272,8 +286,8 @@ function SyncButton({ style, isMobile = false }: SyncButtonProps) {
}

function BudgetTitlebar() {
const maxMonths = useSelector(state => state.prefs.global.maxMonths);
const budgetType = useSelector(state => state.prefs.local.budgetType);
const maxMonths = useSelector(state => state.prefs.global?.maxMonths);
const budgetType = useSelector(state => state.prefs.local?.budgetType);
const { saveGlobalPrefs } = useActions();
const { sendEvent } = useContext(TitlebarContext);

Expand Down Expand Up @@ -366,14 +380,18 @@ function BudgetTitlebar() {
);
}

export function Titlebar({ style }) {
type TitlebarProps = {
style?: CSSProperties;
};

export function Titlebar({ style }: TitlebarProps) {
const navigate = useNavigate();
const location = useLocation();
const sidebar = useSidebar();
const { isNarrowWidth } = useResponsive();
const serverURL = useServerURL();
const floatingSidebar = useSelector(
state => state.prefs.global.floatingSidebar,
state => state.prefs.global?.floatingSidebar,
);

return isNarrowWidth ? null : (
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2273.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [MatissJanis]
---

Fix 'uncategorized transactions' flashing in the header on page load

0 comments on commit 9dfd6ce

Please sign in to comment.