diff --git a/src/lib/components/workspace/Knowledge/Collection.svelte b/src/lib/components/workspace/Knowledge/Collection.svelte index e343c0099..363ce3dc7 100644 --- a/src/lib/components/workspace/Knowledge/Collection.svelte +++ b/src/lib/components/workspace/Knowledge/Collection.svelte @@ -26,6 +26,7 @@ import { blobToFile } from '$lib/utils'; import { processFile } from '$lib/apis/retrieval'; import AddContentMenu from './Collection/AddContentMenu.svelte'; + import AddTextContentModal from './Collection/AddTextContentModal.svelte'; let largeScreen = true; @@ -43,6 +44,9 @@ let knowledge: Knowledge | null = null; let query = ''; + let showAddTextContentModal = false; + let inputFiles = null; + let selectedFile = null; let selectedFileId = null; @@ -58,6 +62,14 @@ let mediaQuery; let dragged = false; + const createFileFromText = (name, content) => { + const blob = new Blob([content], { type: 'text/plain' }); + const file = blobToFile(blob, `${name}.md`); + + console.log(file); + return file; + }; + const uploadFileHandler = async (file) => { console.log(file); @@ -232,6 +244,38 @@ {/if} + { + const file = createFileFromText(e.detail.name, e.detail.content); + uploadFileHandler(file); + }} +/> + + { + if (inputFiles && inputFiles.length > 0) { + for (const file of inputFiles) { + uploadFileHandler(file); + } + + inputFiles = null; + const fileInputElement = document.getElementById('files-input'); + + if (fileInputElement) { + fileInputElement.value = ''; + } + } else { + toast.error($i18n.t(`File not found.`)); + } + }} +/> +
diff --git a/src/lib/components/workspace/Knowledge/Collection/AddTextContentModal.svelte b/src/lib/components/workspace/Knowledge/Collection/AddTextContentModal.svelte index b5f09be5c..5012bf997 100644 --- a/src/lib/components/workspace/Knowledge/Collection/AddTextContentModal.svelte +++ b/src/lib/components/workspace/Knowledge/Collection/AddTextContentModal.svelte @@ -1,42 +1,19 @@ - +
{$i18n.t('Add Content')}
@@ -63,32 +40,45 @@
{ - submitHandler(); + dispatch('submit', { + name, + content + }); + show = false; + name = ''; + content = ''; }} >
- +
+
+
Title
- +
+ +
+
+ +
+
Content
+ +
+