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

πŸ›More fixes + additional features #72

Merged
merged 6 commits into from
Feb 1, 2025
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
7 changes: 5 additions & 2 deletions src/components/SellingItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import { getTimeAgo } from '../utils/utils';

type SellingItemProps = {
ItemInfo: PreviewItem;
onStatusChange: (updatedItem: PreviewItem) => void;
};

const SellingItem = ({ ItemInfo }: SellingItemProps) => {
const SellingItem = ({ ItemInfo, onStatusChange }: SellingItemProps) => {
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
const navigate = useNavigate();

Expand Down Expand Up @@ -58,6 +59,8 @@ const SellingItem = ({ ItemInfo }: SellingItemProps) => {
if (!response.ok) {
throw new Error('μƒνƒœ λ³€κ²½ μš”μ²­μ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.');
}

onStatusChange({ ...ItemInfo, status: Status as 0 | 1 | 2 });
} catch (error) {
console.error('μ—λŸ¬ λ°œμƒ:', error);
} finally {
Expand Down Expand Up @@ -204,7 +207,7 @@ const SellingItem = ({ ItemInfo }: SellingItemProps) => {
<div className={styles.subBox}>
<div className={styles.iconBox}>
<img src={chatIcon} className={styles.smallIcon} />
{14}
{ItemInfo.chatCount}
</div>
{ItemInfo.likeCount > 0 && (
<div className={styles.iconBox}>
Expand Down
14 changes: 11 additions & 3 deletions src/pages/BuyerSelectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
각 μ±„νŒ…λ°©μ— ν•΄λ‹Ήν•˜λŠ” νŽ˜μ΄μ§€.
*/
import { useEffect, useState } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import { useLocation, useNavigate, useParams } from 'react-router-dom';

import leftarrow from '../assets/leftarrow.svg';
//import UpperBar from '../components/UpperBar';
import styles from '../css/BuyerSelectPage.module.css';
import type { Article } from '../typings/item';
import type { Item } from '../typings/item';
import type { LocationState } from '../typings/toolBar';

const BuyerSelectPage = () => {
const { id } = useParams();
Expand All @@ -20,9 +21,16 @@ const BuyerSelectPage = () => {
new Intl.NumberFormat('ko-KR').format(price),
);
const navigate = useNavigate();
const location = useLocation();

const handleBackClick = () => {
void navigate(-1);
const locationState = location.state as LocationState;

if (locationState !== null && locationState.from === 'mysells') {
void navigate(-2);
} else {
void navigate(-1);
}
};

useEffect(() => {
Expand Down Expand Up @@ -136,7 +144,7 @@ const BuyerSelectPage = () => {
: itemInfo?.status === 1
? 'μ˜ˆμ•½μ€‘'
: itemInfo?.status === 2
? 'νŒλ§€μ™„λ£Œ'
? 'κ±°λž˜μ™„λ£Œ'
: ''}
</p>
</div>
Expand Down
14 changes: 10 additions & 4 deletions src/pages/ChatRoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ const ChatRoomPage = () => {
},
{
color: 'black',
text: 'νŒλ§€μ™„λ£Œ',
text: 'κ±°λž˜μ™„λ£Œ',
function: () => {
handleChangeStatus(2);
if (itemInfo === null) throw new Error('Item is null');
Expand Down Expand Up @@ -491,9 +491,15 @@ const ChatRoomPage = () => {
</button>
</>
)}
{itemInfo?.status === 2 &&
// νŒλ§€μ™„λ£Œ μƒνƒœμ—μ„œλŠ” 아무 λ²„νŠΌλ„ λ‚˜νƒ€λ‚˜μ§€ μ•ŠμŒ
null}
{itemInfo?.status === 2 && (
// νŒλ§€μ™„λ£Œ μƒνƒœμ—μ„œλŠ” 아무 λ²„νŠΌλ„ λ‚˜νƒ€λ‚˜μ§€ μ•ŠμŒ -> ꡬ맀자λ₯Ό μœ„ν•΄ ν›„κΈ° 보내기 λ²„νŠΌ μΆ”κ°€
<button
className={styles.iteminfoButton}
onClick={handleSendReviewClick}
>
ν›„κΈ° 보내기
</button>
)}
</div>
</div>
<div
Expand Down
48 changes: 45 additions & 3 deletions src/pages/MannersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
type ErrorResponseType,
type Manner,
mannerTypeLabels,
negMannerTypeLabels,
} from '../typings/user';

const MANNER_INFO_TEXT = `
Expand All @@ -34,7 +35,9 @@ const MANNER_INFO_TEXT = `
const MannersPage = () => {
const { nickname } = useParams<{ nickname: string }>();
const [manners, setManners] = useState<Manner[]>([]);
const [negManners, setNegManners] = useState<Manner[]>([]);
const [loading, setLoading] = useState<boolean>(true);
const myNickname = localStorage.getItem('nickname');
const navigate = useNavigate();

useEffect(() => {
Expand Down Expand Up @@ -63,7 +66,18 @@ const MannersPage = () => {

const data = (await response.json()) as Manner[];
console.info(data);
setManners(data);

const PosManners = data.filter(
(manner) => !manner.mannerType.startsWith('NEG_'),
);
setManners(PosManners);

if (nickname === myNickname) {
const NegManners = data.filter((manner) =>
manner.mannerType.startsWith('NEG_'),
);
setNegManners(NegManners);
}
} catch (error) {
console.error('error:', error);
} finally {
Expand All @@ -72,7 +86,7 @@ const MannersPage = () => {
};

void fetchMannersInfo();
}, [nickname]);
}, [nickname, myNickname]);

return (
<div className={styles.main}>
Expand Down Expand Up @@ -123,7 +137,35 @@ const MannersPage = () => {
<span className={styles.mannerEmoji}>😞</span>
<span>받은 λΉ„λ§€λ„ˆ</span>
</div>
<p className={styles.mannerLine}>받은 λΉ„λ§€λ„ˆκ°€ μ—†μ–΄μš”.</p>
{nickname === myNickname ? (
negManners.length === 0 ? (
<p className={styles.mannerLine}>받은 λΉ„λ§€λ„ˆκ°€ μ—†μ–΄μš”.</p>
) : (
<>
{negManners
.sort((a, b) => b.count - a.count)
.map((manner, index) => (
<div key={index} className={styles.mannerLine}>
<p>
{
negMannerTypeLabels[
manner.mannerType as keyof typeof negMannerTypeLabels
]
}
</p>
<div className={styles.mannerLineRight}>
<img src={peopleIcon} style={{ height: '20px' }} />
{manner.count}
</div>
</div>
))}
</>
)
) : (
<p className={styles.mannerLine}>
&lsquo;받은 λΉ„λ§€λ„ˆ&rsquo;λŠ” λ³ΈμΈμ—κ²Œλ§Œ λ³΄μ—¬μš”.
</p>
)}
</div>
)}
<div className={styles.mannerInfoBox}>
Expand Down
53 changes: 43 additions & 10 deletions src/pages/MySellsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
λ‚˜μ˜ νŒλ§€λ‚΄μ—­ νŽ˜μ΄μ§€.
'νŒλ§€μ€‘', 'κ±°λž˜μ™„λ£Œ' 둜만 ꡬ뢄함
*/
import { useEffect, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { NavLink, useNavigate } from 'react-router-dom';

import leftArrow from '../assets/leftarrow.svg';
Expand All @@ -24,8 +24,8 @@ const MySellsPage = () => {
const [isLoading, setIsLoading] = useState(true);
const navigate = useNavigate();

useEffect(() => {
const fetchMySellsInfo = async () => {
const fetchMySellsInfo = useCallback(
async (fetchType: 'both' | 'selling' | 'sold') => {
const token = localStorage.getItem('token');
try {
if (token === null) throw new Error('No token found');
Expand All @@ -51,15 +51,22 @@ const MySellsPage = () => {
);
const sold = data.filter((item) => item.status === 2);

setSellingItems((prevItems) => [...prevItems, ...selling]); // 판맀 쀑 or μ˜ˆμ•½ 쀑
setSoldItems((prevItems) => [...prevItems, ...sold]); // κ±°λž˜μ™„λ£Œ
if (fetchType === 'both' || fetchType === 'selling') {
setSellingItems((prevItems) => [...prevItems, ...selling]); // 판맀 쀑 or μ˜ˆμ•½ 쀑
}
if (fetchType === 'both' || fetchType === 'sold') {
setSoldItems((prevItems) => [...prevItems, ...sold]); // κ±°λž˜μ™„λ£Œ
}
} catch (error) {
console.error('error:', error);
}
};
},
[lastId],
);

void fetchMySellsInfo();
}, [lastId]);
useEffect(() => {
void fetchMySellsInfo('both');
}, [fetchMySellsInfo]);

useEffect(() => {
const fetchMyPageInfo = async () => {
Expand Down Expand Up @@ -108,6 +115,24 @@ const MySellsPage = () => {
};
}, [nextRequestId]);

const handleStatusChange = (updatedItem: PreviewItem) => {
if (activeTab === 'selling') {
//setSellingItems((prev) =>
// prev.filter((item) => item.id !== updatedItem.id),
//);
//setSoldItems([]);
//void fetchMySellsInfo('sold');
void navigate(`/sendreview/${updatedItem.id}`);
void navigate(`/item/buyerselect/${updatedItem.id}`, {
state: { from: 'mysells' },
});
} else {
setSoldItems((prev) => prev.filter((item) => item.id !== updatedItem.id));
setSellingItems([]);
void fetchMySellsInfo('selling');
}
};

return (
<div className={styles.main}>
<div className={styles.upperBar}>
Expand Down Expand Up @@ -176,7 +201,11 @@ const MySellsPage = () => {
) : (
<div>
{sellingItems.map((item, index) => (
<SellingItem key={index} ItemInfo={item} />
<SellingItem
key={index}
ItemInfo={item}
onStatusChange={handleStatusChange}
/>
))}
</div>
)}
Expand All @@ -189,7 +218,11 @@ const MySellsPage = () => {
) : (
<div>
{soldItems.map((item, index) => (
<SellingItem key={index} ItemInfo={item} />
<SellingItem
key={index}
ItemInfo={item}
onStatusChange={handleStatusChange}
/>
))}
</div>
)}
Expand Down
5 changes: 1 addition & 4 deletions src/pages/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ const ProfilePage = () => {
ν”„λ‘œν•„ μˆ˜μ •
</NavLink>
) : (
<NavLink
to={`/mannerpraise/${profile.user.nickname}`}
className={styles.profileEditButton}
>
<NavLink to="/temp" className={styles.profileEditButton}>
λ§€λ„ˆ μΉ­μ°¬ν•˜κΈ°
</NavLink>
)}
Expand Down
23 changes: 10 additions & 13 deletions src/pages/SearchResultPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ const SearchResultPage = () => {
const token = localStorage.getItem('token');
if (token === null) throw new Error('토큰이 μ—†μŠ΅λ‹ˆλ‹€.');

const itemResponse = await fetch(`/api/item/search/${lastItemId}`, {
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
const itemResponse = await fetch(
`/api/item/search/${lastItemId}?text=${query}`,
{
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
},
body: JSON.stringify({
text: query,
}),
});
);

if (!itemResponse.ok) {
throw new Error(`Failed to fetch items: ${itemResponse.statusText}`);
Expand All @@ -64,16 +64,13 @@ const SearchResultPage = () => {
}

const communityResponse = await fetch(
`/api/feed/search/${lastCommunityId}`,
`/api/feed/search/${lastCommunityId}?text=${query}`,
{
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: query,
}),
},
);
if (!communityResponse.ok) {
Expand Down
14 changes: 6 additions & 8 deletions src/pages/SendReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,14 @@ const SendReviewPage = () => {
}
}

if (content !== '') {
if (content !== '' && activeMood !== 'bad') {
if (itemInfo === undefined) throw new Error('itemInfo is undefined');
const reviewCreateRequest = {
content: content,
location: myLocation,
isWritedByBuyer: !isSeller,
sellerId: itemInfo?.article.seller.id,
buyerId: itemInfo?.article.buyer.id,
sellerId: itemInfo.article.seller.id,
buyerId: itemInfo.article.buyer.id,
articleId: id,
};
console.info(reviewCreateRequest);
Expand Down Expand Up @@ -208,10 +209,7 @@ const SendReviewPage = () => {
<p className={styles.itemTitle}>{itemInfo?.article.title}</p>
<p>
κ±°λž˜ν•œ 이웃
<span style={{ fontWeight: 'bold' }}>
{' '}
{itemInfo?.article.buyer.nickname}{' '}
</span>
<span style={{ fontWeight: 'bold' }}> {partner?.nickname} </span>
{isSeller && (
<span
className={styles.changeBuyer}
Expand All @@ -227,7 +225,7 @@ const SendReviewPage = () => {
<p className={styles.selectMoodMainText}>
{myNickname}λ‹˜,
<br />
{itemInfo?.article.buyer.nickname}λ‹˜κ³Ό κ±°λž˜κ°€ μ–΄λ– μ…¨λ‚˜μš”?
{partner?.nickname}λ‹˜κ³Ό κ±°λž˜κ°€ μ–΄λ– μ…¨λ‚˜μš”?
</p>
<p className={styles.selectMoodSubText}>
거래 μ„ ν˜Έλ„λŠ” λ‚˜λ§Œ λ³Ό 수 μžˆμ–΄μš”.
Expand Down
2 changes: 1 addition & 1 deletion src/pages/SetLocationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const SetLocationPage = () => {
<div className={styles.content}>
<p className={styles.mainText}>λ‚΄ 동넀λ₯Ό μ„€μ •ν•΄μ£Όμ„Έμš”.</p>
<p className={styles.subText}>
λ‹Ήκ·Όλ§ˆμΌ“μ€ 동넀 직거래 λ§ˆμΌ“μ΄μ—μš”. <br />λ‚΄ 동넀λ₯Ό μ„€μ •ν•˜κ³ 
μ™€ν”Œλ§ˆμΌ“μ€ 동넀 직거래 λ§ˆμΌ“μ΄μ—μš”. <br />λ‚΄ 동넀λ₯Ό μ„€μ •ν•˜κ³ 
μ‹œμž‘ν•΄λ³΄μ„Έμš”! <br /> 동넀 μ •λ³΄λŠ” λ‚΄ ν”„λ‘œν•„μ—μ„œ λ³€κ²½ν•  μˆ˜λ„ μžˆμ–΄μš”.
</p>
<select
Expand Down
3 changes: 1 addition & 2 deletions src/pages/TempPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const TempPage = () => {
alignItems: 'center',
}}
>
이 κΈ°λŠ₯은 아직 μΆ”κ°€λ˜μ§€ μ•Šμ•˜κ±°λ‚˜ λ³Έ ν”„λ‘œμ νŠΈμ—μ„œλŠ” κ΅¬ν˜„λ˜μ§€ μ•Šμ„
κΈ°λŠ₯μž…λ‹ˆλ‹€!
이 κΈ°λŠ₯은 λ³Έ ν”„λ‘œμ νŠΈμ—μ„œλŠ” κ΅¬ν˜„λ˜μ§€ μ•Šμ„ κΈ°λŠ₯μž…λ‹ˆλ‹€!
</div>
);
};
Expand Down