nsarrazin commited on
Commit
782a4fb
·
1 Parent(s): 4ddaa1a

feat: add simple light/dark mode toggle

Browse files
Files changed (1) hide show
  1. src/lib/components/NavMenu.svelte +78 -14
src/lib/components/NavMenu.svelte CHANGED
@@ -14,6 +14,7 @@
14
  import InfiniteScroll from "./InfiniteScroll.svelte";
15
  import type { Conversation } from "$lib/types/Conversation";
16
  import { CONV_NUM_PER_PAGE } from "$lib/constants/pagination";
 
17
 
18
  interface Props {
19
  conversations: ConvSidebar[];
@@ -84,6 +85,8 @@
84
  p = 0;
85
  }
86
  });
 
 
87
  </script>
88
 
89
  <div
@@ -139,7 +142,7 @@
139
  {/await}
140
  </div>
141
  <div
142
- class="mt-3 flex touch-none flex-col gap-1 rounded-r-xl p-3 text-sm md:bg-gradient-to-l md:from-gray-50 md:dark:from-gray-800/30"
143
  >
144
  {#if user?.username || user?.email}
145
  <form
@@ -171,13 +174,6 @@
171
  </button>
172
  </form>
173
  {/if}
174
- <button
175
- onclick={switchTheme}
176
- type="button"
177
- class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-2.5 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
178
- >
179
- Theme
180
- </button>
181
  {#if nModels > 1}
182
  <a
183
  href="{base}/models"
@@ -211,10 +207,78 @@
211
  </a>
212
  {/if}
213
 
214
- <a
215
- href="{base}/settings"
216
- class="flex h-9 flex-none items-center gap-1.5 rounded-lg pl-2.5 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
217
- >
218
- Settings
219
- </a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  </div>
 
14
  import InfiniteScroll from "./InfiniteScroll.svelte";
15
  import type { Conversation } from "$lib/types/Conversation";
16
  import { CONV_NUM_PER_PAGE } from "$lib/constants/pagination";
17
+ import { browser } from "$app/environment";
18
 
19
  interface Props {
20
  conversations: ConvSidebar[];
 
85
  p = 0;
86
  }
87
  });
88
+
89
+ let theme = $state(browser ? localStorage.theme : "light");
90
  </script>
91
 
92
  <div
 
142
  {/await}
143
  </div>
144
  <div
145
+ class="flex touch-none flex-col gap-1 rounded-r-xl p-3 text-sm md:mt-3 md:bg-gradient-to-l md:from-gray-50 md:dark:from-gray-800/30"
146
  >
147
  {#if user?.username || user?.email}
148
  <form
 
174
  </button>
175
  </form>
176
  {/if}
 
 
 
 
 
 
 
177
  {#if nModels > 1}
178
  <a
179
  href="{base}/models"
 
207
  </a>
208
  {/if}
209
 
210
+ <span class="flex flex-row-reverse gap-1 md:flex-row">
211
+ <a
212
+ href="{base}/settings"
213
+ class="flex h-9 flex-none flex-grow items-center gap-1.5 rounded-lg pl-2.5 pr-2 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700"
214
+ >
215
+ Settings
216
+ </a>
217
+ <button
218
+ onclick={() => {
219
+ switchTheme();
220
+ theme = localStorage.theme;
221
+ }}
222
+ aria-label="Toggle theme"
223
+ class="flex h-9 min-w-[1em] flex-none items-center rounded-lg p-2 pr-0 text-gray-500 hover:bg-gray-100 dark:text-gray-400 dark:hover:bg-gray-700 md:pr-2"
224
+ >
225
+ {#if browser}
226
+ {#if theme === "dark"}
227
+ <svg
228
+ xmlns="http://www.w3.org/2000/svg"
229
+ xmlns:xlink="http://www.w3.org/1999/xlink"
230
+ aria-hidden="true"
231
+ focusable="false"
232
+ role="img"
233
+ width="1em"
234
+ height="1em"
235
+ preserveAspectRatio="xMidYMid meet"
236
+ viewBox="0 0 32 32"
237
+ stroke-width="1.5"
238
+ ><path
239
+ d="M16 12.005a4 4 0 1 1-4 4a4.005 4.005 0 0 1 4-4m0-2a6 6 0 1 0 6 6a6 6 0 0 0-6-6z"
240
+ fill="currentColor"
241
+ stroke="currentColor"
242
+ stroke-width="0.5"
243
+ ></path><path d="M5.394 6.813l1.414-1.415l3.506 3.506L8.9 10.318z" fill="currentColor"
244
+ ></path><path d="M2 15.005h5v2H2z" fill="currentColor"></path><path
245
+ stroke="currentColor"
246
+ stroke-width="0.5"
247
+ d="M5.394 25.197L8.9 21.691l1.414 1.415l-3.506 3.505z"
248
+ fill="currentColor"
249
+ ></path><path d="M15 25.005h2v5h-2z" fill="currentColor"></path><path
250
+ stroke="currentColor"
251
+ stroke-width="0.5"
252
+ d="M21.687 23.106l1.414-1.415l3.506 3.506l-1.414 1.414z"
253
+ fill="currentColor"
254
+ ></path><path d="M25 15.005h5v2h-5z" fill="currentColor"></path><path
255
+ stroke="currentColor"
256
+ stroke-width="0.5"
257
+ d="M21.687 8.904l3.506-3.506l1.414 1.415l-3.506 3.505z"
258
+ fill="currentColor"
259
+ ></path><path d="M15 2.005h2v5h-2z" fill="currentColor"></path></svg
260
+ >
261
+ {:else}
262
+ <svg
263
+ xmlns="http://www.w3.org/2000/svg"
264
+ xmlns:xlink="http://www.w3.org/1999/xlink"
265
+ aria-hidden="true"
266
+ focusable="false"
267
+ role="img"
268
+ width="1em"
269
+ height="1em"
270
+ preserveAspectRatio="xMidYMid meet"
271
+ viewBox="0 0 32 32"
272
+ stroke-width="1.5"
273
+ ><path
274
+ d="M13.502 5.414a15.075 15.075 0 0 0 11.594 18.194a11.113 11.113 0 0 1-7.975 3.39c-.138 0-.278.005-.418 0a11.094 11.094 0 0 1-3.2-21.584M14.98 3a1.002 1.002 0 0 0-.175.016a13.096 13.096 0 0 0 1.825 25.981c.164.006.328 0 .49 0a13.072 13.072 0 0 0 10.703-5.555a1.01 1.01 0 0 0-.783-1.565A13.08 13.08 0 0 1 15.89 4.38A1.015 1.015 0 0 0 14.98 3z"
275
+ fill="currentColor"
276
+ stroke="currentColor"
277
+ stroke-width="0.5"
278
+ ></path></svg
279
+ >
280
+ {/if}
281
+ {/if}
282
+ </button>
283
+ </span>
284
  </div>