Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter committed Feb 6, 2025
1 parent 19ab890 commit dafb8df
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/theme-default/src/components/Search/SearchPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import * as userSearchHooks from 'virtual-search-hooks';
import { useLocaleSiteData } from '../../logic/useLocaleSiteData';
import { getSidebarGroupData } from '../../logic/useSidebarData';
import { getSidebarData } from '../../logic/useSidebarData';
import { SvgWrapper } from '../SvgWrapper';
import { Tab, Tabs } from '../Tabs';
import { NoSearchResult } from './NoSearchResult';
Expand Down Expand Up @@ -123,7 +123,7 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {

// We need to extract the group name by the link so that we can divide the search result into different groups.
const extractGroupName = (link: string) =>
getSidebarGroupData(sidebar, link).group;
getSidebarData(sidebar, link).group;

async function initPageSearcher() {
if (search === false) {
Expand Down
4 changes: 2 additions & 2 deletions packages/theme-default/src/logic/useFullTextSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from 'react';
import type { MatchResult } from '..';
import { PageSearcher } from '../components/Search/logic/search';
import { useLocaleSiteData } from './useLocaleSiteData';
import { getSidebarGroupData } from './useSidebarData';
import { getSidebarData } from './useSidebarData';

export function useFullTextSearch(): {
initialized: boolean;
Expand All @@ -13,7 +13,7 @@ export function useFullTextSearch(): {
const [initialized, setInitialized] = useState(false);
const { sidebar } = useLocaleSiteData();
const extractGroupName = (link: string) =>
getSidebarGroupData(sidebar, link).group;
getSidebarData(sidebar, link).group;
const searchRef = useRef<PageSearcher | null>(null);

useEffect(() => {
Expand Down
11 changes: 4 additions & 7 deletions packages/theme-default/src/logic/useSidebarData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,12 @@ const match = (
return undefined;
};

export const getSidebarGroupData = (
export const getSidebarData = (
sidebar: NormalizedSidebar,
currentPathname: string,
) => {
console.log(sidebar, 111111);
): SidebarData => {
for (const name of Object.keys(sidebar)) {
const isMatch = matchPath(name, currentPathname);
console.log(isMatch, name, currentPathname);
if (isMatch) {
if (matchPath(name, currentPathname)) {
const sidebarGroup = sidebar[name];
const group = sidebarGroup.find(item => match(item, currentPathname));
return {
Expand All @@ -105,7 +102,7 @@ export function useSidebarData(): SidebarData {
const pathname = decodeURIComponent(rawPathname);

const sidebarData = useMemo(() => {
return getSidebarGroupData(sidebar, pathname);
return getSidebarData(sidebar, pathname);
}, [sidebar, pathname]);

return sidebarData;
Expand Down

0 comments on commit dafb8df

Please sign in to comment.