diff --git a/frontend/src/components/home2/AddServer.tsx b/frontend/src/components/home2/AddServer.tsx new file mode 100644 index 000000000..3b7eea8c3 --- /dev/null +++ b/frontend/src/components/home2/AddServer.tsx @@ -0,0 +1,71 @@ +import { Server } from "@monitor/types"; +import { Component, onMount } from "solid-js"; +import { createStore } from "solid-js/store"; +import { pushNotification } from "../.."; +import { ADD_SERVER } from "@monitor/util"; +import { useAppState } from "../../state/StateProvider"; +import { useToggle } from "../../util/hooks"; +import Input from "../util/Input"; +import Grid from "../util/layout/Grid"; +import CenterMenu from "../util/menu/CenterMenu"; + +const AddServer: Component<{}> = () => { + const [show, toggleShow] = useToggle(); + return ( + } + position="center" + /> + ); +}; + +const Content: Component<{ close: () => void }> = (p) => { + const { ws } = useAppState(); + let nameInput: HTMLInputElement | undefined; + const [server, setServer] = createStore({ + name: "", + address: "", + enabled: true, + owners: [], + toNotify: [], + }); + onMount(() => nameInput?.focus()); + const create = () => { + if (server.name.length > 0 && server.address.length > 0) { + ws.send(ADD_SERVER, { + server, + }); + p.close(); + } else { + pushNotification("bad", "a field is empty. fill in all fields"); + } + }; + return ( + + setServer("name", name)} + placeholder="name" + style={{ "font-size": "1.5rem" }} + /> + setServer("address", address)} + placeholder="address" + style={{ "font-size": "1.5rem" }} + /> + + + ); +}; + +export default AddServer; diff --git a/frontend/src/components/home2/Builds.tsx b/frontend/src/components/home2/Builds.tsx index 314f7b483..1fe783d4d 100644 --- a/frontend/src/components/home2/Builds.tsx +++ b/frontend/src/components/home2/Builds.tsx @@ -7,6 +7,7 @@ import Icon from "../util/Icon"; import Grid from "../util/layout/Grid"; import HoverMenu from "../util/menu/HoverMenu"; import s from "./home.module.scss"; +import { NewBuild } from "./New"; const Builds: Component<{}> = (p) => { const { builds } = useAppState(); @@ -19,6 +20,7 @@ const Builds: Component<{}> = (p) => { )} > {(id) => } + ); } diff --git a/frontend/src/components/home2/Home.tsx b/frontend/src/components/home2/Home.tsx index 0aef8d3ec..6bd94df8b 100644 --- a/frontend/src/components/home2/Home.tsx +++ b/frontend/src/components/home2/Home.tsx @@ -7,6 +7,7 @@ import Tabs from "../util/tabs/Tabs"; import Server from "./Server"; import Builds from "./Builds"; import s from "./home.module.scss"; +import AddServer from "./AddServer"; const Home: Component<{}> = (p) => { const { username, permissions } = useUser(); @@ -24,6 +25,7 @@ const Home: Component<{}> = (p) => { element: ( {(id) => } + ), }, diff --git a/frontend/src/components/home2/New.tsx b/frontend/src/components/home2/New.tsx new file mode 100644 index 000000000..ef3e0ef4f --- /dev/null +++ b/frontend/src/components/home2/New.tsx @@ -0,0 +1,105 @@ +import { CREATE_BUILD, CREATE_DEPLOYMENT } from "@monitor/util"; +import { Component, createSignal, onMount, Show } from "solid-js"; +import { pushNotification } from "../.."; +import { defaultDeployment } from "../../state/defaults"; +import { useAppState } from "../../state/StateProvider"; +import { useKeyDown, useToggle } from "../../util/hooks"; +import Icon from "../util/Icon"; +import Input from "../util/Input"; +import Flex from "../util/layout/Flex"; + +export const NewDeployment: Component<{ serverID: string }> = (p) => { + const { ws } = useAppState(); + const [showNew, toggleShowNew] = useToggle(); + const create = (name: string) => { + ws.send(CREATE_DEPLOYMENT, { + deployment: defaultDeployment(name, p.serverID), + }); + }; + return ( + + + + } + > + + + ); +}; + +export const NewBuild: Component<{}> = (p) => { + const { ws } = useAppState(); + const [showNew, toggleShowNew] = useToggle(); + const create = (name: string) => { + ws.send(CREATE_BUILD, { + build: { name }, + }); + }; + return ( + + + + } + > + + + ); +}; + +const New: Component<{ + create: (value: string) => void; + close: () => void; + placeholder: string; +}> = (p) => { + const [name, setName] = createSignal(""); + let inputRef: HTMLInputElement | undefined; + onMount(() => { + inputRef?.focus(); + }); + useKeyDown("Escape", p.close); + const create = () => { + if (name().length > 0) { + p.create(name()); + setName(""); + p.close(); + } else { + pushNotification("bad", "please provide a name"); + } + }; + return ( + + + + + {/* + create + */} + + + + ); +}; \ No newline at end of file diff --git a/frontend/src/components/home2/NewDeployment.tsx b/frontend/src/components/home2/NewDeployment.tsx deleted file mode 100644 index e98a0707b..000000000 --- a/frontend/src/components/home2/NewDeployment.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { Component } from "solid-js"; -import s from "./home.module.scss"; - -const NewDeployment: Component<{ serverID: string }> = (p) => { - return ( -
- -
- ); -} - -export default NewDeployment; \ No newline at end of file diff --git a/frontend/src/components/home2/Server.tsx b/frontend/src/components/home2/Server.tsx index ba83d2627..909adf588 100644 --- a/frontend/src/components/home2/Server.tsx +++ b/frontend/src/components/home2/Server.tsx @@ -10,7 +10,7 @@ import Flex from "../util/layout/Flex"; import Grid from "../util/layout/Grid"; import Deployment from "./Deployment"; import s from "./home.module.scss"; -import NewDeployment from "./NewDeployment"; +import { NewDeployment } from "./New"; const Server: Component<{ id: string }> = (p) => { const { servers, deployments, selected } = useAppState(); diff --git a/frontend/src/components/sidebar/AddServer.tsx b/frontend/src/components/sidebar/AddServer.tsx index 0396ac594..e2fb6aeb8 100644 --- a/frontend/src/components/sidebar/AddServer.tsx +++ b/frontend/src/components/sidebar/AddServer.tsx @@ -33,6 +33,7 @@ const Content: Component<{ close: () => void }> = (p) => { address: "", enabled: true, owners: [], + toNotify: [] }); onMount(() => nameInput?.focus()); const create = () => {