Skip to content

Commit

Permalink
Notifications slice
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Jan 14, 2025
1 parent 2e0ad56 commit 0e0d650
Show file tree
Hide file tree
Showing 42 changed files with 200 additions and 227 deletions.
8 changes: 2 additions & 6 deletions packages/desktop-client/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ import { HotkeysProvider } from 'react-hotkeys-hook';
import { useTranslation } from 'react-i18next';
import { BrowserRouter } from 'react-router-dom';

import {
addNotification,
loadGlobalPrefs,
signOut,
sync,
} from 'loot-core/client/actions';
import { loadGlobalPrefs, signOut, sync } from 'loot-core/client/actions';
import { setAppState } from 'loot-core/client/app/appSlice';
import { closeBudget, loadBudget } from 'loot-core/client/budgets/budgetsSlice';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { SpreadsheetProvider } from 'loot-core/client/SpreadsheetProvider';
import * as Platform from 'loot-core/src/client/platform';
import {
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop-client/src/components/FinancesApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
useHref,
} from 'react-router-dom';

import { addNotification, sync } from 'loot-core/client/actions';
import { sync } from 'loot-core/client/actions';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import * as undo from 'loot-core/src/platform/client/undo';

import { ProtectedRoute } from '../auth/ProtectedRoute';
Expand Down
6 changes: 4 additions & 2 deletions packages/desktop-client/src/components/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import { useTranslation } from 'react-i18next';

import { css } from '@emotion/css';

import { removeNotification } from 'loot-core/client/actions';
import type { NotificationWithId } from 'loot-core/src/client/state-types/notifications';
import {
removeNotification,
type NotificationWithId,
} from 'loot-core/client/notifications/notificationsSlice';

import { AnimatedLoading } from '../icons/AnimatedLoading';
import { SvgDelete } from '../icons/v0';
Expand Down
17 changes: 11 additions & 6 deletions packages/desktop-client/src/components/ServerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import React, {

import { t } from 'i18next';

import { addNotification } from 'loot-core/client/actions';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send } from 'loot-core/src/platform/client/fetch';
import { type Handlers } from 'loot-core/types/handlers';

import { useDispatch } from '../redux';

