|
2 | 2 | import { replaceState } from "$app/navigation";
|
3 | 3 | import { page } from "$app/state";
|
4 | 4 | import { onMount } from "svelte";
|
5 |
| - import { fly } from "svelte/transition"; |
6 | 5 | import { type Client, createClient } from "~/api/client";
|
7 | 6 | import { generateURL } from "~/api/origins.svelte.ts";
|
8 | 7 | import Header from "~/components/header.svelte";
|
|
11 | 10 | import MdiStopCircle from "virtual:icons/mdi/stop-circle";
|
12 | 11 | import MdiGraph from "virtual:icons/mdi/graph";
|
13 | 12 |
|
| 13 | + import Toast from "~/providers/toast/toast.svelte"; |
| 14 | + import { ToastController } from "~/providers/toast/toast-control.svelte.ts"; |
| 15 | +
|
14 | 16 | const client: Client = createClient({ fetch });
|
15 | 17 | const { data } = $props();
|
| 18 | + const toasts = new ToastController(); |
16 | 19 |
|
17 |
| - const newlyCreated = page.url.searchParams.get("created") !== null; |
18 |
| - const justClosed = page.url.searchParams.get("closed") !== null; |
19 |
| - let createdToastShown = $state(false); |
20 |
| - let closedToastShown = $state(false); |
21 | 20 | let closeModalShown = $state(false);
|
22 | 21 | let removeModalShown = $state(false);
|
23 | 22 |
|
24 | 23 | onMount(() => {
|
| 24 | + const newlyCreated = page.url.searchParams.get("created") !== null; |
| 25 | + const justClosed = page.url.searchParams.get("closed") !== null; |
25 | 26 | if (newlyCreated) {
|
26 |
| - createdToastShown = true; |
27 |
| - // replace ?created with none s.t. it won't show "created!" after reload |
28 |
| - const next = new URL(window.location.href); |
29 |
| - next.search = ""; |
30 |
| - setTimeout(() => { |
31 |
| - replaceState(next, {}); |
| 27 | + toasts.push({ |
| 28 | + kind: "success", |
| 29 | + message: "プロジェクトを作成しました。", |
| 30 | + timeout: 2000, |
32 | 31 | });
|
33 |
| - setTimeout(() => { |
34 |
| - createdToastShown = false; |
35 |
| - }, 2000); |
36 | 32 | }
|
37 | 33 | if (justClosed) {
|
38 |
| - closedToastShown = true; |
39 |
| - // replace ?closed with none s.t. it won't show "closed!" after reload |
40 |
| - const next = new URL(window.location.href); |
41 |
| - next.search = ""; |
42 |
| - setTimeout(() => { |
43 |
| - replaceState(next, {}); |
| 34 | + toasts.push({ |
| 35 | + kind: "success", |
| 36 | + message: "提出を締め切りました。", |
| 37 | + timeout: 2000, |
44 | 38 | });
|
45 |
| - setTimeout(() => { |
46 |
| - closedToastShown = false; |
47 |
| - }, 2000); |
48 | 39 | }
|
| 40 | + // replace ?created and ?closed with none s.t. it won't show "closed!" after reload |
| 41 | + const next = new URL(window.location.href); |
| 42 | + next.search = ""; |
| 43 | + setTimeout(() => { |
| 44 | + replaceState(next, {}); |
| 45 | + }); |
49 | 46 | });
|
50 | 47 |
|
51 | 48 | const link = generateURL({
|
52 | 49 | pathname: `${data.projectId}/submit`,
|
53 | 50 | }).href;
|
54 | 51 |
|
55 |
| - let copyTimeout = $state(0); |
56 |
| - onMount(() => { |
57 |
| - const id = setInterval(() => (copyTimeout > 0 ? copyTimeout-- : null), 100); |
58 |
| - return () => clearTimeout(id); |
59 |
| - }); |
| 52 | + let copied = $state(false); |
60 | 53 | </script>
|
61 | 54 |
|
62 | 55 | <Header title="管理" />
|
63 |
| -<div class="mt-3 ml-3 toast-start toast-top absolute"> |
64 |
| - {#if createdToastShown} |
65 |
| - <div class="alert alert-success z-31" transition:fly> |
66 |
| - <span class="z-31">プロジェクトを作成しました。</span> |
67 |
| - </div> |
68 |
| - {/if} |
69 |
| - {#if closedToastShown} |
70 |
| - <div class="alert alert-success z-31" transition:fly> |
71 |
| - <span class="z-31">提出を締め切りました。</span> |
72 |
| - </div> |
73 |
| - {/if} |
74 |
| -</div> |
| 56 | +<Toast {toasts} /> |
75 | 57 |
|
76 | 58 | <main class="hm-blocks-container">
|
77 | 59 | <div class="hm-block">
|
|
93 | 75 | <label class="input input-bordered w-full">
|
94 | 76 | <img alt="" src={chain} class="h-[1rem] opacity-50 select-none" />
|
95 | 77 | <input type="url" class="x-selectable" value={link} readonly />
|
96 |
| - {#if copyTimeout === 0} |
| 78 | + {#if !copied} |
97 | 79 | <button
|
98 | 80 | class="btn btn-sm btn-soft btn-primary"
|
99 | 81 | onclick={async () => {
|
100 | 82 | await navigator.clipboard.writeText(link);
|
101 |
| - copyTimeout = 20; |
| 83 | + setTimeout(() => { |
| 84 | + copied = false; |
| 85 | + }, 2000); |
102 | 86 | }}
|
103 | 87 | >
|
104 | 88 | copy
|
|
0 commit comments