Skip to content
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
12 changes: 9 additions & 3 deletions frontend/src/components/common/SearchBox/SearchBox.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useRef, useState } from 'react';
import { useSearch } from '@/context/SearchContext';
import { useCategory } from '@/context/CategoryContext';
import useMixpanelTrack from '@/hooks/useMixpanelTrack';
import * as Styled from './SearchBox.styles';
import SearchIcon from '@/assets/images/icons/search_button_icon.svg';
import { useLocation, useNavigate } from 'react-router-dom';

const SearchBox = () => {
const [isSearchBoxClicked, setIsSearchBoxClicked] = useState(false);
const { setKeyword, inputValue, setInputValue } = useSearch();
const { setKeyword, inputValue, setInputValue, setIsSearching } = useSearch();
const { setSelectedCategory } = useCategory();
const trackEvent = useMixpanelTrack();
const navigate = useNavigate();
const location = useLocation();
Expand All @@ -23,6 +25,8 @@ const SearchBox = () => {
const handleSearch = () => {
redirectToHome();
setKeyword(inputValue);
setSelectedCategory('all');
setIsSearching(true);

inputRef.current?.blur();

Expand All @@ -40,7 +44,8 @@ const SearchBox = () => {
return (
<Styled.SearchBoxContainer
$isFocused={isSearchBoxClicked}
onSubmit={handleSubmit}>
onSubmit={handleSubmit}
>
<Styled.SearchInputStyles
ref={inputRef}
type='text'
Expand All @@ -54,7 +59,8 @@ const SearchBox = () => {
<Styled.SearchButton
type='submit'
$isFocused={isSearchBoxClicked}
aria-label='검색'>
aria-label='검색'
>
<img src={SearchIcon} alt='Search Button' />
</Styled.SearchButton>
</Styled.SearchBoxContainer>
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/context/SearchContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ interface SearchContextType {
setKeyword: (keyword: string) => void;
inputValue: string;
setInputValue: (value: string) => void;
isSearching: boolean;
setIsSearching: (isSearching: boolean) => void;
}

interface SearchProviderProps {
Expand All @@ -16,6 +18,7 @@ const SearchContext = createContext<SearchContextType | undefined>(undefined);
export const SearchProvider = ({ children }: SearchProviderProps) => {
const [keyword, setKeyword] = useState<string>('');
const [inputValue, setInputValue] = useState('');
const [isSearching, setIsSearching] = useState(false);

return (
<SearchContext.Provider
Expand All @@ -24,7 +27,10 @@ export const SearchProvider = ({ children }: SearchProviderProps) => {
setKeyword,
inputValue,
setInputValue,
}}>
isSearching,
setIsSearching,
}}
>
{children}
</SearchContext.Provider>
);
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/pages/MainPage/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ const MainPage = () => {
const [isFilterActive, setIsFilterActive] = useState(false);
const { selectedCategory, setSelectedCategory } = useCategory();

const { keyword } = useSearch();
const { keyword, isSearching } = useSearch();
const recruitmentStatus = isFilterActive ? 'OPEN' : 'all';
const division = 'all';
const searchCategory = isSearching ? 'all' : selectedCategory;

const {
data: clubs,
error,
isLoading,
} = useGetCardList(keyword, recruitmentStatus, division, selectedCategory);
} = useGetCardList(keyword, recruitmentStatus, division, searchCategory);
const isEmpty = !isLoading && (!clubs || clubs.length === 0);
const hasData = clubs && clubs.length > 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const clubCategories: Category[] = [
];

const CategoryButtonList = () => {
const { setKeyword, setInputValue } = useSearch();
const { setKeyword, setInputValue, setIsSearching } = useSearch();
const { setSelectedCategory } = useCategory();

const handleCategoryClick = (category: Category) => {
Expand All @@ -71,9 +71,9 @@ const CategoryButtonList = () => {

setKeyword('');
setInputValue('');
setIsSearching(false);

setSelectedCategory(category.id);

};

return (
Expand Down