aboutsummaryrefslogtreecommitdiff
path: root/src_frontend/Components/Settings/Users.svelte
blob: 7e68c3aa495143c7eb71bcebe4a6bcdf9e2f8939 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<script>
    import { onMount } from "svelte";
    import { authorizedSocket, authorizedSocketNeeded, user } from "../../stores/socketStore.js";
    authorizedSocketNeeded.set(true);
    import CreateEditUser from "./CreateEditUser.svelte";
    import ConfirmActionDialog from "../Dialogs/ConfirmActionDialog.svelte";
    import FloatingButton from "../../ComponentLib/Button/FloatingButton.svelte";


    let usersList = [];

    function deleteUser(username) {
        authorizedSocket.emit("user:delete", username, (res) => {
            if (!res.success) { notif({title: res.reason}); }
        });
    };

    authorizedSocket.on("users", (users) => {
        usersList = users;
    });

    onMount(() => {
        authorizedSocket.emit("users:get");
    });
</script>

<style>
    h1 {
        margin: 0;
    }
    ul {
        list-style: none;
        padding: 0;
        margin: 0;
    }
    li {
        width: 100%;
        display: flex;
        padding: 10px 10px;
        border-radius: 5px;
        align-items:center;
        box-sizing: border-box;
    }
    li:hover {
        background-color: var(--grey-100);
    }
    li:not(:last-child) {
        border-bottom: 0.5px solid var(--grey-400);
    }
    .align-right { margin-left: auto; }
    button {
        background-color: transparent;
        border: none;
        padding: 10px;
        border-radius: 50%;
    }
    button:hover {
        background-color: var(--grey-300);
    }
    button:active {
        background-color: var(--grey-400);
    }
</style>

<div>
    <h1>Users</h1>
    <ul>
    {#each usersList as _user}
        <li>
            {_user}
            <div class="align-right">
                {#if $user?.username != _user}
                <ConfirmActionDialog title="Are you sure?" text="Are you sure you want to delete {_user}" action={() => {deleteUser(_user)}}>
                    <svelte:fragment slot="trigger" let:open>
                        <button on:click={open}><i class="fas fa-trash"></i></button>
                    </svelte:fragment>
                </ConfirmActionDialog>
                {/if}
                <CreateEditUser username={_user}>
                    <svelte:fragment slot="trigger" let:open>
                        <button on:click={open}><i class="fas fa-edit"></i></button>
                    </svelte:fragment>
                </CreateEditUser>
            </div>
        </li>
    {/each}
    </ul>
    <CreateEditUser>
        <svelte:fragment slot="trigger" let:open>
            <div class="button"><FloatingButton on:click={open} fullWidth=true>Create new user</FloatingButton></div>
        </svelte:fragment>
    </CreateEditUser>
</div>