mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-21 15:36:50 -05:00
Fix null context crash in tracking budget mode (#6538)
* Initial plan * Fix fatal error by adding default values to TrackingBudgetContext The TrackingBudgetContext was initialized with null, causing a fatal error when components tried to destructure properties like currentMonth. This fix adds proper default values and type definitions, matching the pattern used in EnvelopeBudgetContext. Co-authored-by: MatissJanis <886567+MatissJanis@users.noreply.github.com> * Add release notes for issue #6538 Co-authored-by: MatissJanis <886567+MatissJanis@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MatissJanis <886567+MatissJanis@users.noreply.github.com>
This commit is contained in:
@@ -1,14 +1,31 @@
|
||||
// @ts-strict-ignore
|
||||
import React, { type ReactNode, createContext, useContext } from 'react';
|
||||
|
||||
import * as monthUtils from 'loot-core/shared/months';
|
||||
|
||||
const Context = createContext(null);
|
||||
|
||||
type TrackingBudgetProviderProps = {
|
||||
type TrackingBudgetContextDefinition = {
|
||||
summaryCollapsed: boolean;
|
||||
onBudgetAction: (month: string, action: string, arg: unknown) => void;
|
||||
onBudgetAction: (month: string, action: string, arg?: unknown) => void;
|
||||
onToggleSummaryCollapse: () => void;
|
||||
currentMonth: string;
|
||||
};
|
||||
|
||||
const TrackingBudgetContext = createContext<TrackingBudgetContextDefinition>({
|
||||
summaryCollapsed: false,
|
||||
onBudgetAction: () => {
|
||||
throw new Error('Unitialised context method called: onBudgetAction');
|
||||
},
|
||||
onToggleSummaryCollapse: () => {
|
||||
throw new Error(
|
||||
'Unitialised context method called: onToggleSummaryCollapse',
|
||||
);
|
||||
},
|
||||
currentMonth: 'unknown',
|
||||
});
|
||||
|
||||
type TrackingBudgetProviderProps = Omit<
|
||||
TrackingBudgetContextDefinition,
|
||||
'currentMonth'
|
||||
> & {
|
||||
children: ReactNode;
|
||||
};
|
||||
export function TrackingBudgetProvider({
|
||||
@@ -20,7 +37,7 @@ export function TrackingBudgetProvider({
|
||||
const currentMonth = monthUtils.currentMonth();
|
||||
|
||||
return (
|
||||
<Context.Provider
|
||||
<TrackingBudgetContext.Provider
|
||||
value={{
|
||||
currentMonth,
|
||||
summaryCollapsed,
|
||||
@@ -29,10 +46,10 @@ export function TrackingBudgetProvider({
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Context.Provider>
|
||||
</TrackingBudgetContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useTrackingBudget() {
|
||||
return useContext(Context);
|
||||
return useContext(TrackingBudgetContext);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user