Skip to content

Commit a94584b

Browse files
authored
Merge pull request #125 from nidor022/feature/#123
[#123] 404 한글 문구로 수정, /post/id 없는경로 예외처리
2 parents 5c37a8e + cb83cb2 commit a94584b

File tree

4 files changed

+44
-25
lines changed

4 files changed

+44
-25
lines changed

src/features/rolling-paper/components/rolling-paper-list.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,15 @@ function RollingPaperList({ cardData, totalPages, currentPage, onTurnCards }) {
248248
const navigate = useNavigate();
249249

250250
const handleCardClick = (cardId) => {
251+
if(!cardId) {
252+
navigate("*");
253+
return;
254+
}
255+
251256
navigate(`/post/${cardId}`);
252257
};
258+
259+
253260
const profileImages = useMemo(
254261
() =>
255262
cardData.flatMap((card) =>

src/hooks/use-image-loader.jsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,51 @@ function useImageListLodeChecker(imageList = []) {
2929
useEffect(() => {
3030
if (!imageList.length) return;
3131

32+
let cancelled = false;
33+
3234
setImageLoadStates((prev) => {
3335
const nextStates = { ...prev };
3436
imageList.forEach(({ id }) => {
35-
if (nextStates[id] === undefined) {
36-
nextStates[id] = false;
37-
}
37+
if (nextStates[id] === undefined) nextStates[id] = false;
3838
});
3939
return nextStates;
4040
});
4141

42+
const imageMap = {};
43+
4244
imageList.forEach(({ id, backgroundImageURL }) => {
4345
setImageLoadStates((prev) => {
44-
if (prev[id]) return prev;
46+
if (prev[id] === true) return prev;
4547

46-
if (!backgroundImageURL) {
47-
return { ...prev, [id]: false };
48-
}
48+
if (!backgroundImageURL) return { ...prev, [id]: false };
4949

5050
const img = new Image();
51-
img.src = backgroundImageURL;
51+
imageMap[id] = img;
52+
5253
img.onload = () => {
53-
setImageLoadStates((p) => ({ ...p, [id]: true }));
54+
if (!cancelled) {
55+
setImageLoadStates((p) => ({ ...p, [id]: true }));
56+
}
5457
};
58+
5559
img.onerror = () => {
56-
setImageLoadStates((p) => ({ ...p, [id]: false }));
60+
if (!cancelled) {
61+
setImageLoadStates((p) => ({ ...p, [id]: false }));
62+
}
5763
};
5864

65+
img.src = backgroundImageURL;
5966
return prev;
6067
});
6168
});
69+
70+
return () => {
71+
cancelled = true;
72+
Object.values(imageMap).forEach((img) => {
73+
img.onload = null;
74+
img.onerror = null;
75+
});
76+
};
6277
}, [imageList]);
6378

6479
return imageLoadStates;

src/pages/404-page.jsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ const ErrorNumber = styled.h1`
4545
font-weight: 900;
4646
color: var(--color-purple-700);
4747
margin: 0;
48-
font-size: 200px;
48+
font-size: 150px;
4949
5050
${media.mobile} {
51-
font-size: 130px;
51+
font-size: 110px;
5252
}
5353
`;
5454

5555
const ErrorComment = styled.span`
56-
font-size: 80px;
56+
font-size: 70px;
5757
color: #6e6293;
5858
font-weight: 700;
5959
6060
em {
61-
font-size: 100px;
61+
font-size: 90px;
6262
font-weight: 800;
6363
font-style: normal;
6464
color: #240079;
@@ -72,24 +72,20 @@ const ErrorComment = styled.span`
7272
}
7373
7474
${media.mobile} {
75-
font-size: 50px;
75+
font-size: 40px;
7676
em {
77-
font-size: 60px;
77+
font-size: 50px;
7878
}
7979
}
8080
`;
8181

8282
const ErrorCommentSofter = styled.span`
83-
font-size: 50px;
83+
font-size: 25px;
8484
color: #6e6293;
8585
font-weight: 400;
8686
87-
${media.tablet} {
88-
font-size: 40px;
89-
}
90-
9187
${media.mobile} {
92-
font-size: 30px;
88+
font-size: 18px;
9389
}
9490
`;
9591

@@ -133,10 +129,10 @@ const Error404Page = () => {
133129
<AirplaneSVG src={logoImage} />
134130
<ErrorNumber>404</ErrorNumber>
135131
<ErrorComment>
136-
<em>Oops!</em> Page Not Found...
132+
<em>앗 이런!</em> 페이지를 찾을 수 없습니다.
137133
</ErrorComment>
138134
<ErrorCommentSofter>
139-
Don't worry, let's get you back on track.
135+
페이지의 주소가 올바르지 않거나, 삭제 또는 다른 페이지로 변경되었습니다.
140136
</ErrorCommentSofter>
141137
<HomeButton
142138
size={BUTTON_SIZE.large}

src/pages/messages-page.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,12 @@ function MessagesPage() {
196196
} catch (error) {
197197
// TODO: Error 처리 필요
198198
console.error(error);
199+
navigate("/notfound", { replace: true });
199200
}
200201
}
201202

202203
fetchRollingPaper();
203-
}, [id]);
204+
}, [id, navigate]);
204205

205206
const content = (
206207
<>

0 commit comments

Comments
 (0)