From c714ab29b45c46e768dcf9009a330951d9c03865 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 31 Oct 2023 19:05:07 +0100 Subject: [PATCH 1/4] add create/join switch --- pkgs/clan-cli/clan_cli/nix.py | 3 + pkgs/clan-cli/clan_cli/task_manager.py | 1 + .../ui/src/components/hooks/useAppContext.tsx | 15 +-- pkgs/ui/src/views/joinPrequel.tsx | 101 +++++++++++++++--- 4 files changed, 101 insertions(+), 19 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/nix.py b/pkgs/clan-cli/clan_cli/nix.py index ce3c0c602..56e2964a6 100644 --- a/pkgs/clan-cli/clan_cli/nix.py +++ b/pkgs/clan-cli/clan_cli/nix.py @@ -21,6 +21,7 @@ def nix_flake_show(flake_url: AnyUrl | Path) -> list[str]: "show", "--json", "--show-trace", + "--no-write-lock-file", f"{flake_url}", ] ) @@ -35,6 +36,7 @@ def nix_build( "build", "--no-link", "--print-out-paths", + "--no-write-lock-file", ] ) + flags @@ -57,6 +59,7 @@ def nix_eval(flags: list[str]) -> list[str]: "eval", "--show-trace", "--json", + "--no-write-lock-file", ] ) if os.environ.get("IN_NIX_SANDBOX"): diff --git a/pkgs/clan-cli/clan_cli/task_manager.py b/pkgs/clan-cli/clan_cli/task_manager.py index 3e659cbe6..aaba85363 100644 --- a/pkgs/clan-cli/clan_cli/task_manager.py +++ b/pkgs/clan-cli/clan_cli/task_manager.py @@ -158,6 +158,7 @@ class TaskPool: def __init__(self) -> None: self.lock: threading.RLock = threading.RLock() self.pool: dict[UUID, BaseTask] = {} + def __getitem__(self, uuid: UUID) -> BaseTask: with self.lock: diff --git a/pkgs/ui/src/components/hooks/useAppContext.tsx b/pkgs/ui/src/components/hooks/useAppContext.tsx index f36376e20..b17e69ec3 100644 --- a/pkgs/ui/src/components/hooks/useAppContext.tsx +++ b/pkgs/ui/src/components/hooks/useAppContext.tsx @@ -1,6 +1,4 @@ -import { useListMachines } from "@/api/default/default"; -import { MachinesResponse } from "@/api/model"; -import { AxiosError, AxiosResponse } from "axios"; +import { AxiosError } from "axios"; import React, { Dispatch, ReactNode, @@ -8,7 +6,6 @@ import React, { createContext, useState, } from "react"; -import { KeyedMutator } from "swr"; type AppContextType = { // data: AxiosResponse<{}, any> | undefined; @@ -18,7 +15,7 @@ type AppContextType = { error: AxiosError | undefined; setAppState: Dispatch>; - mutate: KeyedMutator>; + // mutate: KeyedMutator>; swrKey: string | false | Record; }; @@ -38,7 +35,11 @@ interface AppContextProviderProps { } export const WithAppState = (props: AppContextProviderProps) => { const { children } = props; - const { isLoading, error, mutate, swrKey } = useListMachines("defaultFlake"); + const { isLoading, error, swrKey } = { + isLoading: false, + error: undefined, + swrKey: "default", + }; const [data, setAppState] = useState({ isJoined: false }); @@ -50,7 +51,7 @@ export const WithAppState = (props: AppContextProviderProps) => { isLoading, error, swrKey, - mutate, + // mutate, }} > {children} diff --git a/pkgs/ui/src/views/joinPrequel.tsx b/pkgs/ui/src/views/joinPrequel.tsx index 1beba84e9..3b121c5ed 100644 --- a/pkgs/ui/src/views/joinPrequel.tsx +++ b/pkgs/ui/src/views/joinPrequel.tsx @@ -1,31 +1,82 @@ "use client"; -import { IconButton, Input, InputAdornment } from "@mui/material"; +import { + IconButton, + Input, + InputAdornment, + LinearProgress, + MenuItem, + Select, +} from "@mui/material"; import { useSearchParams } from "next/navigation"; -import { Suspense } from "react"; +import { Suspense, useState } from "react"; +import { createFlake } from "@/api/default/default"; +import { useAppState } from "@/components/hooks/useAppContext"; import { Confirm } from "@/components/join/confirm"; import { Layout } from "@/components/join/layout"; import { ChevronRight } from "@mui/icons-material"; import { Controller, useForm } from "react-hook-form"; type FormValues = { + workflow: "join" | "create"; flakeUrl: string; + dest?: string; }; export default function JoinPrequel() { const queryParams = useSearchParams(); const flakeUrl = queryParams.get("flake") || ""; const flakeAttr = queryParams.get("attr") || "default"; - const { control, formState, getValues, reset } = useForm({ - defaultValues: { flakeUrl: "" }, - }); + const [forkInProgress, setForkInProgress] = useState(false); + const { setAppState } = useAppState(); + const { control, formState, getValues, reset, watch, handleSubmit } = + useForm({ + defaultValues: { flakeUrl: "", dest: undefined, workflow: "join" }, + }); + + const workflow = watch("workflow"); + + const WorkflowAdornment = ( + + ( + + )} + /> + + + + + ); return ( {!formState.isSubmitted && !flakeUrl && (
{})} + onSubmit={handleSubmit((values) => { + console.log("submitted", { values }); + if (workflow === "create") { + setForkInProgress(true); + createFlake({ + flake_name: values.dest || "default", + url: values.flakeUrl, + }).then(() => { + setForkInProgress(false); + setAppState((s) => ({ ...s, isJoined: true })); + }); + } + })} className="w-full max-w-2xl justify-self-center" > ( Clan } endAdornment={ - - - - - + workflow == "join" ? WorkflowAdornment : undefined } /> )} /> + {workflow === "create" && ( + ( + Name + } + endAdornment={ + workflow == "create" ? WorkflowAdornment : undefined + } + /> + )} + /> + )} )} - {(formState.isSubmitted || flakeUrl) && ( + {formState.isSubmitted && workflow == "create" && ( +
+ +
+ )} + {(formState.isSubmitted || flakeUrl) && workflow == "join" && ( reset()} flakeUrl={formState.isSubmitted ? getValues("flakeUrl") : flakeUrl} From 1ff5595dbc1e9c426653b086ba9b75e88a8ef71c Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sat, 4 Nov 2023 09:16:37 +0100 Subject: [PATCH 2/4] format --- pkgs/clan-cli/clan_cli/task_manager.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/task_manager.py b/pkgs/clan-cli/clan_cli/task_manager.py index aaba85363..3e659cbe6 100644 --- a/pkgs/clan-cli/clan_cli/task_manager.py +++ b/pkgs/clan-cli/clan_cli/task_manager.py @@ -158,7 +158,6 @@ class TaskPool: def __init__(self) -> None: self.lock: threading.RLock = threading.RLock() self.pool: dict[UUID, BaseTask] = {} - def __getitem__(self, uuid: UUID) -> BaseTask: with self.lock: From 376aee57e9b8909f4f4df1034398396a840dc080 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sat, 4 Nov 2023 09:46:14 +0100 Subject: [PATCH 3/4] disable lint rule --- pkgs/ui/.eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/ui/.eslintrc.json b/pkgs/ui/.eslintrc.json index 891a985aa..981c2fbf2 100644 --- a/pkgs/ui/.eslintrc.json +++ b/pkgs/ui/.eslintrc.json @@ -5,6 +5,7 @@ "plugins": ["@typescript-eslint"], "ignorePatterns": ["**/src/api/*"], "rules": { + "no-unused-vars": "off", "@typescript-eslint/no-explicit-any": "off" } } From aed41a8fbf474ef21cab7ddc52165d039c127eae Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sat, 4 Nov 2023 09:55:53 +0100 Subject: [PATCH 4/4] fix changed api imports --- pkgs/ui/.eslintrc.json | 2 +- pkgs/ui/src/views/joinPrequel.tsx | 4 ++-- pkgs/ui/tsconfig.json | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pkgs/ui/.eslintrc.json b/pkgs/ui/.eslintrc.json index 981c2fbf2..40464e701 100644 --- a/pkgs/ui/.eslintrc.json +++ b/pkgs/ui/.eslintrc.json @@ -5,7 +5,7 @@ "plugins": ["@typescript-eslint"], "ignorePatterns": ["**/src/api/*"], "rules": { - "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": "off", "@typescript-eslint/no-explicit-any": "off" } } diff --git a/pkgs/ui/src/views/joinPrequel.tsx b/pkgs/ui/src/views/joinPrequel.tsx index 3b121c5ed..eb039a667 100644 --- a/pkgs/ui/src/views/joinPrequel.tsx +++ b/pkgs/ui/src/views/joinPrequel.tsx @@ -10,7 +10,7 @@ import { import { useSearchParams } from "next/navigation"; import { Suspense, useState } from "react"; -import { createFlake } from "@/api/default/default"; +import { createFlake } from "@/api/flake/flake"; import { useAppState } from "@/components/hooks/useAppContext"; import { Confirm } from "@/components/join/confirm"; import { Layout } from "@/components/join/layout"; @@ -27,7 +27,7 @@ export default function JoinPrequel() { const queryParams = useSearchParams(); const flakeUrl = queryParams.get("flake") || ""; const flakeAttr = queryParams.get("attr") || "default"; - const [forkInProgress, setForkInProgress] = useState(false); + const [, setForkInProgress] = useState(false); const { setAppState } = useAppState(); const { control, formState, getValues, reset, watch, handleSubmit } = diff --git a/pkgs/ui/tsconfig.json b/pkgs/ui/tsconfig.json index ebe4baa2f..b93706c25 100644 --- a/pkgs/ui/tsconfig.json +++ b/pkgs/ui/tsconfig.json @@ -21,8 +21,7 @@ } ], "paths": { - "@/*": ["./src/*"], - "@API/*": ["./src/api/*"] + "@/*": ["./src/*"] } }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],