Skip to content

Commit

Permalink
Merge pull request #65 from bennetrr/main
Browse files Browse the repository at this point in the history
fix: Toasts
  • Loading branch information
bennetrr authored Aug 14, 2024
2 parents 718a4d3 + f84b0b5 commit 649fa98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const App: React.FC = observer(() => {

return (
<>
<ToastProvider value={toast.current}>
<ToastProvider value={toast}>
<RouterProvider router={appRouter} />
</ToastProvider>

Expand Down
20 changes: 10 additions & 10 deletions src/frontend/src/utils/ToastContext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext, useContext } from 'react';
import { createContext, useContext, RefObject } from 'react';
import { Toast, ToastMessage } from 'primereact/toast';

const ToastContext = createContext<Toast | null>(null);
const ToastContext = createContext<RefObject<Toast> | null>(null);
export const ToastProvider = ToastContext.Provider;

interface IToast {
Expand Down Expand Up @@ -31,30 +31,30 @@ export function useToast(): IToast {

return {
show(message: ToastMessage | ToastMessage[]) {
if (!toast) {
if (!toast?.current) {
console.error('Toast is not initialized, but messages were sent:', message);
return;
}

toast.show(message);
toast.current.show(message);
},
clear() {
if (toast) {
toast.clear();
if (toast?.current) {
toast.current.clear();
}
},
remove(message: ToastMessage | ToastMessage[]) {
if (toast) {
toast.remove(message);
if (toast?.current) {
toast.current.remove(message);
}
},
replace(message: ToastMessage | ToastMessage[]) {
if (!toast) {
if (!toast?.current) {
console.error('Toast is not initialized, but messages were sent:', message);
return;
}

toast.replace(message);
toast.current.replace(message);
}
}
}

0 comments on commit 649fa98

Please sign in to comment.