386534a415
- 为避免prop drilling把原有的刷新画布集中到一个useContext中, 在此基础上实现画布聚焦, 并在画布agent中使用  Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/123 Co-authored-by: 王德宇 <kvtodev@outlook.com> Co-committed-by: 王德宇 <kvtodev@outlook.com>
25 lines
636 B
TypeScript
25 lines
636 B
TypeScript
import { createContext, useContext } from 'react';
|
|
|
|
export interface ImageCanvasActionResult {
|
|
successed: boolean;
|
|
reason?: 'not-found-on-canva' | 'other';
|
|
}
|
|
|
|
export type ImageCanvasActions = {
|
|
focusResource: (resourceId: string) => ImageCanvasActionResult;
|
|
refreshCanvas: () => void;
|
|
};
|
|
|
|
export const ImageCanvasActionsContext =
|
|
createContext<ImageCanvasActions | null>(null);
|
|
|
|
export function useImageCanvasActions() {
|
|
const actions = useContext(ImageCanvasActionsContext);
|
|
if (!actions) {
|
|
throw new Error(
|
|
'useImageCanvasActions must be used within ImageCanvasActionsProvider',
|
|
);
|
|
}
|
|
return actions;
|
|
}
|