diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2021-09-19 19:43:11 +0200 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2021-09-19 19:43:11 +0200 |
commit | 7bdce37fd3f18e2712e18c4e2c64cac69af0aca1 (patch) | |
tree | b7ad3f1cca92e2dfd2664ae9e65652bd03ff58b2 /src_frontend/Components/Settings/CreateEditUser.svelte | |
parent | e6880cd8ccf82d993f222cb14b4860581654acb8 (diff) | |
download | Luxcena-Neo-7bdce37fd3f18e2712e18c4e2c64cac69af0aca1.tar.gz Luxcena-Neo-7bdce37fd3f18e2712e18c4e2c64cac69af0aca1.zip |
:boom: Introduce new UI based on svelte, and rewrite a lot of the node app and the NeoRuntime
Diffstat (limited to 'src_frontend/Components/Settings/CreateEditUser.svelte')
-rw-r--r-- | src_frontend/Components/Settings/CreateEditUser.svelte | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src_frontend/Components/Settings/CreateEditUser.svelte b/src_frontend/Components/Settings/CreateEditUser.svelte new file mode 100644 index 0000000..ca87336 --- /dev/null +++ b/src_frontend/Components/Settings/CreateEditUser.svelte @@ -0,0 +1,93 @@ +<script> + import { onMount } from "svelte"; + import dialogPolyfill from 'dialog-polyfill' + import Button from "../../ComponentLib/Button/Button.svelte"; + import { authorizedSocket } from "../../stores/socketStore.js"; + import { notif } from "../../stores/notifs"; + + export let username = null; + + let modal; + let password = ""; + let newUser = username == null; + + function open() { + modal.showModal() + } + function register(node) { + dialogPolyfill.registerDialog(node); + } + + function updateUser() { + authorizedSocket.emit("user:newpassword", username, password, (res) => { + if (!res.success) { notif({title: res.reason}); } + modal.close(); + }); + } + + function createUser() { + authorizedSocket.emit("user:create", username, password, (res) => { + if (!res.success) { notif({title: res.reason}); } + modal.close(); + }); + } +</script> + +<style> + dialog { + padding: 0; + border: none; + border-radius: 15px; + } + h2 { + margin: 0; + } + .content { + padding: 15px; + box-sizing: border-box; + } + input { + display: block; + width: 100%; + box-sizing: border-box; + } + .buttons { + padding: 0 15px 15px 15px; + display: flex; + } + .buttons > * { + flex-grow: 1; + } + .buttons > *:not(:last-child) { + margin-right: 5px; + } + .buttons > *:not(:first-child) { + margin-left: 5px; + } +</style> + +<slot name="trigger" {open}></slot> +<dialog bind:this={modal} use:register> + <div class="content"> + <h2> + {#if newUser} + Create user + {:else} + Edit user + {/if} + </h2> + <label for="username">Username</label> + <input type="text" id="username" placeholder="username" bind:value={username} disabled="{!newUser}" /> + <label for="password">password</label> + <input type="password" id="password" bind:value={password} /> + </div> + <div class="buttons"> + <div><Button fullWidth=true on:click={() => modal.close() } color={"var(--theme-primary)"} backgroundColor={"white"}>Cancel</Button></div> + {#if newUser} + <div><Button fullWidth=true on:click={createUser}>Create</Button></div> + {:else} + <div><Button fullWidth=true on:click={updateUser}>Update</Button></div> + {/if} + </div> + +</dialog>
\ No newline at end of file |