Skip to content

Commit

Permalink
fix(search): search bar history list
Browse files Browse the repository at this point in the history
  • Loading branch information
candicecz committed Oct 24, 2024
1 parent 0536264 commit 610f97b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/components/search-bar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { FaClockRotateLeft, FaXmark } from 'react-icons/fa6';
import React, { useEffect, useMemo, useState } from 'react';
import { FaClockRotateLeft } from 'react-icons/fa6';
import { uniq } from 'lodash';
import dynamic from 'next/dynamic';
import { useRouter } from 'next/router';
Expand Down Expand Up @@ -122,7 +122,10 @@ const SearchBar = ({
query: { q: `${term.trim()}` },
});
};

const historyList = useMemo(
() => [...searchHistory].reverse(),
[searchHistory],
);
return (
<>
<SearchInput
Expand All @@ -134,8 +137,8 @@ const SearchBar = ({
onChange={setSearchTerm}
onSubmit={handleSubmit}
getInputValue={(idx: number): string => {
if (searchHistory && searchHistory[idx]) {
return searchHistory[idx] || '';
if (historyList && historyList[idx]) {
return historyList[idx] || '';
}
return '';
}}
Expand All @@ -158,7 +161,7 @@ const SearchBar = ({
color='primary.600'
fontWeight='medium'
>
{searchHistory.length
{historyList.length
? 'Previous searches'
: 'No previous searches.'}
</Text>
Expand All @@ -170,7 +173,7 @@ const SearchBar = ({
onClick={() => setIsOpen(false)}
/> */}
</ListItem>
{[...searchHistory].reverse().map((str, index) => {
{historyList.map((str, index) => {
return (
<SearchHistoryItem
key={str}
Expand Down

0 comments on commit 610f97b

Please sign in to comment.