feat(chat): ignore upper/lower case to select document/tag/collection

This commit is contained in:
Jonathan Rohde 2024-06-24 16:44:44 +02:00
parent f54a66b86b
commit 09e95b8d3c

View File

@ -43,11 +43,11 @@
]; ];
$: filteredCollections = collections $: filteredCollections = collections
.filter((collection) => collection.name.includes(prompt.split(' ')?.at(0)?.substring(1) ?? '')) .filter((collection) => findByName(collection, prompt))
.sort((a, b) => a.name.localeCompare(b.name)); .sort((a, b) => a.name.localeCompare(b.name));
$: filteredDocs = $documents $: filteredDocs = $documents
.filter((doc) => doc.name.includes(prompt.split(' ')?.at(0)?.substring(1) ?? '')) .filter((doc) => findByName(doc, prompt))
.sort((a, b) => a.title.localeCompare(b.title)); .sort((a, b) => a.title.localeCompare(b.title));
$: filteredItems = [...filteredCollections, ...filteredDocs]; $: filteredItems = [...filteredCollections, ...filteredDocs];
@ -58,6 +58,15 @@
console.log(filteredCollections); console.log(filteredCollections);
} }
type ObjectWithName = {
name: string;
};
const findByName = (obj: ObjectWithName, prompt: string) => {
const name = obj.name.toLowerCase();
return name.includes(prompt.toLowerCase().split(' ')?.at(0)?.substring(1) ?? '');
}
export const selectUp = () => { export const selectUp = () => {
selectedIdx = Math.max(0, selectedIdx - 1); selectedIdx = Math.max(0, selectedIdx - 1);
}; };