refactor(core): replace all notification relies on jotai (#6417)

- remove all notification that implemented with jotai and replaced with new `notify`
- Add some notify presets:
  - `notify.error`
  - `notify.success`
  - `notify.warning`
This commit is contained in:
CatsJuice
2024-04-02 03:19:06 +00:00
parent a4cd51e503
commit 9127bfae67
24 changed files with 150 additions and 201 deletions
@@ -1,6 +1,9 @@
import { atom } from 'jotai';
import { nanoid } from 'nanoid';
/**
* @deprecated use `import type { Notification } from '@affine/component'` instead
*/
export type Notification = {
key?: string;
title: string;
@@ -19,6 +22,9 @@ const notificationsBaseAtom = atom<Notification[]>([]);
const expandNotificationCenterBaseAtom = atom(false);
const cleanupQueueAtom = atom<(() => unknown)[]>([]);
/**
* @deprecated use `import { notify } from '@affine/component'` instead
*/
export const expandNotificationCenterAtom = atom<boolean, [boolean], void>(
get => get(expandNotificationCenterBaseAtom),
(get, set, value) => {
@@ -29,17 +35,24 @@ export const expandNotificationCenterAtom = atom<boolean, [boolean], void>(
set(expandNotificationCenterBaseAtom, value);
}
);
/**
* @deprecated use `import { notify } from '@affine/component'` instead
*/
export const notificationsAtom = atom<Notification[]>(get =>
get(notificationsBaseAtom)
);
/**
* @deprecated use `import { notify } from '@affine/component'` instead
*/
export const removeNotificationAtom = atom(null, (_, set, key: string) => {
set(notificationsBaseAtom, notifications =>
notifications.filter(notification => notification.key !== key)
);
});
/**
* @deprecated use `import { notify } from '@affine/component'` instead
*/
export const pushNotificationAtom = atom<null, [Notification], void>(
null,
(_, set, newNotification) => {
@@ -375,6 +375,9 @@ function NotificationCard(props: NotificationCardProps): ReactNode {
);
}
/**
* @deprecated use `import { NotificationCenter } from '@affine/component'` instead
*/
export function NotificationCenter(): ReactNode {
const notifications = useAtomValue(notificationsAtom);
const [expand, setExpand] = useAtom(expandNotificationCenterAtom);