|
13 | 13 | isMachineTimeSameAsPreferred |
14 | 14 | } from "@davidnet/svelte-ui"; |
15 | 15 | import { onMount, onDestroy } from "svelte"; |
| 16 | + import { writable } from "svelte/store"; |
16 | 17 |
|
17 | 18 | let correlationID = crypto.randomUUID(); |
18 | 19 | let sessionInfo: SessionInfo | null = $state(null); |
|
112 | 113 | onDestroy(() => { |
113 | 114 | window.removeEventListener("resize", handleResize); |
114 | 115 | }); |
| 116 | +
|
| 117 | + export type CustomLink = { |
| 118 | + id: string; |
| 119 | + name: string; |
| 120 | + url: string; |
| 121 | + }; |
| 122 | +
|
| 123 | + const storedLinks = localStorage.getItem("customLinks"); |
| 124 | + const initialLinks: CustomLink[] = storedLinks ? JSON.parse(storedLinks) : []; |
| 125 | +
|
| 126 | + export const customLinks = writable<CustomLink[]>(initialLinks); |
| 127 | +
|
| 128 | + customLinks.subscribe((links) => { |
| 129 | + localStorage.setItem("customLinks", JSON.stringify(links)); |
| 130 | + }); |
| 131 | +
|
| 132 | + // Functions to manage links |
| 133 | + export function create_custom_link(id: string, name: string, url: string) { |
| 134 | + customLinks.update((links) => [...links, { id, name, url }]); |
| 135 | + } |
| 136 | +
|
| 137 | + export function edit_custom_link(id: string, name: string, url: string) { |
| 138 | + customLinks.update((links) => |
| 139 | + links.map((link) => (link.id === id ? { ...link, name, url } : link)) |
| 140 | + ); |
| 141 | + } |
| 142 | +
|
| 143 | + export function remove_custom_link(id: string) { |
| 144 | + customLinks.update((links) => links.filter((link) => link.id !== id)); |
| 145 | + } |
| 146 | +
|
| 147 | + function addLinkPrompt() { |
| 148 | + const name = prompt("Enter link name:"); |
| 149 | + if (!name) return; |
| 150 | + const url = prompt("Enter link URL:"); |
| 151 | + if (!url) return; |
| 152 | + const id = crypto.randomUUID(); |
| 153 | + create_custom_link(id, name, url); |
| 154 | + } |
| 155 | +
|
| 156 | + function editLinkPrompt(link: { id: string; name: string; url: string }) { |
| 157 | + const name = prompt("Edit link name:", link.name); |
| 158 | + if (!name) return; |
| 159 | + const url = prompt("Edit link URL:", link.url); |
| 160 | + if (!url) return; |
| 161 | + edit_custom_link(link.id, name, url); |
| 162 | + } |
115 | 163 | </script> |
116 | 164 |
|
117 | 165 | <FlexWrapper direction="column" width="100%"> |
|
363 | 411 | <span style="color: var(--token-color-text-secondary); margin-left: var(--token-space-3);">No recent activity.</span> |
364 | 412 | </FlexWrapper> |
365 | 413 |
|
| 414 | +<Space height="var(--token-space-4)" /> |
| 415 | + |
| 416 | +<FlexWrapper alignitems="flex-start" width="80%"> |
| 417 | + <h2>Your links:</h2> |
| 418 | + <FlexWrapper gap="var(--token-space-3)" justifycontent={width > 600 ? "flex-start" : "space-evenly"} direction="row" wrap="wrap"> |
| 419 | + {#each $customLinks as link (link.id)} |
| 420 | + <div class="option"> |
| 421 | + <FlexWrapper width="100%" height="100%" gap="var(--token-space-2)" direction="column" alignitems="center"> |
| 422 | + <a href={link.url} target="_blank"> |
| 423 | + <p class="option-text">{link.name}</p> |
| 424 | + </a> |
| 425 | + <FlexWrapper gap="0.25rem"> |
| 426 | + <button onclick={() => editLinkPrompt(link)}>✏️</button> |
| 427 | + <button onclick={() => remove_custom_link(link.id)}>🗑️</button> |
| 428 | + </FlexWrapper> |
| 429 | + </FlexWrapper> |
| 430 | + </div> |
| 431 | + {/each} |
| 432 | + <!-- Button to add a new link --> |
| 433 | + <div class="option" on:click={addLinkPrompt}> |
| 434 | + <FlexWrapper width="100%" height="100%" justifycontent="center" alignitems="center"> |
| 435 | + <p class="option-text">➕ Add</p> |
| 436 | + </FlexWrapper> |
| 437 | + </div> |
| 438 | + </FlexWrapper> |
| 439 | +</FlexWrapper> |
| 440 | + |
| 441 | + |
366 | 442 | <style> |
367 | 443 | .welcomebox { |
368 | 444 | height: 4rem; |
|
0 commit comments