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

템플릿 검색시 엔터를 눌러야 검색되도록 변경 #915

Merged
merged 5 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 0 additions & 1 deletion frontend/src/hooks/template/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { useSourceCode } from './useSourceCode';
export { useTag } from './useTag';
export { useSearchKeyword } from './useSearchKeyword';
8 changes: 0 additions & 8 deletions frontend/src/hooks/template/useSearchKeyword.ts

This file was deleted.

4 changes: 4 additions & 0 deletions frontend/src/pages/MyTemplatesPage/MyTemplatePage.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export const MainContainer = styled.main`
}
`;

export const SearchKeywordPlaceholder = styled.div`
height: 1.5rem;
`;

export const SearchInput = styled(Input)`
box-shadow: inset 1px 2px 8px #00000030;
`;
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/pages/MyTemplatesPage/MyTemplatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useParams } from 'react-router-dom';

import { SORTING_OPTIONS } from '@/api';
import { SearchIcon } from '@/assets/images';
import { Flex, Input, PagingButtons, Dropdown } from '@/components';
import { Flex, Input, PagingButtons, Dropdown, Heading } from '@/components';
import { useAuth } from '@/hooks/authentication';
import { useMemberNameQuery } from '@/queries/members';
import { useTrackPageViewed } from '@/service/amplitude';
Expand Down Expand Up @@ -43,6 +43,7 @@ const MyTemplatePage = () => {
totalPages,
dropdownProps,
keyword,
searchKeyword,
page,
sortingOption,
selectedTagIds,
Expand Down Expand Up @@ -86,6 +87,10 @@ const MyTemplatePage = () => {
/>
)}

<S.SearchKeywordPlaceholder>
<Heading.XSmall color='black'>{searchKeyword ? `'${searchKeyword}' 검색 결과` : ''}</Heading.XSmall>
</S.SearchKeywordPlaceholder>

<Flex width='100%' gap='1rem'>
<S.SearchInput size='medium' variant='text'>
<Input.Adornment>
Expand Down Expand Up @@ -119,7 +124,7 @@ const MyTemplatePage = () => {
{!isTemplateListLoading && (
<TemplateListSection
templateList={templateList}
isSearching={keyword !== ''}
isSearching={keyword !== '' || keyword !== searchKeyword}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyword와 searchKeyword의 변수명 의미가 모호한거 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyword=>inputKeyword, searchKeyword=>searchedKeyword으로 변경하였습니다!

isEditMode={isEditMode}
selectedList={selectedList}
setSelectedList={setSelectedList}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useCallback, useEffect } from 'react';

import { useDropdown, useQueryParams } from '@/hooks';
import { useDropdown, useInput, useQueryParams } from '@/hooks';
import { useAuth } from '@/hooks/authentication';
import { useSearchKeyword } from '@/hooks/template';
import { useTemplateListQuery } from '@/queries/templates';
import { getSortingOptionByValue } from '@/service/getSortingOptionByValue';
import { scroll } from '@/utils';
Expand All @@ -20,7 +19,7 @@ export const useFilteredTemplateList = ({ memberId: passedMemberId }: Props) =>
const selectedTagIds = queryParams.tags;
const page = queryParams.page;
const { currentValue: sortingOption, ...dropdownProps } = useDropdown(getSortingOptionByValue(queryParams.sort));
const { keyword, debouncedKeyword, handleKeywordChange } = useSearchKeyword(queryParams.keyword);
const [keyword, handleKeywordChange] = useInput(queryParams.keyword);

const { memberInfo } = useAuth();
const memberId = passedMemberId ?? memberInfo.memberId;
Expand All @@ -33,7 +32,7 @@ export const useFilteredTemplateList = ({ memberId: passedMemberId }: Props) =>
memberId,
categoryId: selectedCategoryId,
tagIds: selectedTagIds,
keyword: debouncedKeyword,
keyword: queryParams.keyword,
sort: sortingOption.key,
page,
});
Expand All @@ -49,14 +48,6 @@ export const useFilteredTemplateList = ({ memberId: passedMemberId }: Props) =>
updateQueryParams({ sort: sortingOption.value, page: FIRST_PAGE });
}, [queryParams.sort, sortingOption, updateQueryParams]);