type LoginMethods = {
method: string;
displayName: string;
Expand Down Expand Up @@ -84,6 +86,7 @@ export const useSetLoginMethods = () =>
useContext(ServerContext).setLoginMethods;

export function ServerProvider({ children }: { children: ReactNode }) {
const dispatch = useDispatch();
const [serverURL, setServerURL] = useState('');
const [version, setVersion] = useState('');
const [multiuserEnabled, setMultiuserEnabled] = useState(false);
Expand All @@ -104,11 +107,13 @@ export function ServerProvider({ children }: { children: ReactNode }) {
const data: Awaited<ReturnType<Handlers['subscribe-get-login-methods']>> =
await send('subscribe-get-login-methods');
if ('error' in data) {
addNotification({
type: 'error',
title: t('Failed to refresh login methods'),
message: data.error ?? t('Unknown'),
});
dispatch(
addNotification({
type: 'error',
title: t('Failed to refresh login methods'),
message: data.error ?? t('Unknown'),
}),
);
setAvailableLoginMethods([]);
} else if (data.methods) {
setAvailableLoginMethods(data.methods);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import React, {
} from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { addNotification } from 'loot-core/client/actions';
import { pushModal } from 'loot-core/client/modals/modalsSlice';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send } from 'loot-core/src/platform/client/fetch';
import * as undo from 'loot-core/src/platform/client/undo';
import { type Handlers } from 'loot-core/types/handlers';
Expand Down Expand Up @@ -43,7 +43,7 @@ function UserAccessContent({
setLoading,
}: ManageUserAccessContentProps) {
const { t } = useTranslation();

const dispatch = useDispatch();
const [allAccess, setAllAccess] = useState([]);
const [page, setPage] = useState(0);
const [filter, setFilter] = useState('');
Expand Down Expand Up @@ -85,13 +85,15 @@ function UserAccessContent({
};

if ('error' in data) {
addNotification({
type: 'error',
id: 'error',
title: t('Error getting available users'),
sticky: true,
message: data.error,
});
dispatch(
addNotification({
type: 'error',
id: 'error',
title: t('Error getting available users'),
sticky: true,
message: data.error,
}),
);
return [];
}

Expand All @@ -104,7 +106,7 @@ function UserAccessContent({

setAllAccess(loadedAccess);
return loadedAccess;
}, [cloudFileId, setLoading, t]);
}, [cloudFileId, dispatch, setLoading, t]);

const loadOwner = useCallback(async () => {
const file: Awaited<ReturnType<Handlers['get-user-file-info']>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import React, { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';

import { addNotification, signOut } from 'loot-core/client/actions';
import { signOut } from 'loot-core/client/actions';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send } from 'loot-core/platform/client/fetch';
import { getUserAccessErrors } from 'loot-core/shared/errors';
import { type UserAvailable } from 'loot-core/types/models';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
} from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { addNotification, signOut } from 'loot-core/client/actions';
import { signOut } from 'loot-core/client/actions';
import { pushModal } from 'loot-core/client/modals/modalsSlice';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send } from 'loot-core/src/platform/client/fetch';
import * as undo from 'loot-core/src/platform/client/undo';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/budget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { memo, useMemo, useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';

import { pushModal } from 'loot-core/client/modals/modalsSlice';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import {
applyBudgetAction,
createCategory,
Expand All @@ -15,7 +16,6 @@ import {
updateCategory,
updateGroup,
} from 'loot-core/client/queries/queriesSlice';
import { addNotification } from 'loot-core/src/client/actions';
import { useSpreadsheet } from 'loot-core/src/client/SpreadsheetProvider';
import { send, listen } from 'loot-core/src/platform/client/fetch';
import * as monthUtils from 'loot-core/src/shared/months';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { type ReactNode, useEffect, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { useLocation, type Location } from 'react-router-dom';

import { addNotification } from 'loot-core/client/actions';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send } from 'loot-core/platform/client/fetch';
import { type Handlers } from 'loot-core/types/handlers';
import { type OpenIdConfig } from 'loot-core/types/models/openid';

import { useDispatch } from '../../../redux';
import { theme, styles } from '../../../style';
import { ButtonWithLoading } from '../../common/Button2';
import { Input } from '../../common/Input';
Expand Down Expand Up @@ -49,7 +50,7 @@ export function OpenIdForm({
loadData,
}: OpenIdFormProps) {
const { t } = useTranslation();

const dispatch = useDispatch();
const [issuer, setIssuer] = useState('');
const [clientId, setClientId] = useState('');
const [clientSecret, setClientSecret] = useState('');
Expand All @@ -71,13 +72,15 @@ export function OpenIdForm({
if (!config) return;

if ('error' in config) {
addNotification({
type: 'error',
id: 'error',
title: t('Error getting OpenID config'),
sticky: true,
message: config.error,
});
dispatch(
addNotification({
type: 'error',
id: 'error',
title: t('Error getting OpenID config'),
sticky: true,
message: config.error,
}),
);
} else if ('openId' in config) {
setProviderName(config?.openId?.selectedProvider ?? 'other');
setIssuer(config?.openId?.issuer ?? '');
Expand All @@ -87,7 +90,7 @@ export function OpenIdForm({
},
);
}
}, [loadData, t]);
}, [dispatch, loadData, t]);

const handleProviderChange = (provider: OpenIdProviderOption) => {
if (provider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
import { ListBox, Section, Header, Collection } from 'react-aria-components';
import { useTranslation } from 'react-i18next';

import { setNotificationInset } from 'loot-core/client/actions';
import { setNotificationInset } from 'loot-core/client/notifications/notificationsSlice';
import { groupById, integerToCurrency } from 'loot-core/shared/util';
import * as monthUtils from 'loot-core/src/shared/months';
import { isPreviewId } from 'loot-core/src/shared/transactions';
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop-client/src/components/modals/EditAccess.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useEffect, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { addNotification, signOut } from 'loot-core/client/actions';
import { signOut } from 'loot-core/client/actions';
import {
type Modal as ModalType,
popModal,
} from 'loot-core/client/modals/modalsSlice';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send } from 'loot-core/platform/client/fetch';
import { getUserAccessErrors } from 'loot-core/shared/errors';
import { type Handlers } from 'loot-core/types/handlers';
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop-client/src/components/modals/EditUser.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { addNotification, signOut } from 'loot-core/client/actions';
import { signOut } from 'loot-core/client/actions';
import {
type Modal as ModalType,
popModal,
} from 'loot-core/client/modals/modalsSlice';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send } from 'loot-core/platform/client/fetch';
import {
type NewUserEntity,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useEffect, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { addNotification } from 'loot-core/client/actions';
import { closeAndLoadBudget } from 'loot-core/client/budgets/budgetsSlice';
import {
type Modal as ModalType,
popModal,
} from 'loot-core/client/modals/modalsSlice';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send } from 'loot-core/platform/client/fetch';
import { getUserAccessErrors } from 'loot-core/shared/errors';
import { type Budget } from 'loot-core/types/budget';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { addNotification } from 'loot-core/client/actions';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';

import { useGlobalPref } from '../../../hooks/useGlobalPref';
import { useDispatch } from '../../../redux';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useEffect, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import { addNotification } from 'loot-core/client/actions';
import { duplicateBudget } from 'loot-core/client/budgets/budgetsSlice';
import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send } from 'loot-core/platform/client/fetch';

import { useDispatch } from '../../../redux';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useLocation } from 'react-router-dom';
import {
addNotification,
removeNotification,
} from 'loot-core/src/client/actions';
} from 'loot-core/client/notifications/notificationsSlice';
import { useDashboard } from 'loot-core/src/client/data-hooks/dashboard';
import { useReports } from 'loot-core/src/client/data-hooks/reports';
import { send } from 'loot-core/src/platform/client/fetch';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import { format, parseISO } from 'date-fns';
import { SchedulesProvider } from 'loot-core/client/data-hooks/schedules';
import { useTransactions } from 'loot-core/client/data-hooks/transactions';
import { useWidget } from 'loot-core/client/data-hooks/widget';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send } from 'loot-core/platform/client/fetch';
import { q, type Query } from 'loot-core/shared/query';
import { ungroupTransactions } from 'loot-core/shared/transactions';
import { amountToCurrency } from 'loot-core/shared/util';
import { addNotification } from 'loot-core/src/client/actions';
import * as monthUtils from 'loot-core/src/shared/months';
import {
type RuleConditionEntity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useParams } from 'react-router-dom';

