mirror of
https://github.com/morten-olsen/refocus.dev.git
synced 2026-02-08 00:46:25 +01:00
feat: desktop version
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import { createContext, useCallback, useMemo, useState } from 'react';
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
} from 'react';
|
||||
import type { Notification } from './types';
|
||||
|
||||
type NotificationsContextValue = {
|
||||
@@ -9,6 +15,7 @@ type NotificationsContextValue = {
|
||||
|
||||
type NotificationsProviderProps = {
|
||||
children: React.ReactNode;
|
||||
onNotificationsUpdate?: (notification: Notification[]) => void;
|
||||
};
|
||||
|
||||
const NotificationsContext = createContext<NotificationsContextValue | null>(
|
||||
@@ -19,6 +26,7 @@ let nextId = 0;
|
||||
|
||||
const NotificationsProvider: React.FC<NotificationsProviderProps> = ({
|
||||
children,
|
||||
onNotificationsUpdate,
|
||||
}) => {
|
||||
const [notifications, setNotifications] = useState<Notification[]>([]);
|
||||
|
||||
@@ -55,6 +63,10 @@ const NotificationsProvider: React.FC<NotificationsProviderProps> = ({
|
||||
[notifications, add, dismiss],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
onNotificationsUpdate?.(notifications);
|
||||
}, [notifications, onNotificationsUpdate]);
|
||||
|
||||
return (
|
||||
<NotificationsContext.Provider value={value}>
|
||||
{children}
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
SlackLogin,
|
||||
} from './clients';
|
||||
import { Widget, WidgetsProvider } from './widgets';
|
||||
import { NotificationsProvider } from './notifications';
|
||||
import { NotificationsProvider, Notification } from './notifications';
|
||||
import { BoardsLoad, BoardsProvider, BoardsSave } from './boards';
|
||||
|
||||
type DashboardProviderProps = {
|
||||
@@ -14,6 +14,7 @@ type DashboardProviderProps = {
|
||||
widgets?: Widget<TSchema>[];
|
||||
load: BoardsLoad;
|
||||
save: BoardsSave;
|
||||
onNotificationsUpdate?: (notifications: Notification[]) => void;
|
||||
logins: {
|
||||
github: GithubLogin;
|
||||
linear: LinearLogin;
|
||||
@@ -27,10 +28,11 @@ const DashboardProvider: React.FC<DashboardProviderProps> = ({
|
||||
load,
|
||||
save,
|
||||
logins,
|
||||
onNotificationsUpdate,
|
||||
}) => (
|
||||
<WidgetsProvider widgets={widgets}>
|
||||
<BoardsProvider load={load} save={save}>
|
||||
<NotificationsProvider>
|
||||
<NotificationsProvider onNotificationsUpdate={onNotificationsUpdate}>
|
||||
<ClientProvider logins={logins}>{children}</ClientProvider>
|
||||
</NotificationsProvider>
|
||||
</BoardsProvider>
|
||||
|
||||
Reference in New Issue
Block a user