feat: query all documents

This commit is contained in:
Timothy J. Baek 2024-02-03 17:21:51 -08:00
parent 3858485675
commit eb2b1ab77b
4 changed files with 27 additions and 18 deletions

View file

@ -468,7 +468,7 @@
<div class="flex flex-col justify-center -space-y-0.5"> <div class="flex flex-col justify-center -space-y-0.5">
<div class=" dark:text-gray-100 text-sm font-medium line-clamp-1"> <div class=" dark:text-gray-100 text-sm font-medium line-clamp-1">
#{file.name} {file?.title ?? `#${file.name}`}
</div> </div>
<div class=" text-gray-500 text-sm">Collection</div> <div class=" text-gray-500 text-sm">Collection</div>

View file

@ -13,34 +13,43 @@
let filteredItems = []; let filteredItems = [];
let filteredDocs = []; let filteredDocs = [];
let filteredTags = [];
let collections = []; let collections = [];
$: collections = $documents $: collections = [
.reduce((a, e, i, arr) => { {
return [...new Set([...a, ...(e?.content?.tags ?? []).map((tag) => tag.name)])]; name: 'All Documents',
}, [])
.map((tag) => ({
name: tag,
type: 'collection', type: 'collection',
collection_names: $documents title: 'All Documents',
.filter((doc) => (doc?.content?.tags ?? []).map((tag) => tag.name).includes(tag)) collection_names: $documents.map((doc) => doc.collection_name)
.map((doc) => doc.collection_name) },
})); ...$documents
.reduce((a, e, i, arr) => {
return [...new Set([...a, ...(e?.content?.tags ?? []).map((tag) => tag.name)])];
}, [])
.map((tag) => ({
name: tag,
type: 'collection',
collection_names: $documents
.filter((doc) => (doc?.content?.tags ?? []).map((tag) => tag.name).includes(tag))
.map((doc) => doc.collection_name)
}))
];
$: filteredCollections = collections $: filteredCollections = collections
.filter((tag) => tag.name.includes(prompt.split(' ')?.at(0)?.substring(1) ?? '')) .filter((collection) => collection.name.includes(prompt.split(' ')?.at(0)?.substring(1) ?? ''))
.sort((a, b) => a.name.localeCompare(b.name)); .sort((a, b) => a.name.localeCompare(b.name));
$: filteredDocs = $documents $: filteredDocs = $documents
.filter((p) => p.name.includes(prompt.split(' ')?.at(0)?.substring(1) ?? '')) .filter((doc) => doc.name.includes(prompt.split(' ')?.at(0)?.substring(1) ?? ''))
.sort((a, b) => a.title.localeCompare(b.title)); .sort((a, b) => a.title.localeCompare(b.title));
$: filteredItems = [...filteredCollections, ...filteredDocs]; $: filteredItems = [...filteredCollections, ...filteredDocs];
$: if (prompt) { $: if (prompt) {
selectedIdx = 0; selectedIdx = 0;
console.log(filteredCollections);
} }
export const selectUp = () => { export const selectUp = () => {
@ -74,7 +83,7 @@
}; };
</script> </script>
{#if filteredDocs.length > 0 || prompt.split(' ')?.at(0)?.substring(1).startsWith('http')} {#if filteredItems.length > 0 || prompt.split(' ')?.at(0)?.substring(1).startsWith('http')}
<div class="md:px-2 mb-3 text-left w-full"> <div class="md:px-2 mb-3 text-left w-full">
<div class="flex w-full rounded-lg border border-gray-100 dark:border-gray-700"> <div class="flex w-full rounded-lg border border-gray-100 dark:border-gray-700">
<div class=" bg-gray-100 dark:bg-gray-700 w-10 rounded-l-lg text-center"> <div class=" bg-gray-100 dark:bg-gray-700 w-10 rounded-l-lg text-center">
@ -101,7 +110,7 @@
> >
{#if doc.type === 'collection'} {#if doc.type === 'collection'}
<div class=" font-medium text-black line-clamp-1"> <div class=" font-medium text-black line-clamp-1">
#{doc.name} {doc?.title ?? `#${doc.name}`}
</div> </div>
<div class=" text-xs text-gray-600 line-clamp-1">Collection</div> <div class=" text-xs text-gray-600 line-clamp-1">Collection</div>

View file

@ -140,7 +140,7 @@
<div class="flex flex-col justify-center -space-y-0.5"> <div class="flex flex-col justify-center -space-y-0.5">
<div class=" dark:text-gray-100 text-sm font-medium line-clamp-1"> <div class=" dark:text-gray-100 text-sm font-medium line-clamp-1">
#{file.name} {file?.title ?? `#${file.name}`}
</div> </div>
<div class=" text-gray-500 text-sm">Collection</div> <div class=" text-gray-500 text-sm">Collection</div>

View file

@ -37,7 +37,7 @@
}; };
const addTagHandler = async (tagName) => { const addTagHandler = async (tagName) => {
if (!tags.find((tag) => tag.name === tagName)) { if (!tags.find((tag) => tag.name === tagName) && tagName !== '') {
tags = [...tags, { name: tagName }]; tags = [...tags, { name: tagName }];
await tagDocByName(localStorage.token, doc.name, { await tagDocByName(localStorage.token, doc.name, {