diff --git a/apps/renderer/src/components/ui/modal/stacked/bus.ts b/apps/renderer/src/components/ui/modal/stacked/bus.ts new file mode 100644 index 000000000..72979102e --- /dev/null +++ b/apps/renderer/src/components/ui/modal/stacked/bus.ts @@ -0,0 +1,10 @@ +import { createEventBus } from "@follow/utils/event-bus" + +export const ModalEventBus = createEventBus<{ + MODAL_DISPATCH: ModalDisposeEvent +}>() + +export type ModalDisposeEvent = { + type: "dismiss" + id: string +} diff --git a/apps/renderer/src/modules/trending/index.tsx b/apps/renderer/src/modules/trending/index.tsx index fc0784df6..c566dd6a1 100644 --- a/apps/renderer/src/modules/trending/index.tsx +++ b/apps/renderer/src/modules/trending/index.tsx @@ -295,7 +295,7 @@ const TrendingEntries = ({ data }: { data: Models.TrendingEntry[] }) => { return (
  • (event: T, data: EventBusMap[T]) { - window.dispatchEvent(new EventBusEvent(event, data)) +type AnyObject = Record +class EventBusStatic { + dispatch(event: T, data: E[T]) { + window.dispatchEvent(new EventBusEvent(event as string, data)) } - subscribe(event: T, callback: (data: EventBusMap[T]) => void) { + subscribe(event: T, callback: (data: E[T]) => void) { const handler = (e: any) => { if (e instanceof EventBusEvent && e._type === event) { callback(e.data) @@ -24,7 +25,7 @@ class EventBusStatic { } window.addEventListener(EventBusEvent.type, handler) - return this.unsubscribe.bind(this, event, handler) + return this.unsubscribe.bind(this, event as string, handler) } unsubscribe(event: string, handler: (e: any) => void) { @@ -32,4 +33,5 @@ class EventBusStatic { } } -export const EventBus = new EventBusStatic() +export const EventBus = new EventBusStatic() +export const createEventBus = () => new EventBusStatic()