import * as d from 'date-fns';

import { addNotification } from 'loot-core/client/actions';
import { useWidget } from 'loot-core/client/data-hooks/widget';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send } from 'loot-core/src/platform/client/fetch';
import * as monthUtils from 'loot-core/src/shared/months';
import { integerToCurrency } from 'loot-core/src/shared/util';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';

import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send, sendCatch } from 'loot-core/platform/client/fetch/index';
import { addNotification } from 'loot-core/src/client/actions';
import { calculateHasWarning } from 'loot-core/src/client/reports';
import * as monthUtils from 'loot-core/src/shared/months';
import { type CustomReportEntity } from 'loot-core/types/models/reports';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useParams } from 'react-router-dom';

import * as d from 'date-fns';

import { addNotification } from 'loot-core/src/client/actions';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { useWidget } from 'loot-core/src/client/data-hooks/widget';
import { send } from 'loot-core/src/platform/client/fetch';
import * as monthUtils from 'loot-core/src/shared/months';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useParams } from 'react-router-dom';

import * as d from 'date-fns';

import { addNotification } from 'loot-core/client/actions';
import { useWidget } from 'loot-core/client/data-hooks/widget';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send } from 'loot-core/src/platform/client/fetch';
import * as monthUtils from 'loot-core/src/shared/months';
import { amountToCurrency } from 'loot-core/src/shared/util';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { useParams } from 'react-router-dom';
import { parseISO } from 'date-fns';

import { useWidget } from 'loot-core/client/data-hooks/widget';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { send } from 'loot-core/platform/client/fetch';
import { amountToCurrency } from 'loot-core/shared/util';
import { addNotification } from 'loot-core/src/client/actions';
import * as monthUtils from 'loot-core/src/shared/months';
import {
type SummaryContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
isValid as isDateValid,
} from 'date-fns';

import { addNotification } from 'loot-core/client/actions';
import { pushModal } from 'loot-core/client/modals/modalsSlice';
import { addNotification } from 'loot-core/client/notifications/notificationsSlice';
import { useCachedSchedules } from 'loot-core/src/client/data-hooks/schedules';
import {
getAccountsById,
Expand Down
10 changes: 5 additions & 5 deletions packages/desktop-client/src/global-events.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// @ts-strict-ignore
import {
addGenericErrorNotification,
addNotification,
loadPrefs,
} from 'loot-core/client/actions';
import { loadPrefs } from 'loot-core/client/actions';
import { setAppState } from 'loot-core/client/app/appSlice';
import { closeBudgetUI } from 'loot-core/client/budgets/budgetsSlice';
import {
closeModal,
pushModal,
replaceModal,
} from 'loot-core/client/modals/modalsSlice';
import {
addGenericErrorNotification,
addNotification,
} from 'loot-core/client/notifications/notificationsSlice';
import {
getAccounts,
getCategories,
Expand Down
Loading

0 comments on commit 0e0d650

Please sign in to comment.