useEffect(() => {
if (queryParams.keyword === debouncedKeyword) {
return;
}

updateQueryParams({ keyword: debouncedKeyword, page: FIRST_PAGE });
}, [queryParams.keyword, debouncedKeyword, updateQueryParams]);

const handlePageChange = (page: number) => {
scroll.top('smooth');

Expand All @@ -80,6 +71,8 @@ export const useFilteredTemplateList = ({ memberId: passedMemberId }: Props) =>
const handleSearchSubmit = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') {
updateQueryParams({ page: FIRST_PAGE });

updateQueryParams({ keyword, page: FIRST_PAGE });
}
};

Expand All @@ -90,6 +83,7 @@ export const useFilteredTemplateList = ({ memberId: passedMemberId }: Props) =>
totalPages,
dropdownProps,
keyword,
searchKeyword: queryParams.keyword,
page,
sortingOption,
selectedTagIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ export const TemplateListSectionWrapper = styled.div`
position: relative;
width: 100%;
`;

export const SearchKeywordPlaceholder = styled.div`
height: 1.5rem;
`;
21 changes: 8 additions & 13 deletions frontend/src/pages/TemplateExplorePage/TemplateExplorePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TemporaryError,
TemplateCard,
} from '@/components';
import { useDebounce, useDropdown, useInput, useQueryParams, useWindowWidth } from '@/hooks';
import { useDropdown, useInput, useQueryParams, useWindowWidth } from '@/hooks';
import { useTemplateExploreQuery } from '@/queries/templates';
import { useTrackPageViewed } from '@/service/amplitude';
import { getSortingOptionByValue } from '@/service/getSortingOptionByValue';
Expand Down Expand Up @@ -48,8 +48,6 @@ const TemplateExplorePage = () => {

const [keyword, handleKeywordChange] = useInput(queryParams.keyword);

const debouncedKeyword = useDebounce(keyword, 300);

const { currentValue: sortingOption, ...dropdownProps } = useDropdown(getSortingOptionByValue(queryParams.sort));

const { selectedTagIds, selectedHotTopic, selectTopic } = useHotTopic();
Expand All @@ -62,22 +60,15 @@ const TemplateExplorePage = () => {
updateQueryParams({ sort: sortingOption.value, page: FIRST_PAGE });
}, [queryParams.sort, sortingOption, updateQueryParams]);

useEffect(() => {
if (queryParams.keyword === debouncedKeyword) {
return;
}

updateQueryParams({ keyword: debouncedKeyword, page: FIRST_PAGE });
}, [queryParams.keyword, debouncedKeyword, updateQueryParams]);

const handleSearchSubmit = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter') {
handlePage(FIRST_PAGE);
updateQueryParams({ keyword, page: FIRST_PAGE });
}
};

return (
<Flex direction='column' gap='4rem' align='flex-start' css={{ paddingTop: '5rem' }}>
<Flex direction='column' gap='1.5rem' align='flex-start' css={{ paddingTop: '5rem' }}>
<Flex direction='column' justify='flex-start' gap='1rem' width='100%'>
{isMobile ? (
<Heading.XSmall color='black'>
Expand All @@ -91,6 +82,10 @@ const TemplateExplorePage = () => {
<HotTopicCarousel selectTopic={selectTopic} selectedHotTopic={selectedHotTopic} />
</Flex>

<S.SearchKeywordPlaceholder>
<Heading.XSmall color='black'>{queryParams.keyword ? `'${queryParams.keyword}' 검색 결과` : ''}</Heading.XSmall>
</S.SearchKeywordPlaceholder>

<Flex width='100%' gap='1rem'>
<S.SearchInput size='medium' variant='text'>
<Input.Adornment>
Expand Down Expand Up @@ -121,7 +116,7 @@ const TemplateExplorePage = () => {
page={page}
handlePage={handlePage}
sortingOption={sortingOption}
keyword={debouncedKeyword}
keyword={queryParams.keyword}
tagIds={selectedTagIds}
/>
</ErrorBoundary>
Expand Down