feat: improving suggestion dropdown design

This commit is contained in:
Moyasee
2025-11-22 07:26:48 +02:00
parent 093a9f251e
commit a1117c8269
3 changed files with 21 additions and 26 deletions

View File

@@ -24,7 +24,8 @@
display: flex;
align-items: center;
justify-content: space-between;
padding: 8px 12px 4px;
padding: 8px 12px 8px;
margin-bottom: 4px;
}
&__section-title {
@@ -35,19 +36,15 @@
letter-spacing: 0.5px;
}
&__clear-button {
&__clear-text-button {
color: globals.$muted-color;
cursor: pointer;
padding: 4px;
border-radius: 4px;
transition: all ease 0.2s;
display: flex;
align-items: center;
justify-content: center;
padding: 2px 6px;
font-size: 11px;
transition: color ease 0.2s;
&:hover {
color: #dadbe1;
background-color: rgba(255, 255, 255, 0.1);
}
}
@@ -74,18 +71,11 @@
transform: translateY(-50%);
color: globals.$muted-color;
padding: 4px;
border-radius: 4px;
opacity: 0;
transition: all ease 0.15s;
transition: opacity ease 0.15s;
display: flex;
align-items: center;
justify-content: center;
background-color: transparent;
&:hover {
color: #ff5555;
background-color: rgba(255, 85, 85, 0.1);
}
}
&__item {

View File

@@ -1,11 +1,6 @@
import { useEffect, useRef, useCallback, useState } from "react";
import { createPortal } from "react-dom";
import {
ClockIcon,
SearchIcon,
TrashIcon,
XIcon,
} from "@primer/octicons-react";
import { ClockIcon, SearchIcon, XIcon } from "@primer/octicons-react";
import cn from "classnames";
import { useTranslation } from "react-i18next";
import type { SearchHistoryEntry } from "@renderer/hooks/use-search-history";
@@ -144,11 +139,10 @@ export function SearchDropdown({
</span>
<button
type="button"
className="search-dropdown__clear-button"
className="search-dropdown__clear-text-button"
onClick={onClearHistory}
title={t("clear_history")}
>
<TrashIcon size={14} />
clear
</button>
</div>
<ul className="search-dropdown__list">

View File

@@ -19,6 +19,7 @@ export function useSearchSuggestions(
const [isLoading, setIsLoading] = useState(false);
const library = useAppSelector((state) => state.library.value);
const abortControllerRef = useRef<AbortController | null>(null);
const cacheRef = useRef<Map<string, SearchSuggestion[]>>(new Map());
const getLibrarySuggestions = useCallback(
(searchQuery: string, limit: number = 3): SearchSuggestion[] => {
@@ -67,6 +68,15 @@ export function useSearchSuggestions(
return;
}
const cacheKey = `${searchQuery.toLowerCase()}_${limit}`;
const cachedResults = cacheRef.current.get(cacheKey);
if (cachedResults) {
setSuggestions(cachedResults);
setIsLoading(false);
return;
}
abortControllerRef.current?.abort();
const abortController = new AbortController();
abortControllerRef.current = abortController;
@@ -98,6 +108,7 @@ export function useSearchSuggestions(
})
);
cacheRef.current.set(cacheKey, catalogueSuggestions);
setSuggestions(catalogueSuggestions);
} catch (error) {
if (!abortController.signal.aborted) {