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

[Refactor] 셰어/마인더 상담 목록 페이지 뷰 쿼리스트링 상태에 맞게 매칭 #188

Merged
merged 14 commits into from
Mar 23, 2024
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
4 changes: 4 additions & 0 deletions src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import { BuyerChat } from 'pages/Buyer/BuyerChat';
import Service from 'pages/Common/Service';
import { BuyerQuit } from 'pages/Buyer/BuyerQuit';
import { SellerChatTemp } from 'pages/Seller/SellerChatTemp';
import BuyerOpenConsult from 'pages/Buyer/BuyerOpenConsult';
import SellerOpenConsult from 'pages/Seller/SellerOpenConsult';
const Router = () => {
return (
<Routes>
Expand All @@ -54,6 +56,7 @@ const Router = () => {
<Route path="/share" element={<BuyerHome />} />
<Route path="/" element={<BuyerHome />} />
<Route path="/consult" element={<BuyerConsult />} />
<Route path="/open-consult" element={<BuyerOpenConsult />} />
<Route path="/profile/:id" element={<BuyerCounselorProfile />} />
<Route path="/search" element={<BuyerSearch />} />
<Route path="/categorySearch" element={<BuyerCategoryResult />} />
Expand Down Expand Up @@ -108,6 +111,7 @@ const Router = () => {
/>

<Route path="/minder/consult" element={<SellerConsult />} />
<Route path="/minder/open-consult" element={<SellerOpenConsult />} />
{/* 판매자 : 프로필 정보 */}
<Route path="/minder/mypage" element={<SellerMypage />} />

Expand Down
3 changes: 3 additions & 0 deletions src/assets/icons/icon-comment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/icon-heart3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions src/assets/icons/icon-lock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/icons/icon-save3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/underline-big.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/components/Buyer/BuyerConsult/BuyerChatSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const BuyerChatSection = ({
* https://stackoverflow.com/questions/73896315/rxjs-subscribe-callback-doesnt-have-access-to-current-react-state-functional-c
*/
const cardDataRef = useRef<consultApiObject[]>([]);
const { stompClient } = useStompContext();
const { stompClient, isConnected } = useStompContext();
//채팅 readId, 가장 최근 unread message, 정렬 업데이트
const updateChatData = (
chatId: number,
Expand Down Expand Up @@ -148,6 +148,7 @@ export const BuyerChatSection = ({
sendConnectRequest();

return () => {
console.log('unmount');
if (roomIdsRef.current) {
roomIdsRef.current.forEach((value) => {
stompClient.current?.unsubscribe(
Expand All @@ -161,7 +162,7 @@ export const BuyerChatSection = ({
);
}
};
}, [stompClient]);
}, [stompClient, isConnected]);

useLayoutEffect(() => {
const fetchData = async () => {
Expand Down
18 changes: 15 additions & 3 deletions src/components/Buyer/BuyerConsult/ConsultModal.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import { ReactComponent as CheckIcon } from 'assets/icons/icon-modal-check.svg';
import { SetStateAction, useEffect, useState } from 'react';
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
import { SetStateAction, useState } from 'react';
import { useRecoilState, useSetRecoilState } from 'recoil';
import styled, { keyframes } from 'styled-components';
import { Green, Grey1, Grey6 } from 'styles/color';
import { Body1 } from 'styles/font';
import { isConsultModalOpenState, scrollLockState } from 'utils/atom';
import { ReactComponent as Bar } from 'assets/icons/icon-modal-bar.svg';
import { SetURLSearchParams } from 'react-router-dom';
interface SortModalProps {
sortType: number;
setSortType: React.Dispatch<SetStateAction<number>>;
searchParams: URLSearchParams;
setSearchParams: SetURLSearchParams;
}

//최근순 읽지않은순 modal
export const ConsultModal = ({ sortType, setSortType }: SortModalProps) => {
export const ConsultModal = ({
sortType,
setSortType,
searchParams,
setSearchParams,
}: SortModalProps) => {
//modal 여부
const [isModalOpen, setIsModalOpen] = useRecoilState(isConsultModalOpenState);
//여기서 unmount 시 sortType 바꾸고 새로 request
Expand All @@ -34,6 +42,8 @@ export const ConsultModal = ({ sortType, setSortType }: SortModalProps) => {
className="row"
onClick={() => {
setSortType(0);
searchParams.set('sort', 'latest');
setSearchParams(searchParams);
setIsModalOpen(false);
setScrollLock(false);
}}
Expand All @@ -51,6 +61,8 @@ export const ConsultModal = ({ sortType, setSortType }: SortModalProps) => {
className="row"
onClick={() => {
setSortType(1);
searchParams.set('sort', 'unread');
setSearchParams(searchParams);
setIsModalOpen(false);
setScrollLock(false);
}}
Expand Down
39 changes: 34 additions & 5 deletions src/components/Common/TabA1.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from 'styled-components';
import { ReactComponent as UnderLineBuyer } from 'assets/icons/underline-buyer.svg';
import { ReactComponent as UnderLineBuyerBig } from 'assets/icons/underline-big.svg';
import { Subtitle } from 'styles/font';
import { Black, Green, Grey6 } from 'styles/color';
import { useEffect, useState } from 'react';
Expand All @@ -24,6 +25,7 @@ export const TabA1 = ({ isBuyer, initState }: TabA1Props) => {
return (
<Wrapper>
<TabButton
tabState={1}
onClick={() => {
setTabState(1);
if (isBuyer) {
Expand All @@ -43,6 +45,7 @@ export const TabA1 = ({ isBuyer, initState }: TabA1Props) => {
)}
</TabButton>
<TabButton
tabState={2}
onClick={() => {
setTabState(2);
if (isBuyer) {
Expand All @@ -61,8 +64,28 @@ export const TabA1 = ({ isBuyer, initState }: TabA1Props) => {
<Subtitle color={Black}>상담</Subtitle>
)}
</TabButton>
<TabButton>
<TabButton
tabState={3}
onClick={() => {
setTabState(3);
if (isBuyer) {
navigate('/open-consult');
} else {
navigate('/minder/open-consult');
}
}}
>
{tabState === 3 ? (
<>
<Subtitle color={color}>공개상담</Subtitle>
<UnderLineBuyerBig />
</>
) : (
<Subtitle color={Black}>공개상담</Subtitle>
)}
</TabButton>
<TabButton tabState={4}>
{tabState === 4 ? (
<>
<Subtitle color={color}>내 정보</Subtitle>
<UnderLineBuyer />
Expand All @@ -71,7 +94,7 @@ export const TabA1 = ({ isBuyer, initState }: TabA1Props) => {
<Subtitle
color={Black}
onClick={() => {
setTabState(3);
setTabState(4);
if (isBuyer) {
navigate('/mypage');
} else {
Expand All @@ -91,17 +114,23 @@ const Wrapper = styled.div`
height: 4.4rem;
display: flex;
justify-content: center;
gap: 12%;
border-bottom: 1px solid ${Grey6};
position: sticky;
top: 6rem;
background-color: white;
z-index: 999;
`;
const TabButton = styled.div`
const TabButton = styled.div<{ tabState: number }>`
display: flex;
flex-direction: column;
width: 6.5rem;
width: ${(props) =>
props?.tabState === 1
? '8.8rem'
: props?.tabState === 2
? '8.2rem'
: props?.tabState === 3
? '10.9rem'
: '9.6rem'};
align-items: center;
cursor: pointer;
`;
2 changes: 1 addition & 1 deletion src/components/Seller/Common/OngoingCounsultBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface OngoingCounsultBoxProps {
counselorprofileStatus: number | undefined;
onClick?: () => void;
reviewCompleted?: boolean;
isChat: boolean;
isChat?: boolean;
}
function OngoingCounsultBox({
categoryStatus,
Expand Down
25 changes: 17 additions & 8 deletions src/components/Seller/SellerConsult/SellerChatList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getChatsMinder } from 'api/get';
import { ConsultModal } from 'components/Buyer/BuyerConsult/ConsultModal';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { SetURLSearchParams, useNavigate } from 'react-router-dom';
import { useRecoilState, useSetRecoilState } from 'recoil';
import styled from 'styled-components';
import { isConsultModalOpenState, scrollLockState } from 'utils/atom';
Expand All @@ -18,13 +18,17 @@ import { ConsultInfoItem, ConsultInfoList } from 'utils/type';
interface SellerConsultProps {
sortType: number;
setSortType: React.Dispatch<React.SetStateAction<number>>;
isIncludeCompleteConsult: boolean;
isChecked: boolean;
searchParams: URLSearchParams;
setSearchParams: SetURLSearchParams;
}

function SellerChatList({
sortType,
isIncludeCompleteConsult,
isChecked,
setSortType,
searchParams,
setSearchParams,
}: SellerConsultProps) {
const [consultInfo, setConsultInfo] = useState<ConsultInfoList>([]);
const [isLoading, setIsLoading] = useState<boolean>(true);
Expand All @@ -41,7 +45,7 @@ function SellerChatList({
* https://stackoverflow.com/questions/73896315/rxjs-subscribe-callback-doesnt-have-access-to-current-react-state-functional-c
*/
const cardDataRef = useRef<ConsultInfoItem[]>([]);
const { stompClient } = useStompContext();
const { stompClient, isConnected } = useStompContext();
//채팅 readId, 가장 최근 unread message, 정렬 업데이트
const updateChatData = (
chatId: number,
Expand Down Expand Up @@ -172,12 +176,12 @@ function SellerChatList({
);
}
};
}, [stompClient]);
}, [stompClient, isConnected]);

const fetchChatData = useCallback(async () => {
setIsLoading(true);
const params = {
filter: !isIncludeCompleteConsult,
filter: isChecked,
sortType: sortType === 0 ? 'latest' : 'unread',
};

Expand All @@ -199,7 +203,7 @@ function SellerChatList({
} finally {
setIsLoading(false);
}
}, [isIncludeCompleteConsult, navigate, setIsLoading, sortType]);
}, [isChecked, navigate, setIsLoading, sortType]);

useEffect(() => {
fetchChatData();
Expand Down Expand Up @@ -250,7 +254,12 @@ function SellerChatList({
setScrollLock(false);
}}
/>
<ConsultModal sortType={sortType} setSortType={setSortType} />
<ConsultModal
sortType={sortType}
setSortType={setSortType}
searchParams={searchParams}
setSearchParams={setSearchParams}
/>
</>
) : null}
</ConsultBoxList>
Expand Down
Loading
Loading