+page.svelte 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <script lang="ts">
  2. import * as Sidebar from "$lib/components/ui/sidebar/index.js";
  3. import AppSidebar from "$lib/components/Sidebar.svelte";
  4. import { toggleMode } from "mode-watcher";
  5. import { Button } from "$lib/components/ui/button";
  6. import { SunIcon, MoonIcon, Lock } from "@lucide/svelte";
  7. import WorkspaceEntry from "$lib/components/WorkspaceEntry.svelte";
  8. import {
  9. state as _state,
  10. createEnvironment,
  11. selectEnvironment,
  12. } from "$lib/state.svelte";
  13. import { SlidersHorizontal } from "@lucide/svelte";
  14. import Environment from "$lib/components/Environment.svelte";
  15. import * as DropdownMenu from "$lib/components/ui/dropdown-menu/index";
  16. import Auth from "$lib/components/Auth.svelte";
  17. import { Input } from "$lib/components/ui/input";
  18. let displayModal: "env" | "auth" | null = $state(null);
  19. let addEnvInput = $state("");
  20. </script>
  21. <Sidebar.Provider>
  22. <AppSidebar onSelect={() => (displayModal = null)} />
  23. <main class="w-full p-4 space-y-4">
  24. <header class="flex items-center w-full border-b pb-2">
  25. <p class="w-full">{_state.workspace?.name ?? "-"}</p>
  26. <p class="text-center mr-2">Environment:</p>
  27. <DropdownMenu.Root>
  28. <DropdownMenu.Trigger>
  29. {#snippet child({ props })}
  30. <div class="flex justify-center w-1/8">
  31. <!-- Workspace name -->
  32. <Sidebar.MenuButton
  33. class="flex justify-center"
  34. {...props}
  35. variant="outline"
  36. >
  37. {_state.environment?.name || "-"}
  38. </Sidebar.MenuButton>
  39. </div>
  40. {/snippet}
  41. </DropdownMenu.Trigger>
  42. <DropdownMenu.Content align="center">
  43. <DropdownMenu.Label>New environment</DropdownMenu.Label>
  44. <form
  45. class="flex w-full max-w-sm items-center gap-2"
  46. onsubmit={(e) => {
  47. e.preventDefault();
  48. if (addEnvInput.length > 0 && _state.workspace) {
  49. createEnvironment(_state.workspace.id, addEnvInput);
  50. addEnvInput = "";
  51. }
  52. }}
  53. >
  54. <Input
  55. type="text"
  56. placeholder="My environment"
  57. bind:value={addEnvInput}
  58. />
  59. <Button type="submit" variant="outline">+</Button>
  60. </form>
  61. <DropdownMenu.Separator />
  62. <DropdownMenu.Item onSelect={() => selectEnvironment(null)}
  63. >- {_state.environment === null ? " ✓" : ""}</DropdownMenu.Item
  64. >
  65. {#each _state.environments as env}
  66. <DropdownMenu.Item onSelect={() => selectEnvironment(env.id)}
  67. >{env.name}{_state.environment?.id === env.id
  68. ? " ✓"
  69. : ""}</DropdownMenu.Item
  70. >
  71. {/each}
  72. </DropdownMenu.Content>
  73. </DropdownMenu.Root>
  74. </header>
  75. {#if displayModal === "env"}
  76. <Environment />
  77. {:else if displayModal === "auth"}
  78. <Auth />
  79. {:else if _state.entry}
  80. <WorkspaceEntry />
  81. {:else}{/if}
  82. </main>
  83. <Sidebar.Provider style="--sidebar-width: 3.5rem">
  84. <Sidebar.Root fixed={false} variant="floating" side="right">
  85. <Sidebar.Menu class="items-center">
  86. <Sidebar.MenuItem class="pt-2">
  87. <Button onclick={toggleMode} variant="ghost" size="icon-sm">
  88. <SunIcon
  89. class="h-1 w-1 scale-100 rotate-0 transition-all! dark:scale-0 dark:-rotate-90"
  90. />
  91. <MoonIcon
  92. class="absolute h-1 w-1 scale-0 rotate-90 transition-all! dark:scale-100 dark:rotate-0"
  93. />
  94. <span class="sr-only">Toggle theme</span>
  95. </Button>
  96. </Sidebar.MenuItem>
  97. <Sidebar.MenuItem class="pt-2">
  98. <Button
  99. onclick={() =>
  100. (displayModal = displayModal === "env" ? null : "env")}
  101. variant={displayModal === "env" ? "default" : "ghost"}
  102. size="icon-sm"
  103. >
  104. <SlidersHorizontal />
  105. <span class="sr-only">Display environment</span>
  106. </Button>
  107. </Sidebar.MenuItem>
  108. <Sidebar.MenuItem class="pt-2">
  109. <Button
  110. onclick={() =>
  111. (displayModal = displayModal === "auth" ? null : "auth")}
  112. variant={displayModal === "auth" ? "default" : "ghost"}
  113. size="icon-sm"
  114. >
  115. <Lock />
  116. <span class="sr-only">Display auth</span>
  117. </Button>
  118. </Sidebar.MenuItem>
  119. </Sidebar.Menu>
  120. </Sidebar.Root>
  121. </Sidebar.Provider>
  122. </Sidebar.Provider>