Skip to content

Commit

Permalink
Merge pull request #5 from christianhellsten/v0.5
Browse files Browse the repository at this point in the history
Search both content and title
  • Loading branch information
christianhellsten authored Dec 26, 2023
2 parents b49d358 + d8c0159 commit 95d9df4
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion css/Sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}

#search-input {
padding-left: 1.5rem;
padding-left: .75rem;
}

#sidebar.collapsed {
Expand Down
19 changes: 12 additions & 7 deletions js/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,20 @@ export class Sidebar {
function escapeRegExp (string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // Escapes special characters
}

const query = escapeRegExp(this.searchInput.value.trim()).replace(/\s+/g, '.*')
const queryContent = query.length > 2 // Nobody wants to query content based on one character?
const regex = new RegExp(query, 'i') // 'i' for case-insensitive matching
const chatItems = this.element.querySelectorAll('.chat-list-item')
chatItems.forEach(function (item) {
const title = item.textContent.toLowerCase()
const match = regex.test(title)
// console.log(`Search ${regex} ${title}`)
if (match) {
console.log(`${query}`)
// TODO: Optimize data model :)
const matches = this.chats.chats.filter(chat => {
let match = regex.test(chat.title)
if (queryContent) {
match ||= regex.test(chat.content)
}
return match
}).map(chat => chat.id)
this.element.querySelectorAll('.chat-list-item').forEach(item => {
if (matches.includes(item.data.id)) { // Now matches the type
item.classList.remove('hidden')
} else {
item.classList.add('hidden')
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "Ollama HTML UI",
"type": "module",
"browserslist": "> 0.5%, last 2 versions, not dead",
"scripts": {
"server": "node scripts/server.js",
"test": "node --test --test-reporter=spec",
Expand Down
Binary file modified screenshots/chat-collapsed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/chat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/mobile-chat-collapsed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/mobile-chat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/mobile-search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 95d9df4

Please sign in to comment.