Dough Git

clove/allInOne

web/src/routes/admin/dash/+page.svelte

back to web/src/routes/admin/dash

<!-- src/routes/admin/dash/+page.svelte
     Copyright (c) 2026 Clove Nytrix Doughmination Twilight
     Licensed under the DASL-1.0 Licence.
     See LICENCE.md in the project root for full licence information.
-->

<script lang="ts">
  import IcChat from "~icons/ic/outline-chat";
  import IcMonitorHeart from "~icons/ic/outline-monitor-heart";
  import IcRefresh from "~icons/ic/outline-refresh";
  import IcSwapHoriz from "~icons/ic/outline-swap-horiz";
  import { errorText, type Message as MessageType } from "#lib";
  import { client } from "#lib/api.ts";
  import PageHead from "#lib/components/PageHead.svelte";
  import Message from "#lib/components/Message.svelte";

  const PAGES = [
    {
      href: "/admin/switch",
      label: "Switch manager",
      icon: IcSwapHoriz,
      desc: "Manage fronting members",
    },
    {
      href: "/admin/mental",
      label: "Mental health",
      icon: IcMonitorHeart,
      desc: "Update mental state",
    },
    {
      href: "/admin/status",
      label: "Status manager",
      icon: IcChat,
      desc: "Set member statuses",
    },
  ];

  let refreshing = $state(false);
  let message = $state<MessageType>(null);

  async function forceRefresh() {
    if (!confirm("This will reload the website for ALL connected users. Are you sure?")) return;

    refreshing = true;
    message = null;
    try {
      await client.forceRefresh();
      message = {
        type: "success",
        content: "Refresh command sent to all connected clients! The page will reload in 3 seconds...",
      };
      setTimeout(() => location.reload(), 3000);
    } catch (err) {
      message = {
        type: "error",
        content: errorText(err, "Failed to send refresh command"),
      };
      refreshing = false;
    }
  }
</script>

<svelte:head>
  <title>Admin dashboard · Plural System</title>
</svelte:head>

<div class="page">
  <PageHead
    eyebrow="Admin"
    title="Admin dashboard"
    back={{
      href: "/",
      label: "Back to home",
    }}
  />

  <div class="tiles">
    {#each PAGES as page (page.href)}
      <a class="tile" href={page.href}>
        <span class="tile-icon"><page.icon width="22" height="22" /></span>
        <h2>{page.label}</h2>
        <p>{page.desc}</p>
      </a>
    {/each}
  </div>

  <Message {message} />

  <section class="panel danger-zone">
    <div class="grow">
      <h2>Reload all open pages</h2>
      <p class="muted">
        Immediately reload the site for everyone viewing it.
      </p>
    </div>
    <div>
      <button type="button" class="danger" disabled={refreshing} onclick={forceRefresh}>
        <IcRefresh width="16" height="16" />{refreshing ? "Sending..." : "Refresh all"}
      </button>
    </div>
  </section>
</div>

<style>
  .danger-zone {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    border-color: rgb(255 138 154 / 35%);
  }

  .danger-zone h2,
  .danger-zone p {
    margin: 0;
  }

  .danger-zone h2 {
    color: var(--bad);
    font-size: 1rem;
  }
</style>