From 5718cc1c512aefcc78e3d0d1d1f2e4562a19325a Mon Sep 17 00:00:00 2001 From: Kenneth Date: Fri, 29 Nov 2024 23:52:53 +0000 Subject: [PATCH] refactor: remove unused code/import --- web/src/templates/api.ts | 4 +- web/src/templates/template-editor-store.tsx | 2 +- web/src/workspaces/new-workspace-dialog.tsx | 2 +- web/src/workspaces/workspace-table.tsx | 187 ++------------------ 4 files changed, 14 insertions(+), 181 deletions(-) diff --git a/web/src/templates/api.ts b/web/src/templates/api.ts index c774d95..6d97b93 100644 --- a/web/src/templates/api.ts +++ b/web/src/templates/api.ts @@ -1,7 +1,7 @@ import { useCallback, useState } from "react"; -import useSWR, { mutate, useSWRConfig } from "swr"; +import useSWR, { useSWRConfig } from "swr"; import type { Template, TemplateMeta, TemplateImage } from "./types"; -import { fetchApi, type ApiError } from "@/api"; +import { fetchApi } from "@/api"; function useTemplates() { return useSWR( diff --git a/web/src/templates/template-editor-store.tsx b/web/src/templates/template-editor-store.tsx index 1e29ca3..9088315 100644 --- a/web/src/templates/template-editor-store.tsx +++ b/web/src/templates/template-editor-store.tsx @@ -1,4 +1,4 @@ -import { create, createStore, useStore } from "zustand"; +import { createStore, useStore } from "zustand"; import type { Template } from "./types"; import { createContext, useContext } from "react"; import { buildTemplate } from "./api"; diff --git a/web/src/workspaces/new-workspace-dialog.tsx b/web/src/workspaces/new-workspace-dialog.tsx index 8f06280..baf9faf 100644 --- a/web/src/workspaces/new-workspace-dialog.tsx +++ b/web/src/workspaces/new-workspace-dialog.tsx @@ -24,7 +24,7 @@ import { LoadingSpinner } from "@/components/ui/loading-spinner"; import { useToast } from "@/hooks/use-toast"; import { useTemplateImages } from "@/templates/api"; import { superstructResolver } from "@hookform/resolvers/superstruct"; -import { useRef, useCallback, useEffect } from "react"; +import { useRef, useEffect } from "react"; import { useForm } from "react-hook-form"; import { nonempty, object, pattern, string, type Infer } from "superstruct"; import { useCreateWorkspace } from "./api"; diff --git a/web/src/workspaces/workspace-table.tsx b/web/src/workspaces/workspace-table.tsx index fe14a8d..55b6a3b 100644 --- a/web/src/workspaces/workspace-table.tsx +++ b/web/src/workspaces/workspace-table.tsx @@ -1,4 +1,12 @@ +import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; +import { Dialog, DialogTrigger } from "@/components/ui/dialog"; +import { LoadingSpinner } from "@/components/ui/loading-spinner"; +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover"; import { Skeleton } from "@/components/ui/skeleton"; import { Table, @@ -12,41 +20,15 @@ import { useToast } from "@/hooks/use-toast"; import { StopIcon } from "@radix-ui/react-icons"; import { ToastAction } from "@radix-ui/react-toast"; import dayjs from "dayjs"; -import { Info, Loader2, Play, Plus, Trash2 } from "lucide-react"; +import { Info, Loader2, Play, Trash2 } from "lucide-react"; +import { createContext, useContext, useEffect, useState } from "react"; import { - Fragment, - createContext, - useContext, - useEffect, - useState, -} from "react"; -import { - useAddWorkspacePort, useChangeWorkspaceStatus, useDeleteWorkspace, useWorkspaces, } from "./api"; import { type Workspace, WorkspaceStatus } from "./types"; -import { LoadingSpinner } from "@/components/ui/loading-spinner"; -import { Badge } from "@/components/ui/badge"; -import { Input } from "@/components/ui/input"; -import { useForm } from "react-hook-form"; -import { number, object, pattern, size, string, type Infer } from "superstruct"; -import { superstructResolver } from "@hookform/resolvers/superstruct"; -import { - Form, - FormControl, - FormField, - FormItem, - FormMessage, -} from "@/components/ui/form"; -import { Dialog, DialogTrigger } from "@/components/ui/dialog"; import { WorkspaceInfoDialog } from "./workspace-info-dialog"; -import { - Popover, - PopoverContent, - PopoverTrigger, -} from "@/components/ui/popover"; const WorkspaceTableRowContext = createContext( null as unknown as Workspace, @@ -296,153 +278,4 @@ function WorkspaceInfoButton() { ); } -function WorkspaceInfoPopoverContent() { - const workspace = useContext(WorkspaceTableRowContext); - return ( -
-
- {workspace.sshPort ? ( - <> -
-

SSH Port

-
-

{workspace.sshPort}

- - ) : null} -
-
-

- Forwarded ports -

-
- {workspace?.ports?.map(({ port, subdomain }) => ( - -
-

{subdomain}

-
-
-

{port}

- -
-
- ))} -
- -
- ); -} - -const PortEntryForm = object({ - portName: pattern(string(), /^[\w-]+$/), - port: size(number(), 0, 65536), -}); - -function PortEntry() { - const [isAddingPort, setIsAddingPort] = useState(false); - const { addWorkspacePort, status } = useAddWorkspacePort(); - const workspace = useContext(WorkspaceTableRowContext); - const form = useForm({ - resolver: superstructResolver(PortEntryForm), - disabled: status.type === "loading", - defaultValues: { - port: 1234, - portName: "", - }, - }); - - function onAddPortButtonClick() { - if (isAddingPort) { - } else { - setIsAddingPort(true); - } - } - - async function onSubmit(values: Infer) { - await addWorkspacePort(workspace.name, [ - { subdomain: values.portName, port: values.port }, - ]); - } - - if (!isAddingPort) { - return ( - - ); - } - - return ( -
- - {isAddingPort ? ( - <> - ( - - - - - - - )} - /> - ( - - - - field.onChange(value.currentTarget.valueAsNumber) - } - /> - - - - )} - /> - - ) : null} - - - - ); -} - export { WorkspaceTable, WorkspaceTableRowContext };