From 402fafcc91b787cbefbad08fd9d0a46974982d20 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 15 Jun 2024 06:15:59 +0000 Subject: [PATCH] Placeholder for a plugin panel loaded dynamically --- src/frontend/src/hooks/UsePluginPanels.tsx | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/frontend/src/hooks/UsePluginPanels.tsx diff --git a/src/frontend/src/hooks/UsePluginPanels.tsx b/src/frontend/src/hooks/UsePluginPanels.tsx new file mode 100644 index 0000000000..3f730c4d43 --- /dev/null +++ b/src/frontend/src/hooks/UsePluginPanels.tsx @@ -0,0 +1,58 @@ +import { useTimeout } from '@mantine/hooks'; +import { Icon24Hours } from '@tabler/icons-react'; +import { ReactNode, useEffect, useMemo, useState } from 'react'; + +import { PanelType } from '../components/nav/Panel'; + +export interface PluginPanelState extends PanelType { + pluginKey: string; + targetType: string; + targetId?: string | number | null; +} + +export function usePluginPanel({ + pluginKey, + panelName, + targetModel, + targetId +}: { + pluginKey: string; + panelName: string; + targetModel: string; + targetId?: string | number | null; +}): PluginPanelState { + // TODO: Query to fetch the "content" for the plugin + + const [loaded, setLoaded] = useState(false); + + const { start } = useTimeout(() => setLoaded(true), 5000); + + useEffect(() => { + start(); + console.log('starting timer!'); + }, []); + + const content = useMemo(() => { + return loaded ? ( + 'plugin content loaded!' + ) : ( +
+

Plugin content goes here...

+

Plugin Key: {pluginKey}

+

Panel Name: {panelName}

+

Target Model: {targetModel}

+

Target ID: {targetId}

+
+ ); + }, [loaded, pluginKey, panelName, targetModel, targetId]); + + return { + content: content, + name: panelName, + pluginKey: pluginKey, + targetType: targetModel, + targetId: targetId, + label: 'A plugin panel', + icon: + }; +}