From aed2caefe1c4e906b79d3e0ef4b5966ce5974e51 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 30 Nov 2024 15:44:04 -0800 Subject: [PATCH] refac --- src/lib/components/common/FileItem.svelte | 95 +++-- .../components/common/RichTextInput.svelte | 24 +- .../workspace/Knowledge/KnowledgeBase.svelte | 394 ++++++++---------- .../Knowledge/KnowledgeBase/Files.svelte | 3 + 4 files changed, 256 insertions(+), 260 deletions(-) diff --git a/src/lib/components/common/FileItem.svelte b/src/lib/components/common/FileItem.svelte index 733623c17..2e00ef220 100644 --- a/src/lib/components/common/FileItem.svelte +++ b/src/lib/components/common/FileItem.svelte @@ -5,6 +5,7 @@ import FileItemModal from './FileItemModal.svelte'; import GarbageBin from '../icons/GarbageBin.svelte'; import Spinner from './Spinner.svelte'; + import Tooltip from './Tooltip.svelte'; const i18n = getContext('i18n'); const dispatch = createEventDispatcher(); @@ -18,6 +19,7 @@ export let item = null; export let edit = false; + export let small = false; export let name: string; export let type: string; @@ -31,7 +33,7 @@ {/if} - - {/if} - -
- - {selectedFile?.meta?.name} - -
- -
- -
- - -
- {#key selectedFile.id} - - {/key} -
- - {:else} -
- {/if} - - - {:else if !largeScreen && selectedFileId !== null} - { - selectedFileId = null; - }} - > -
-
-
-
+
+ {#if largeScreen} +
+ {#if selectedFile} +
+
+ {#if !showSidepanel} +
-
- {selectedFile?.meta?.name} -
+ {/if} -
- -
+ -
- {#key selectedFile.id} - + +
+
+ +
+ {#key selectedFile.id} + + {/key} +
+
+ {:else} +
+
+ {$i18n.t('Drag and drop a file to upload or select a file to view')} +
+
+ {/if} +
+ {:else if !largeScreen && selectedFileId !== null} + { + selectedFileId = null; + }} + > +
+
+
+
+ +
+
+ {selectedFile?.meta?.name} +
+ +
+ +
+
+ +
+ {#key selectedFile.id} + + {/key} +
+
+
+
+ {/if} + +
+
+
+
+
+
+ + - {/key} + +
+ { + selectedFileId = null; + }} + /> + +
+ { + if (e.detail.type === 'directory') { + uploadDirectoryHandler(); + } else if (e.detail.type === 'text') { + showAddTextContentModal = true; + } else { + document.getElementById('files-input').click(); + } + }} + on:sync={(e) => { + showSyncConfirmModal = true; + }} + />
- - {/if} - + + {#if filteredItems.length > 0} +
+ { + selectedFileId = selectedFileId === e.detail ? null : e.detail; + }} + on:delete={(e) => { + console.log(e.detail); + + selectedFileId = null; + deleteFileHandler(e.detail); + }} + /> +
+ {:else} +
+
+ {$i18n.t('No content found')} +
+
+ {/if} +
+
+
{:else} diff --git a/src/lib/components/workspace/Knowledge/KnowledgeBase/Files.svelte b/src/lib/components/workspace/Knowledge/KnowledgeBase/Files.svelte index 288d398d1..bdc3371da 100644 --- a/src/lib/components/workspace/Knowledge/KnowledgeBase/Files.svelte +++ b/src/lib/components/workspace/Knowledge/KnowledgeBase/Files.svelte @@ -6,6 +6,8 @@ export let selectedFileId = null; export let files = []; + + export let small = false;
@@ -16,6 +18,7 @@ colorClassName="{selectedFileId === file.id ? ' bg-gray-50 dark:bg-gray-850' : 'bg-transparent'} hover:bg-gray-50 dark:hover:bg-gray-850 transition" + {small} {file} name={file?.name ?? file?.meta?.name} type="file"