Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: loadSearchData on focus & show loading only once #1915

Merged
merged 1 commit into from
Sep 26, 2023
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
4 changes: 1 addition & 3 deletions src/client/theme-api/useSiteSearch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ if (typeof window !== 'undefined') {

export const useSiteSearch = () => {
const debounceTimer = useRef<number>();
// const routes = useLocaleDocRoutes();
// const { demos } = useSiteData();
const [loading, setLoading] = useState(false);
const [loading, setLoading] = useState(true);
const [keywords, setKeywords] = useState('');
const [enabled, setEnabled] = useState(false);
const navData = useNavData();
Expand Down
1 change: 1 addition & 0 deletions src/client/theme-default/slots/SearchBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const SearchBar: FC = () => {
<Input
onFocus={() => {
setFocusing(true);
loadSearchData();
}}
onMouseEnter={() => {
loadSearchData();
Expand Down
9 changes: 8 additions & 1 deletion src/client/theme-default/slots/SearchResult/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ const SearchResult: FC<{
}> = (props) => {
const [data, histsCount] = useFlatSearchData(props.data);
const [activeIndex, setActiveIndex] = useState(-1);
const [loading, setLoading] = useState(props.loading);

useEffect(() => {
if (!props.loading) {
setLoading(false);
}
}, [props.loading]);

useEffect(() => {
const handler = (ev: KeyboardEvent) => {
Expand Down Expand Up @@ -149,7 +156,7 @@ const SearchResult: FC<{

let returnNode: React.ReactNode = null;

if (props.loading) {
if (loading) {
returnNode = (
<div className="dumi-default-search-empty">
<IconInbox />
Expand Down
Loading