61875be857
Let GMs manage and show images over the scene from the editor and control panel, with zoom tools, help docs, and full ru/en i18n. Co-authored-by: Cursor <cursoragent@cursor.com>
32 lines
925 B
TypeScript
32 lines
925 B
TypeScript
import { useEffect, useState } from 'react';
|
|
|
|
import { ipcChannels } from '../../../shared/ipc/contracts';
|
|
import type { MaterialsOverlayEvent, MaterialsOverlayState } from '../../../shared/types';
|
|
import { getDndApi } from '../dndApi';
|
|
|
|
export function useMaterialsOverlayState(): readonly [
|
|
MaterialsOverlayState | null,
|
|
{ dispatch: (event: MaterialsOverlayEvent) => Promise<void> },
|
|
] {
|
|
const api = getDndApi();
|
|
const [state, setState] = useState<MaterialsOverlayState | null>(null);
|
|
|
|
useEffect(() => {
|
|
void api.invoke(ipcChannels.materialsOverlay.getState, {}).then((r) => {
|
|
setState(r.state);
|
|
});
|
|
return api.on(ipcChannels.materialsOverlay.stateChanged, ({ state: next }) => {
|
|
setState(next);
|
|
});
|
|
}, [api]);
|
|
|
|
return [
|
|
state,
|
|
{
|
|
dispatch: async (event) => {
|
|
await api.invoke(ipcChannels.materialsOverlay.dispatch, { event });
|
|
},
|
|
},
|
|
] as const;
|
|
}
|