|
1 | 1 | <script lang="ts">
|
2 | 2 | import type { Message } from "$lib/types/Message";
|
3 |
| - import { createEventDispatcher } from "svelte"; |
| 3 | + import { createEventDispatcher, onDestroy } from "svelte"; |
4 | 4 |
|
5 | 5 | import CarbonSendAltFilled from "~icons/carbon/send-alt-filled";
|
6 | 6 | import CarbonExport from "~icons/carbon/export";
|
7 | 7 | import CarbonStopFilledAlt from "~icons/carbon/stop-filled-alt";
|
8 | 8 | import CarbonClose from "~icons/carbon/close";
|
| 9 | + import CarbonCheckmark from "~icons/carbon/checkmark"; |
9 | 10 |
|
10 | 11 | import EosIconsLoading from "~icons/eos-icons/loading";
|
11 | 12 |
|
|
38 | 39 |
|
39 | 40 | let loginModalOpen = false;
|
40 | 41 | let message: string;
|
| 42 | + let timeout: ReturnType<typeof setTimeout>; |
| 43 | + let isSharedRecently = false; |
| 44 | + $: $page.params.id && (isSharedRecently = false); |
41 | 45 |
|
42 | 46 | const dispatch = createEventDispatcher<{
|
43 | 47 | message: string;
|
|
73 | 77 | $: sources = files.map((file) => file2base64(file));
|
74 | 78 |
|
75 | 79 | const settings = useSettingsStore();
|
| 80 | +
|
| 81 | + function onShare() { |
| 82 | + dispatch("share"); |
| 83 | + isSharedRecently = true; |
| 84 | + if (timeout) { |
| 85 | + clearTimeout(timeout); |
| 86 | + } |
| 87 | + timeout = setTimeout(() => { |
| 88 | + isSharedRecently = false; |
| 89 | + }, 2000); |
| 90 | + } |
| 91 | +
|
| 92 | + onDestroy(() => { |
| 93 | + if (timeout) { |
| 94 | + clearTimeout(timeout); |
| 95 | + } |
| 96 | + }); |
76 | 97 | </script>
|
77 | 98 |
|
78 | 99 | <div class="relative min-h-0 min-w-0">
|
|
226 | 247 | </p>
|
227 | 248 | {#if messages.length}
|
228 | 249 | <button
|
229 |
| - class="flex flex-none items-center hover:text-gray-400 hover:underline max-sm:rounded-lg max-sm:bg-gray-50 max-sm:px-2.5 dark:max-sm:bg-gray-800" |
| 250 | + class="flex flex-none items-center hover:text-gray-400 max-sm:rounded-lg max-sm:bg-gray-50 max-sm:px-2.5 dark:max-sm:bg-gray-800" |
230 | 251 | type="button"
|
231 |
| - on:click={() => dispatch("share")} |
| 252 | + class:hover:underline={!isSharedRecently} |
| 253 | + on:click={onShare} |
| 254 | + disabled={isSharedRecently} |
232 | 255 | >
|
233 |
| - <CarbonExport class="text-[.6rem] sm:mr-1.5 sm:text-primary-500" /> |
234 |
| - <div class="max-sm:hidden">Share this conversation</div> |
| 256 | + {#if isSharedRecently} |
| 257 | + <CarbonCheckmark class="text-[.6rem] sm:mr-1.5 sm:text-green-600" /> |
| 258 | + <div class="text-green-600 max-sm:hidden">Link copied to clipboard</div> |
| 259 | + {:else} |
| 260 | + <CarbonExport class="text-[.6rem] sm:mr-1.5 sm:text-primary-500" /> |
| 261 | + <div class="max-sm:hidden">Share this conversation</div> |
| 262 | + {/if} |
235 | 263 | </button>
|
236 | 264 | {/if}
|
237 | 265 | </div>
|
|
0 commit comments