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

[Fix] #33 포스트 이미지 보이게 수정 #37

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions src/app/(afterLogin)/_component/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export default function Post({ post }: { post: any }) {
}

// 이미지 유효하지 않은 경우 디폴트 이미지 적용
const profileImageUrl =
post?.user?.profileImage?.link || "/default_profile_img.svg";
const profileImageUrl = post?.user?.profileImage?.url || "/default_profile_img.svg";

return (
<Main>
Expand Down
69 changes: 37 additions & 32 deletions src/app/(afterLogin)/_component/PostImages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,90 +10,95 @@ import {
} from "./PostStyle";

type Image = {
imageId: number;
link: string;
id: number;
url: string;
};

type Props = {
post: {
postId: number;
content: string;
User: {
id: string;
nickname: string;
image: string;
user: {
userId: number;
name: string;
customId: string;
profileImage: {
name: string;
url: string;
};
};
createdAt: Date;
Images: Image[];
isLikedByUser: boolean;
createdAt: string;
images: Image[];
};
};

export default function PostImages({ post }: Props) {
if (!post?.Images || post?.Images.length === 0) return null;
if (!post?.images || post?.images.length === 0) return null;
Copy link
Member

Choose a reason for hiding this comment

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

이미지가 없는 경우에 대한 ui 반응은 따로 없는 건가요?

Copy link
Collaborator Author

@JIN921 JIN921 Nov 13, 2024

Choose a reason for hiding this comment

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

이미지가 없는 경우는 PostImage 컴포넌트가 안떠서 Post 컴포넌트에 그냥 글만 뜨게 되어 있어요!

Copy link
Member

Choose a reason for hiding this comment

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

확인 했습니다!


if (post.Images.length === 1) {
const image = post.Images[0];
console.log(post.images); // post.images가 제대로 출력되는지 확인

if (post.images.length === 1) {
const image = post.images[0];
return (
<PostImageSection>
<SingleImageLink
href={`/${post.User.id}/status/${post.postId}/photo/${image.imageId}`}
style={{ backgroundImage: `url(${image.link})` }}
href={`/${post.user.customId}/status/${post.postId}/photo/${image.id}`}
style={{ backgroundImage: `url(${image.url})` }}
>
<img src={image.link} alt={`image-${image.imageId}`} />
<img src={image.url} alt={`image-${image.id}`} />
</SingleImageLink>
</PostImageSection>
);
}

if (post.Images.length === 2) {
if (post.images.length === 2) {
return (
<PostImageSection>
<TwoImageWrapper>
{post.Images.map((image) => (
{post.images.map((image) => (
<ImageLink
key={image.imageId}
href={`/${post.User.id}/status/${post.postId}/photo/${image.imageId}`}
style={{ backgroundImage: `url(${image.link})` }}
key={image.id}
href={`/${post.user.customId}/status/${post.postId}/photo/${image.id}`}
style={{ backgroundImage: `url(${image.url})` }}
/>
))}
</TwoImageWrapper>
</PostImageSection>
);
}

if (post.Images.length === 3) {
if (post.images.length === 3) {
return (
<PostImageSection>
<ThreeImageWrapper>
<ImageLink
href={`/${post.User.id}/status/${post.postId}/photo/${post.Images[0].imageId}`}
style={{ backgroundImage: `url(${post.Images[0]?.link})` }}
href={`/${post.user.customId}/status/${post.postId}/photo/${post.images[0].id}`}
style={{ backgroundImage: `url(${post.images[0]?.url})` }}
/>
<ThreeImageColumn>
<ImageLink
href={`/${post.User.id}/status/${post.postId}/photo/${post.Images[1].imageId}`}
style={{ backgroundImage: `url(${post.Images[1]?.link})` }}
href={`/${post.user.customId}/status/${post.postId}/photo/${post.images[1].id}`}
style={{ backgroundImage: `url(${post.images[1]?.url})` }}
/>
<ImageLink
href={`/${post.User.id}/status/${post.postId}/photo/${post.Images[2].imageId}`}
style={{ backgroundImage: `url(${post.Images[2]?.link})` }}
href={`/${post.user.customId}/status/${post.postId}/photo/${post.images[2].id}`}
style={{ backgroundImage: `url(${post.images[2]?.url})` }}
/>
</ThreeImageColumn>
</ThreeImageWrapper>
</PostImageSection>
);
}

if (post.Images.length === 4) {
if (post.images.length === 4) {
return (
<PostImageSection>
<FourImageWrapper>
{post.Images.map((image) => (
{post.images.map((image) => (
<FourImageLink
key={image.imageId}
href={`/${post.User.id}/status/${post.postId}/photo/${image.imageId}`}
style={{ backgroundImage: `url(${image.link})` }}
key={image.id}
href={`/${post.user.customId}/status/${post.postId}/photo/${image.id}`}
style={{ backgroundImage: `url(${image.url})` }}
/>
))}
</FourImageWrapper>
Expand Down
2 changes: 1 addition & 1 deletion src/app/(afterLogin)/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default function Home() {
<Post key={index} post={post} />
))
) : (
<div>No posts available</div>
<div> </div>
)}
</StyledMain>
);
Expand Down