|
2 | 2 | import FileDropZone from "$lib/common/FileDropZone.svelte"; |
3 | 3 | import FileGallery from "$lib/common/FileGallery.svelte"; |
4 | 4 | import { conversationUserAttachmentStore } from "$lib/helpers/store"; |
5 | | - import { page } from '$app/stores'; |
6 | 5 | import { onMount } from "svelte"; |
7 | 6 |
|
8 | 7 | /** @type {boolean} */ |
|
11 | 10 | /** @type {boolean} */ |
12 | 11 | export let disabled = false; |
13 | 12 |
|
| 13 | + /** @type {any[]} */ |
| 14 | + export let files = []; |
| 15 | +
|
14 | 16 | onMount(() => { |
15 | | - const conversationId = $page.params.conversationId; |
16 | | - const savedAttachments = conversationUserAttachmentStore.get(conversationId); |
| 17 | + const savedAttachments = conversationUserAttachmentStore.get(); |
17 | 18 | files = savedAttachments.acceptedFiles || []; |
18 | 19 | }); |
19 | 20 |
|
20 | | - /** @type {any[]} */ |
21 | | - let files = []; |
22 | | -
|
23 | 21 | /** @param {any} e */ |
24 | 22 | async function handleFileDrop(e) { |
25 | 23 | const { acceptedFiles, fileRejections } = e.detail; |
26 | | - const conversationId = $page.params.conversationId; |
27 | | - const savedAttachments = conversationUserAttachmentStore.get(conversationId); |
| 24 | + const savedAttachments = conversationUserAttachmentStore.get(); |
28 | 25 | const newAttachments = [...savedAttachments.acceptedFiles || [], ...acceptedFiles]; |
29 | | - conversationUserAttachmentStore.put(conversationId, { |
30 | | - conversationId: conversationId, |
| 26 | + conversationUserAttachmentStore.put({ |
31 | 27 | acceptedFiles: newAttachments |
32 | 28 | }); |
33 | 29 | files = newAttachments; |
|
36 | 32 | /** @param {number} index */ |
37 | 33 | function deleteFile(index) { |
38 | 34 | files = files?.filter((f, idx) => idx !== index) || []; |
39 | | - const conversationId = $page.params.conversationId; |
40 | | - conversationUserAttachmentStore.put(conversationId, { |
41 | | - conversationId: conversationId, |
| 35 | + conversationUserAttachmentStore.put({ |
42 | 36 | acceptedFiles: files |
43 | 37 | }); |
44 | 38 | } |
|
0 commit comments