import { Match } from "effect" import { createEffect, createMemo, Show, type ParentProps } from "solid-js" import { usePlatform } from "@/runtime/platform/platform" import { ServerConnection, useServers } from "@/runtime/server/registry" import { useCurrentRoute } from "@/shell/state/layout" import { useTabs } from "@/shell/tabs/tabs" import { Contribution } from "./render" import { usePluginServers } from "./servers" /** * Keeps the routed session or draft mounted and lets its server's plugin cover it while the * server is not ready. */ export function PluginServerCover(props: ParentProps) { const servers = usePluginServers() const route = useCurrentRoute() const tabs = useTabs() const covered = createMemo(() => { const current = route() const key = Match.value(current).pipe( Match.when({ type: "session" }, (session) => session.server), Match.when( { type: "draft" }, (draft) => tabs.store.find((tab) => tab.type === "draft" && tab.draftID === draft.draftID)?.server, ), Match.orElse(() => undefined), ) if (!key) return const source = servers.entry(key) if (!source?.entry.cover || source.entry.state === "ready") return return source.key }) const tab = () => { const current = route() if (current.type === "session") return `${current.server}:${current.sessionId}` if (current.type === "draft") return current.draftID return "" } return (