Skip to content

Commit

Permalink
feat: Change pointer appearance when hover, redirect profile page whe…
Browse files Browse the repository at this point in the history
…n user profile image clicked. (kookmin-sw#75)
  • Loading branch information
cjeongmin committed May 14, 2024
1 parent 0a4418e commit 1a9f51c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
32 changes: 24 additions & 8 deletions src/app/pages/shared-post-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,6 @@ export function SharedPostPage({

const { mutate: deleteSharedPost } = useDeleteSharedPost();

const [selected, setSelected] = useState<
| {
memberId: string;
profileImage: string;
}
| undefined
>(undefined);

const { isLoading: isSharedPostLoading, data: sharedPost } = useSharedPost({
postId,
enabled: type === 'hasRoom' && auth?.accessToken != null,
Expand All @@ -468,6 +460,21 @@ export function SharedPostPage({
enabled: type === 'dormitory' && auth?.accessToken != null,
});

const [selected, setSelected] = useState<
| {
memberId: string;
profileImage: string;
}
| undefined
>(
sharedPost != null
? {
memberId: sharedPost.data.publisherAccount.memberId,
profileImage: sharedPost.data.publisherAccount.profileImageFileName,
}
: undefined,
);

const { data: userData } = useUserData(auth?.accessToken != null);
const [userId, setUserId] = useState<string>('');

Expand All @@ -493,6 +500,15 @@ export function SharedPostPage({
sharedPost?.data.publisherAccount.memberId ?? '',
);

useEffect(() => {
if (selected != null || sharedPost == null) return;

setSelected({
memberId: sharedPost.data.publisherAccount.memberId,
profileImage: sharedPost.data.publisherAccount.profileImageFileName,
});
}, [selected, sharedPost]);

useEffect(() => {
if (sharedPost?.data.address.roadAddress != null) {
fromAddrToCoord({ query: sharedPost?.data.address.roadAddress }).then(
Expand Down
25 changes: 21 additions & 4 deletions src/components/shared-posts/PostCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import { useRouter } from 'next/navigation';
import styled from 'styled-components';

import { HorizontalDivider } from '@/components';
Expand All @@ -24,6 +25,8 @@ const styles = {
border-radius: 16px;
object-fit: cover;
cursor: pointer;
`,
content: styled.div`
flex-grow: 1;
Expand All @@ -44,6 +47,8 @@ const styles = {
font-style: normal;
font-weight: 700;
line-height: normal;
cursor: pointer;
}
h2 {
Expand All @@ -68,6 +73,8 @@ const styles = {
writer: styled.div`
position: relative;
cursor: pointer;
display: flex;
flex-shrink: 0;
flex-direction: column;
Expand Down Expand Up @@ -129,16 +136,22 @@ export function PostCard({
post: SharedPostListItem | DormitorySharedPostListItem;
onClick: () => void;
}) {
const router = useRouter();

const recruitmentCapacity =
'roomInfo' in post
? post.roomInfo.recruitmentCapacity
: post.recruitmentCapacity;

return (
<div>
<styles.container onClick={onClick}>
<styles.thumbnail alt="" src={post.thumbnail.fileName} />
<styles.content>
<styles.container>
<styles.thumbnail
onClick={onClick}
alt=""
src={post.thumbnail.fileName}
/>
<styles.content onClick={onClick}>
<div>
<h1>{post.title}</h1>
<h2>{post.address.roadAddress}</h2>
Expand All @@ -156,7 +169,11 @@ export function PostCard({
)}
</div>
</styles.content>
<styles.writer>
<styles.writer
onClick={() => {
router.push(`/profile/${post.publisherAccount.memberId}`);
}}
>
<img alt="" src={post.publisherAccount.profileImageFileName} />
<styles.percentage>
<p>50%</p>
Expand Down

0 comments on commit 1a9f51c

Please sign in to comment.