Skip to content

Commit

Permalink
frontend: switch quick search to act on the old recent cards
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSavage committed Dec 11, 2024
1 parent fb275cd commit d168776
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
25 changes: 0 additions & 25 deletions zettelkasten-front/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,11 @@ import { FileUpload } from "../components/files/FileUpload";
export function Sidebar() {
const navigate = useNavigate();
const location = useLocation();
const currentPath = location.pathname;

const [filter, setFilter] = useState<string>("");
const [message, setMessage] = useState<string>("");
const { partialCards, lastCard } = usePartialCardContext();
const { tasks } = useTaskContext();
const username = localStorage.getItem("username");
const [isNewDropdownOpen, setIsNewDropdownOpen] = useState(false);
const [filteredCards, setFilteredCards] = useState<PartialCard[]>([]);
const [chatConversations, setChatConversations] = useState<
ConversationSummary[]
>([]);
Expand All @@ -54,15 +50,6 @@ export function Sidebar() {
setShowQuickSearchWindow,
} = useShortcutContext();

const mainCards = useMemo(
() => partialCards.filter((card) => !card.card_id.includes("/")),
[partialCards],
);

useEffect(() => {
setFilteredCards(mainCards.slice(0, 100));
}, [mainCards]);

function getCurrentCard(): PartialCard | Card | null {
const location = useLocation();
const currentPath = location.pathname;
Expand Down Expand Up @@ -101,18 +88,6 @@ export function Sidebar() {
[tasks],
);

async function handleFilter(text: string) {
setFilter(text);
if (text == "") {
setFilteredCards(mainCards.slice(0, 100));
}
await fetchPartialCards(text, "date").then((data) => {
setFilteredCards(
data === null ? [] : data.filter((card) => !card.card_id.includes("/")),
);
});
}

const handleKeyPress = (event: KeyboardEvent) => {
// if this is true, the user is using a system shortcut, don't do anything with it
if (event.metaKey) {
Expand Down
13 changes: 9 additions & 4 deletions zettelkasten-front/src/components/cards/QuickSearchWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { quickFilterCards } from "../../utils/cards";
import { PartialCard } from "../../models/Card";
import { useNavigate } from "react-router-dom";

import { fetchPartialCards } from "../../api/cards";

interface QuickSearchWindowProps {
setShowWindow: (showWindow: boolean) => void;
}
Expand All @@ -21,15 +23,18 @@ export function QuickSearchWindow({ setShowWindow }: QuickSearchWindowProps) {
navigate(`/app/card/${card.id}`);
}

function handleLinkInputChange(e: React.ChangeEvent<HTMLInputElement>) {
async function handleLinkInputChange(e: React.ChangeEvent<HTMLInputElement>) {
setLink(e.target.value);
const search = e.target.value; // assuming you want case-insensitive matching
console.log(search);
setSearchTerm(search);
if (search !== "") {
let results = quickFilterCards(partialCards, search);
console.log(results);
setTopResults(results);

await fetchPartialCards(search, "date").then((data) => {
setTopResults(
data === null ? [] : data.filter((card) => !card.card_id.includes("/")),
);
});
} else {
setTopResults([]);
}
Expand Down

0 comments on commit d168776

Please sign in to comment.