From db39eda18a77b4c2f1510555f6555ac18a89f38c Mon Sep 17 00:00:00 2001 From: Haileyesus Date: Wed, 8 Apr 2026 16:47:31 +0300 Subject: [PATCH] setup plugin routes --- src/App.tsx | 2 + .../view/PluginContentRouterAdapter.tsx | 102 ++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 src/components/plugins/view/PluginContentRouterAdapter.tsx diff --git a/src/App.tsx b/src/App.tsx index b4b2f727..c663c420 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -20,6 +20,7 @@ import StandaloneShellRouterAdapter from '@/components/standalone-shell/view/Sta import FileTreeRouterAdapter from '@/components/file-tree/view/FileTreeRouterAdapter.js'; import GitPanelRouterAdapter from '@/components/git-panel/view/GitPanelRouterAdapter.js'; import { TaskMasterPanel } from '@/components/task-master/index.js'; +import PluginContentRouterAdapter from '@/components/plugins/view/PluginContentRouterAdapter.js'; const isValidRouteTab = (value: string | undefined): boolean => { if (!value) { @@ -124,6 +125,7 @@ const router = createBrowserRouter( { path: 'files', element: }, { path: 'git', element: }, { path: 'tasks', element: }, + { path: 'plugins', element: }, { path: ':tab', element: }, ], }, diff --git a/src/components/plugins/view/PluginContentRouterAdapter.tsx b/src/components/plugins/view/PluginContentRouterAdapter.tsx new file mode 100644 index 00000000..c79c8fdd --- /dev/null +++ b/src/components/plugins/view/PluginContentRouterAdapter.tsx @@ -0,0 +1,102 @@ +/** + * This is for backward compatibility with the old setup that point to the standalone shell. + * It fetches the project and session data based on the URL parameters and passes them to the StandaloneShell component. + * If no valid parameters are found, it defaults to an empty project. + * + * TODO: This adapter can be removed once all tabs use the updated projects and sessions format. + */ + +import { useParams } from "react-router-dom"; +import { useEffect, useState } from "react"; +import { + getProjectsInLegacyFormat, + getSessionInLegacyFormat, +} from "@/components/refactored/sidebar/data/legacy-response-format-api.js"; +import { DEFAULT_PROJECT_FOR_EMPTY_SHELL } from "@/constants/config.js"; +import { Project, ProjectSession } from "@/types/app.js"; +import PluginTabContent from "@/components/plugins/view/PluginTabContent.js"; + +export default function PluginContentRouterAdapter() { + const { sessionId, workspaceId } = useParams<{ + sessionId?: string; + workspaceId?: string; + }>(); + + const [project, setProject] = useState(DEFAULT_PROJECT_FOR_EMPTY_SHELL); + const [session, setSession] = useState(null); + const [loading, setLoading] = useState(true); + + // TODO: Get plugin name from the url params + const pluginName = new URLSearchParams(window.location.search).get('name') || ''; + + useEffect(() => { + let cancelled = false; + + const fetchProjectAndSession = async () => { + setLoading(true); + + try { + if (workspaceId) { + const fetchedProject = await getProjectsInLegacyFormat(workspaceId); + + if (!cancelled) { + setProject(fetchedProject ?? DEFAULT_PROJECT_FOR_EMPTY_SHELL); + setSession(null); + } + + return; + } + + if (sessionId) { + const result = await getSessionInLegacyFormat(sessionId); + + if (!cancelled) { + if (result) { + setProject(result.project ?? DEFAULT_PROJECT_FOR_EMPTY_SHELL); + setSession(result.session ?? null); + } else { + setProject(DEFAULT_PROJECT_FOR_EMPTY_SHELL); + setSession(null); + } + } + + return; + } + + if (!cancelled) { + setProject(DEFAULT_PROJECT_FOR_EMPTY_SHELL); + setSession(null); + } + } catch (error) { + console.error("Failed to fetch project/session:", error); + + if (!cancelled) { + setProject(DEFAULT_PROJECT_FOR_EMPTY_SHELL); + setSession(null); + } + } finally { + if (!cancelled) { + setLoading(false); + } + } + }; + + fetchProjectAndSession(); + + return () => { + cancelled = true; + }; + }, [sessionId, workspaceId]); + + if (loading) { + return
Loading...
; + } + + return ( + + ); +} \ No newline at end of file