Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
270 changes: 0 additions & 270 deletions src/app/upload/page_not_AI.tsx

This file was deleted.

13 changes: 10 additions & 3 deletions src/components/Searchbar/searchbar-child.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useState, useRef, useEffect } from "react";
import { Search } from "lucide-react";
import { useRouter } from "next/navigation";
import { Input } from "@/components/ui/input";
import Fuse from "fuse.js";

function SearchBarChild({
initialSubjects,
Expand All @@ -16,15 +17,21 @@ function SearchBarChild({
const [searchText, setSearchText] = useState("");
const [suggestions, setSuggestions] = useState<string[]>([]);
const suggestionsRef = useRef<HTMLUListElement | null>(null);
const fuzzy = new Fuse(initialSubjects);

const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const text = e.target.value;
setSearchText(text);

if (text.length > 1 && initialSubjects.length > 0) {
const filteredSuggestions = initialSubjects.filter((subject) =>
subject.toLowerCase().includes(text.toLowerCase()),
);
const filteredSuggestions = fuzzy
.search(text)
.sort((a, b) => {
return (a.score ?? Infinity) - (b.score ?? Infinity); // Use Infinity for undefined scores
})
.map((item) => item.item)
.slice(0, 10);

setSuggestions(filteredSuggestions);
} else {
setSuggestions([]);
Expand Down
Loading