Skip to content
5 changes: 1 addition & 4 deletions cafeWang/src/components/Board/BoardDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ import {
getInfinityScrollBulletinCommentDB,
} from "../../redux/Async/bulletinBoard";

import { whereFrom } from "../../redux/Modules/whereFromSlice";

// 무한스크롤 Hook
import { useInterSectionObserver } from "../../hooks/index";

Expand Down Expand Up @@ -339,7 +337,6 @@ const BoardDetail = ({ boardName }) => {
<UserHashTagItem
key={tag}
onClick={(e) => {
dispatch(whereFrom("cafe"));
dispatch(
getSearchCafeDB({
keyword: tag,
Expand All @@ -349,7 +346,7 @@ const BoardDetail = ({ boardName }) => {
)
.unwrap()
.then(() => {
history.push("/searchmain");
history.push("/searchmain/cafeboard");
});
}}
>
Expand Down
66 changes: 41 additions & 25 deletions cafeWang/src/pages/SearchPage/SearchMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ import { getSearchCafeDB, getSearchBoardDB } from "../../redux/Async/Search";

import { setSorting } from "../../redux/Modules/searchSlice";

//interSectionObserver
import { useInterSectionObserver } from "../../hooks/useIntersectionObserver";
import { useParams } from "react-router";

const SearchMain = () => {
const [popUp, setPopUp] = useState(false);

// 검색페이지를올떄 자유게시판에서 왔는지, 카페 후기게시판에서왔는지를 판단하기위함.
const whereFrom = useParams().wherefrom;
Copy link
Member Author

Choose a reason for hiding this comment

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

useParans훅을 이용하여 해당하는 값을 받아올 수 있어, 이를 활용하여 분기처리시의 기준값으로 설정해줌.


const dispatch = useDispatch();
const isActive = useSelector((state) => state.modal.isActive);
const isFetching = useSelector((state) => state.search.isFetching);
Expand All @@ -34,9 +41,6 @@ const SearchMain = () => {
//현재 게시물이 존재하는지(카페 후기 or 자유게시물 아무거나뭐든)
const isList = useSelector((state) => state.search.isList);

// 검색페이지를올떄 자유게시판에서 왔는지, 카페 후기게시판에서왔는지를 판단하기위함.
const whereFrom = useSelector((state) => state.whereFrom.whereFrom);

const hashTag = useSelector((state) => state.search.hashTag);
const preKeyword = useSelector((state) => state.search.keyword);
const currentSorting = useSelector((state) => state.search.currentSorting);
Expand Down Expand Up @@ -73,7 +77,7 @@ const SearchMain = () => {
setPopUp(false);
}, 700);
} else {
if (whereFrom === "cafe") {
if (whereFrom === "cafeboard") {
dispatch(
getSearchCafeDB({
keyword,
Expand Down Expand Up @@ -107,7 +111,6 @@ const SearchMain = () => {

//처음접속시 인풋창 포커스 & 스크롤 탑 위치
useEffect(() => {

window.scrollTo({
top: 0,
});
Expand All @@ -116,6 +119,7 @@ const SearchMain = () => {
}, []);

//게시물 불러오기(검색된 게시물을 클릭하여 상세페이지로 이동후 뭔가 동작(좋아요,댓글)을 하고 다시 뒤로돌아왔을떄 변경된내용을 반영시키기위해 다시 불러옴)

// 최초에 검색하고 게시물을 불러올떈 동작하지않는다.
useEffect(() => {
// (검색전엔 아무것도 불러오지않은상태니 배열의 길이로 실행여부를 판단함.)
Expand Down Expand Up @@ -160,6 +164,8 @@ const SearchMain = () => {
}
}, []);

//게시물 불러오기(검색된 게시물을 클릭하여 상세페이지로 이동후 뭔가 동작(좋아요,댓글)을 하고 다시 뒤로돌아왔을떄 변경된내용을 반영시키기위해 다시 불러옴)
// 최초에 검색하고 게시물을 불러올떈 동작하지않는다.
useEffect(() => {
if (boardList.length !== 0) {
if (currentSorting === "byDate") {
Expand All @@ -180,10 +186,13 @@ const SearchMain = () => {
}
}, []);

// //무한 스크롤
// const target = useRef(null);
// const [isLoading, setIsLoading] = useState(false);
// const pageRef = useRef(1);

// useInterSectionObserver(fetchMoreData, pageRef, target.current, currentList);



return (
<>
{/* 헤더 */}
Expand Down Expand Up @@ -215,7 +224,11 @@ const SearchMain = () => {
{isActive ? (
""
) : (
<SearchModal isSearch={isSearch} setIsSearch={setIsSearch} />
<SearchModal
isSearch={isSearch}
setIsSearch={setIsSearch}
whereFrom={whereFrom}
/>
)}
</HeaderInner>

Expand Down Expand Up @@ -248,7 +261,7 @@ const SearchMain = () => {
let keyword = null;

// 카페 후기검색일경우 해쉬태그도 생각해야한다.
if (whereFrom === "cafe") {
if (whereFrom === "cafeboard") {
if (hashTag) {
keyword = hashTag;
} else {
Expand Down Expand Up @@ -287,7 +300,7 @@ const SearchMain = () => {

let keyword = null;

if (whereFrom === "cafe") {
if (whereFrom === "cafeboard") {
if (hashTag) {
keyword = hashTag;
} else {
Expand Down Expand Up @@ -320,21 +333,24 @@ const SearchMain = () => {
</SmallFilterButton>
</ButtonInner>
{/* 목록 뿌려주기 */}
{whereFrom === "cafe" ? (
<SearchListInner>
{isFetching && <SpinnerImg src={Spinner} />}
{cafeList.length !== 0 // 검색된결과가 없다면 ( == 받아온 배열의 길이가 0 이라면) "게시물이 없습니다 " 보여줌.
? cafeList.map((cafe) => (
<CafeCard
key={cafe.cafeId}
{...cafe}
_onClick={() => {
history.push(`/cafeboard/detail/${cafe.cafeId}`);
}}
/>
))
: !isFetching && <Blank message="조회된 글이 없습니다." />}
</SearchListInner>
{whereFrom === "cafeboard" ? (
<>
<SearchListInner>
{isFetching && <SpinnerImg src={Spinner} />}
{cafeList.length !== 0 // 검색된결과가 없다면 ( == 받아온 배열의 길이가 0 이라면) "게시물이 없습니다 " 보여줌.
? cafeList.map((cafe) => (
<CafeCard
key={cafe.cafeId}
{...cafe}
_onClick={() => {
history.push(`/cafeboard/detail/${cafe.cafeId}`);
}}
/>
))
: !isFetching && <Blank message="조회된 글이 없습니다." />}
</SearchListInner>
{/* <div ref={target}>{isLoading && "loading..."}</div> */}
</>
) : (
<SearchListInner>
{boardList.length !== 0
Expand Down
11 changes: 4 additions & 7 deletions cafeWang/src/pages/SearchPage/SearchModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ import {
deleteBoardKeyword,
} from "../../redux/Modules/searchSlice";

const SearchModal = ({ isSearch, setIsSearch }) => {
const SearchModal = ({ isSearch, setIsSearch, whereFrom }) => {
const dispatch = useDispatch();

const [popUp, setPopUp] = useState(false);

// 카페 후기게시판 or 자유게시판 중 어디서 왔는지 판단해주는 변수
const whereFrom = useSelector((state) => state.whereFrom.whereFrom);

//카페 후기 최근검색목록 리스트
const cafeSearchList = useSelector((state) => state.search.cafeSearchList);

Expand All @@ -48,7 +45,7 @@ const SearchModal = ({ isSearch, setIsSearch }) => {
{/* 전체삭제 버튼 */}
<DeleteAllButton
onClick={() => {
if (whereFrom === "cafe") {
if (whereFrom === "cafeboard") {
if (cafeSearchList.length === 0) {
setPopUp(true);
setTimeout(() => {
Expand All @@ -73,7 +70,7 @@ const SearchModal = ({ isSearch, setIsSearch }) => {

<SearchWordList>
{/* 카페 후기에서 왔으면 카페 후기 최근검색목록 아니면 자유게시판 최근검색목록 보여주기 */}
{whereFrom === "cafe"
{whereFrom === "cafeboard"
? cafeSearchList.map((keyword) => {
return (
<SearchWordInner key={keyword}>
Expand Down Expand Up @@ -136,7 +133,7 @@ const SearchModal = ({ isSearch, setIsSearch }) => {
</RecentSearchInner>
<>
{/* 해쉬태그검색은 카페 후기검색에만 있는 기능이니 카페 후기게시판에서 이동했는지 확인 */}
{whereFrom === "cafe" && (
{whereFrom === "cafeboard" && (
<>
<Grid margin="16px 0px">
<Text grey>추천 키워드</Text>
Expand Down
8 changes: 0 additions & 8 deletions cafeWang/src/redux/configureStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import cafeBoardSlice from "./Modules/cafeBoardSlice";
import mainPageSlice from "./Modules/mainPageSlice";
import searchSlice from "./Modules/searchSlice";
import popUpSlice from "./Modules/popupSlice";
import whereFromSlice from "./Modules/whereFromSlice";

import { persistReducer } from "redux-persist";
import { persistStore } from "redux-persist";
Expand All @@ -33,12 +32,6 @@ const searchPersistConfig = {
whitelist: ["cafeSearchList", "boardSearchList"],
};

const whereFromPersistConfig = {
key: "whereFrom",
storage: storageSession,
whitelist: ["whereFrom"],
};

const reducer = combineReducers({
router: connectRouter(history),
user: userSlice.reducer,
Expand All @@ -48,7 +41,6 @@ const reducer = combineReducers({
cafeBoard: cafeBoardSlice.reducer,
mainPage: mainPageSlice.reducer,
search: persistReducer(searchPersistConfig, searchSlice.reducer),
whereFrom: persistReducer(whereFromPersistConfig, whereFromSlice.reducer),
popUp: popUpSlice.reducer,
});

Expand Down
8 changes: 4 additions & 4 deletions cafeWang/src/shared/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ function App() {
</ButtonCafe>
</FloatButton>
<WebVer />

<Container>
<Switch>
<PublickRoute path="/" exact component={Tutorial}/>
<PublickRoute path="/intro" exact component={Intro} />
<PublickRoute path="/" exact component={Tutorial} />
<PublickRoute path="/intro" exact component={Intro} />
<PublickRoute path="/login" exact component={Login} />
<PublickRoute path="/signup" exact component={Signup} />
<PublickRoute path="/user/kakao/callback" exact component={Kakao} />
Expand Down Expand Up @@ -122,7 +122,7 @@ function App() {
exact
component={UserPageFollowList}
/>
<PrivateRoute path="/searchmain" component={SearchMain} />
<PrivateRoute path="/searchmain/:wherefrom" component={SearchMain} />
Copy link
Member Author

Choose a reason for hiding this comment

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

검색페이지를 담당하는 컴포넌트의 path주소마지막에 변수를 설정해준다.

<PrivateRoute path="/setting" component={Setting} />
<NotFound />
</Switch>
Expand Down
8 changes: 3 additions & 5 deletions cafeWang/src/shared/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { history } from "../redux/configureStore";
import { useLocation } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
import { resetList } from "./../redux/Modules/searchSlice";
import { whereFrom } from "./../redux/Modules/whereFromSlice";

const Header = (props) => {
const dispatch = useDispatch();
const location = useLocation().pathname;
Expand Down Expand Up @@ -116,9 +116,8 @@ const Header = (props) => {
<IconInner height="24px">
<SearchIcon
onClick={() => {
history.push("/searchmain");
history.push("/searchmain/cafeboard");
Copy link
Member Author

Choose a reason for hiding this comment

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

카페 후기메인페이지에서 이동했을떄.

dispatch(resetList());
dispatch(whereFrom("cafe"));
}}
/>
</IconInner>
Expand Down Expand Up @@ -151,9 +150,8 @@ const Header = (props) => {
<IconInner height="24px">
<SearchIcon
onClick={() => {
history.push("/Searchmain");
history.push("/Searchmain/bulletinboard");
Copy link
Member Author

Choose a reason for hiding this comment

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

자유게시판 후기메인페이지에서 이동했을떄.

dispatch(resetList());
dispatch(whereFrom("Board"));
}}
/>
</IconInner>
Expand Down