-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use the event bus for toast instead of a context (#126)
* Use the event bus for toast instead of a context * Added a dedicated toast listener function
- Loading branch information
1 parent
596b8ec
commit 8fb1b4b
Showing
7 changed files
with
50 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { useEventBusDispatcher, useEventBusListener } from "@squide/firefly"; | ||
|
||
export type MessageTypes = "write-to-host"; | ||
export type MessageTypes = "write-to-host" | "show-toast"; | ||
|
||
export const useApplicationEventBusDispatcher = useEventBusDispatcher<MessageTypes>; | ||
export const useApplicationEventBusListener = useEventBusListener<MessageTypes>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
export * from "./BackgroundColorContext.ts"; | ||
export * from "./ToastContext.ts"; | ||
export * from "./appContext.ts"; | ||
export * from "./eventBus.ts"; | ||
export * from "./isNetlify.ts"; | ||
export * from "./layouts/registerLayouts.tsx"; | ||
export * from "./session.ts"; | ||
export * from "./useToast.ts"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useCallback } from "react"; | ||
import { useApplicationEventBusDispatcher, useApplicationEventBusListener } from "./eventBus.ts"; | ||
|
||
export function useToast() { | ||
const dispatch = useApplicationEventBusDispatcher(); | ||
|
||
return useCallback((message: string) => { | ||
dispatch("show-toast", message); | ||
}, [dispatch]); | ||
} | ||
|
||
export function useToastListener(callback: (message: string) => void) { | ||
useApplicationEventBusListener("show-toast", callback as (message: unknown) => void); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters