feat: 컴포넌트 추가, 스타일 수정
This commit is contained in:
43
web-app/app/shared/components/modal/store.ts
Normal file
43
web-app/app/shared/components/modal/store.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import type { ComponentType } from 'react';
|
||||
|
||||
interface ModalData {
|
||||
id: string;
|
||||
scopeId: string;
|
||||
Component: ComponentType<any>;
|
||||
props: Record<string, unknown>;
|
||||
resolve: () => void;
|
||||
}
|
||||
|
||||
let modals: ModalData[] = [];
|
||||
let listeners: (() => void)[] = [];
|
||||
|
||||
const emitChange = () => {
|
||||
listeners.forEach((listener) => listener());
|
||||
};
|
||||
|
||||
const SERVER_SNAPSHOT: ModalData[] = [];
|
||||
|
||||
export const modalStore = {
|
||||
subscribe: (listener: () => void) => {
|
||||
listeners = [...listeners, listener];
|
||||
return () => {
|
||||
listeners = listeners.filter((l) => l !== listener);
|
||||
};
|
||||
},
|
||||
getSnapshot: () => modals,
|
||||
getServerSnapshot: () => SERVER_SNAPSHOT,
|
||||
addModal: (modal: ModalData) => {
|
||||
modals = [...modals, modal];
|
||||
emitChange();
|
||||
},
|
||||
removeModal: (id: string) => {
|
||||
modals = modals.filter((m) => m.id !== id);
|
||||
emitChange();
|
||||
},
|
||||
removeByScope: (scopeId: string) => {
|
||||
modals = modals.filter((m) => m.scopeId !== scopeId);
|
||||
emitChange();
|
||||
},
|
||||
};
|
||||
|
||||
export type { ModalData };
|
||||
Reference in New Issue
Block a user