Webview: add feeback for clan create workflow
This commit is contained in:
@@ -10,7 +10,8 @@ import {
|
|||||||
} from "solid-js";
|
} from "solid-js";
|
||||||
import { SubmitHandler, createForm, required } from "@modular-forms/solid";
|
import { SubmitHandler, createForm, required } from "@modular-forms/solid";
|
||||||
import toast from "solid-toast";
|
import toast from "solid-toast";
|
||||||
import { effect } from "solid-js/web";
|
import { setCurrClanURI, setRoute } from "@/src/App";
|
||||||
|
import { isValidHostname } from "@/util";
|
||||||
|
|
||||||
interface ClanDetailsProps {
|
interface ClanDetailsProps {
|
||||||
directory: string;
|
directory: string;
|
||||||
@@ -29,7 +30,10 @@ export const ClanForm = (props: ClanFormProps) => {
|
|||||||
const handleSubmit: SubmitHandler<ClanMeta> = (values, event) => {
|
const handleSubmit: SubmitHandler<ClanMeta> = (values, event) => {
|
||||||
console.log("submit", values);
|
console.log("submit", values);
|
||||||
pyApi.open_file.dispatch({
|
pyApi.open_file.dispatch({
|
||||||
file_request: { mode: "save" },
|
file_request: {
|
||||||
|
mode: "save",
|
||||||
|
},
|
||||||
|
|
||||||
op_key: "create_clan",
|
op_key: "create_clan",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -37,17 +41,45 @@ export const ClanForm = (props: ClanFormProps) => {
|
|||||||
if (r.op_key !== "create_clan") {
|
if (r.op_key !== "create_clan") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r.status !== "success") {
|
if (r.status !== "success") {
|
||||||
toast.error("Failed to create clan");
|
toast.error("Cannot select clan directory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const target_dir = r?.data;
|
||||||
|
if (!target_dir) {
|
||||||
|
toast.error("Cannot select clan directory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r.data) {
|
if (!isValidHostname(target_dir)) {
|
||||||
pyApi.create_clan.dispatch({
|
toast.error(`Directory name must be valid URI: ${target_dir}`);
|
||||||
options: { directory: r.data, meta: values },
|
return;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toast.promise(
|
||||||
|
new Promise<void>((resolve, reject) => {
|
||||||
|
pyApi.create_clan.receive((r) => {
|
||||||
|
if (r.status === "error") {
|
||||||
|
reject();
|
||||||
|
console.error(r.errors);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
// Navigate to the new clan
|
||||||
|
setCurrClanURI(target_dir);
|
||||||
|
setRoute("machines");
|
||||||
|
});
|
||||||
|
|
||||||
|
pyApi.create_clan.dispatch({
|
||||||
|
options: { directory: target_dir, meta: values },
|
||||||
|
op_key: "create_clan",
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
loading: "Creating clan...",
|
||||||
|
success: "Clan Successfully Created",
|
||||||
|
error: "Failed to create clan",
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,6 @@ import toast from "solid-toast";
|
|||||||
import { ClanDetails, ClanForm } from "./clanDetails";
|
import { ClanDetails, ClanForm } from "./clanDetails";
|
||||||
|
|
||||||
export const CreateClan = () => {
|
export const CreateClan = () => {
|
||||||
// const [mode, setMode] = createSignal<"init" | "open" | "create">("init");
|
|
||||||
const [clanDir, setClanDir] = createSignal<string | null>(null);
|
|
||||||
|
|
||||||
// createEffect(() => {
|
|
||||||
// console.log(mode());
|
|
||||||
// });
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<ClanForm
|
<ClanForm
|
||||||
|
|||||||
Reference in New Issue
Block a user