Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…tend into hotfix/#74/minha
  • Loading branch information
AAminha committed Nov 23, 2023
2 parents bb125f7 + e9d579f commit e21d978
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
8 changes: 7 additions & 1 deletion src/components/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ChangeEvent } from 'react';
import React, { ChangeEvent, useCallback } from 'react';
import styled from 'styled-components';
import SearchImage from '@/assets/icons/icon-search.svg';

Expand All @@ -18,6 +18,11 @@ const SearchBar: React.FC<Props> = ({
const onChange = (e: ChangeEvent<HTMLInputElement>) => {
setSearchInput(e.target.value);
};

const handleFocus = useCallback(() => {
setSearchInput('');
}, []);

return (
<Container
onSubmit={e => {
Expand All @@ -29,6 +34,7 @@ const SearchBar: React.FC<Props> = ({
value={searchInput}
placeholder={placeHolder}
onChange={onChange}
onFocus={handleFocus}
/>
<button type="submit">
<img src={SearchImage} alt="search" />
Expand Down
23 changes: 11 additions & 12 deletions src/pages/board/Board.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import styled from 'styled-components';
import { useQuery } from 'react-query';
Expand All @@ -20,7 +20,7 @@ interface BoardProps {
}

const filterList: string[][] = [
['전체', '여행 지원사업 후기', '여행 대외활동 후기', '여행 공모전 후기'],
['전체', '여행 지원사업 후기', '여행 공모전 후기', '여행 대외활동 후기'],
['전체', '지원서 예시자료', '보고서 예시자료'],
];

Expand All @@ -46,10 +46,9 @@ const Board: React.FC<BoardProps> = ({ title, description }) => {
},
);

useEffect(() => {
// 라우팅이 변경되면 검색 내용 초기화
setSearch('');
}, [boardType]);
const handleSearch = useCallback(() => {
setSearch(searchInput);
}, [searchInput]);

useEffect(() => {
if (location?.state?.filter) {
Expand All @@ -58,8 +57,11 @@ const Board: React.FC<BoardProps> = ({ title, description }) => {
}, [location]);

useEffect(() => {
// 라우팅, 필터가 변경되면 검색 내용 초기화
setSearchInput('');
setSearch('');
window.scrollTo({ top: 0, behavior: 'smooth' });
}, [filter]);
}, [filter, boardType]);

if (isLoading) return <Loading />;

Expand All @@ -83,10 +85,7 @@ const Board: React.FC<BoardProps> = ({ title, description }) => {
placeHolder={'검색어를 입력해 주세요'}
searchInput={searchInput}
setSearchInput={setSearchInput}
handleSubmit={() => {
setSearch(searchInput);
setSearchInput('');
}}
handleSubmit={handleSearch}
/>
</SearchBarWrapper>
<PostingList
Expand All @@ -108,7 +107,7 @@ const Container = styled.div`
width: 1400px;
margin: 0 auto 128px;
body:not(&) {
background-color: white;
}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ const MapPage = () => {
if (isLoading) return <Loading />;

const markerData: markerDataType[] = data?.data?.result
? data?.data?.result?.programs
? data?.data?.result?.programs.filter(
({ remainDay }: { remainDay: string }) => remainDay !== '마감',
)
: [];

return (
Expand Down

0 comments on commit e21d978

Please sign in to comment.