mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 09:20:15 +01:00
feat(client): Toast Provider to show Toasts from higher on the DOM tree (#1110)
This commit is contained in:
parent
81a90d245b
commit
5cafe0900c
5 changed files with 34 additions and 11 deletions
|
|
@ -4,6 +4,7 @@ import { RouterProvider } from 'react-router-dom';
|
||||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
||||||
import { QueryClient, QueryClientProvider, QueryCache } from '@tanstack/react-query';
|
import { QueryClient, QueryClientProvider, QueryCache } from '@tanstack/react-query';
|
||||||
import { ScreenshotProvider, ThemeProvider, useApiErrorBoundary } from './hooks';
|
import { ScreenshotProvider, ThemeProvider, useApiErrorBoundary } from './hooks';
|
||||||
|
import { ToastProvider } from './Providers';
|
||||||
import Toast from './components/ui/Toast';
|
import Toast from './components/ui/Toast';
|
||||||
import { router } from './routes';
|
import { router } from './routes';
|
||||||
|
|
||||||
|
|
@ -25,10 +26,12 @@ const App = () => {
|
||||||
<RecoilRoot>
|
<RecoilRoot>
|
||||||
<ThemeProvider>
|
<ThemeProvider>
|
||||||
<RadixToast.Provider>
|
<RadixToast.Provider>
|
||||||
|
<ToastProvider>
|
||||||
<RouterProvider router={router} />
|
<RouterProvider router={router} />
|
||||||
<ReactQueryDevtools initialIsOpen={false} position="top-right" />
|
<ReactQueryDevtools initialIsOpen={false} position="top-right" />
|
||||||
<Toast />
|
<Toast />
|
||||||
<RadixToast.Viewport className="pointer-events-none fixed inset-0 z-[60] mx-auto my-2 flex max-w-[560px] flex-col items-stretch justify-start md:pb-5" />
|
<RadixToast.Viewport className="pointer-events-none fixed inset-0 z-[60] mx-auto my-2 flex max-w-[560px] flex-col items-stretch justify-start md:pb-5" />
|
||||||
|
</ToastProvider>
|
||||||
</RadixToast.Provider>
|
</RadixToast.Provider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</RecoilRoot>
|
</RecoilRoot>
|
||||||
|
|
|
||||||
17
client/src/Providers/ToastContext.tsx
Normal file
17
client/src/Providers/ToastContext.tsx
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { createContext } from 'react';
|
||||||
|
import type { TShowToast } from '~/common';
|
||||||
|
import { useToast } from '~/hooks';
|
||||||
|
|
||||||
|
type ToastContextType = {
|
||||||
|
showToast: ({ message, severity, showIcon }: TShowToast) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ToastContext = createContext<ToastContextType>({
|
||||||
|
showToast: () => ({}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default function ToastProvider({ children }) {
|
||||||
|
const { showToast } = useToast();
|
||||||
|
|
||||||
|
return <ToastContext.Provider value={{ showToast }}>{children}</ToastContext.Provider>;
|
||||||
|
}
|
||||||
2
client/src/Providers/index.ts
Normal file
2
client/src/Providers/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
export { default as ToastProvider } from './ToastContext';
|
||||||
|
export * from './ToastContext';
|
||||||
|
|
@ -28,6 +28,12 @@ export enum NotificationSeverity {
|
||||||
ERROR = 'error',
|
ERROR = 'error',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type TShowToast = {
|
||||||
|
message: string;
|
||||||
|
severity?: NotificationSeverity;
|
||||||
|
showIcon?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
export type TBaseSettingsProps = {
|
export type TBaseSettingsProps = {
|
||||||
conversation: TConversation | TPreset | null;
|
conversation: TConversation | TPreset | null;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { useRef, useEffect } from 'react';
|
|
||||||
import { useRecoilState } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
|
import { useRef, useEffect } from 'react';
|
||||||
|
import type { TShowToast } from '~/common';
|
||||||
import { NotificationSeverity } from '~/common';
|
import { NotificationSeverity } from '~/common';
|
||||||
import store from '~/store';
|
import store from '~/store';
|
||||||
|
|
||||||
|
|
@ -15,12 +16,6 @@ export default function useToast(timeoutDuration = 100) {
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
type TShowToast = {
|
|
||||||
message: string;
|
|
||||||
severity?: NotificationSeverity;
|
|
||||||
showIcon?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
const showToast = ({
|
const showToast = ({
|
||||||
message,
|
message,
|
||||||
severity = NotificationSeverity.SUCCESS,
|
severity = NotificationSeverity.SUCCESS,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue