Skip to content

Commit

Permalink
Fix: Add state for brokenURL
Browse files Browse the repository at this point in the history
  • Loading branch information
Byukchong committed May 17, 2024
1 parent d7e115e commit 4c5ba76
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/Navigation/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
justify-content: center;
position: sticky;
top: 0;
z-index: 1;
z-index: 99;
width: 100%;
background-color: var(--light-blue);
}
Expand Down
17 changes: 12 additions & 5 deletions components/ShareCards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useFetch } from '@/hooks/useFetch';
import { formatDate, generateTimeText } from '@/utils/date';
import styles from '@/components/ShareCards/index.module.css';
import Image from 'next/image';
import { SyntheticEvent } from 'react';
import { SyntheticEvent, useState } from 'react';
import thumbnail from '@/public/thumbnail.svg';
import Link from 'next/link';

Expand All @@ -24,9 +24,12 @@ interface FolderData {
function ShareCards({ url }: { url: string }) {
const Card = useFetch<FolderData>(url);
const CardDatas = Card?.folder.links;
const [imageErrors, setImageErrors] = useState<{ [key: string]: boolean }>(
{}
);

const AddThumbnail = (e: SyntheticEvent<HTMLImageElement, Event>) => {
e.currentTarget.src = '/thumbnail.svg';
const handleImageError = (id: string) => {
setImageErrors((prev) => ({ ...prev, [id]: true }));
};

return (
Expand All @@ -41,10 +44,14 @@ function ShareCards({ url }: { url: string }) {
<Image
width="320"
height="200"
src={CardData.imageSource ? CardData.imageSource : thumbnail}
src={
imageErrors[CardData.id]
? thumbnail
: CardData.imageSource || thumbnail
}
className={styles.card_img}
alt={CardData.imageSource ? CardData.title : '썸네일'}
onError={AddThumbnail}
onError={() => handleImageError(CardData.id)}
/>
</div>
<div className={styles.card_txt_div}>
Expand Down
2 changes: 1 addition & 1 deletion pages/shared/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function SharedPage() {
<>
<Navigation />
<FolderData />
<div className={styles.PageDisplay}>
<div className={styles.pageDisplay}>
<SearchBar />
<ShareCards url={BASE_URL_FOLDER_SAMPLE} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion pages/signin/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
align-items: center;
padding: 238px 0 253px;
background-color: var(--light-blue);
height: 100%;
height: 100vh;

@media (max-width: 1200px) {
padding: 200px 0 291px;
Expand Down
2 changes: 1 addition & 1 deletion pages/signup/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
align-items: center;
padding: 238px 0 253px;
background-color: var(--light-blue);
height: 100%;
height: 100vh;

@media (max-width: 1200px) {
padding: 200px 0 291px;
Expand Down

0 comments on commit 4c5ba76

Please sign in to comment.