Skip to content

Commit

Permalink
リプライ表示の仮実装 (#398)
Browse files Browse the repository at this point in the history
## 変更内容
リプライしたことがわかるように

@coderabbitai: ignore
  • Loading branch information
takecchi authored Apr 4, 2024
1 parent d6245b4 commit 809bf0e
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/app/(menu)/_components/timeline/layouts/Post.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
'use client';

import { CardActionArea, styled, Tooltip, Typography } from '@mui/material';
import {
CardActionArea,
Skeleton,
styled,
Tooltip,
Typography,
} from '@mui/material';
import Link from 'next/link';
import FavoriteButton from '@/app/(menu)/_components/timeline/elements/FavoriteButton';
import RepostButton from '@/app/(menu)/_components/timeline/elements/RepostButton';
Expand All @@ -9,6 +15,7 @@ import MomentAgo from '@/app/(menu)/_components/timeline/elements/MomentAgo';
import { format } from 'date-fns';
import AvatarIcon from '@/app/(menu)/_components/timeline/elements/AvatarIcon';
import { isRepost as checkRepost } from '@/app/(menu)/_utils/post.utils';
import { usePost } from '@/swr/client/post';

const Article = styled('article')`
border-bottom: 1px solid ${({ theme }) => theme.palette.grey[100]};
Expand Down Expand Up @@ -74,6 +81,32 @@ const MomentLinks = styled(Link)`
}
`;

/**
* 〇〇さんへの返信
* @constructor
*/
function ReplyTo({ replyToPostId }: { replyToPostId: string }) {
const { data, isLoading } = usePost(replyToPostId);

if (isLoading) {
return <Skeleton style={{ maxWidth: '250px' }} />;
}

if (!data) {
return <div>読み込みエラー</div>;
}

return (
<MomentLinks
aria-label="リポストしたユーザー"
href={`/${data.author.username}/posts/${data.id}`}
onClick={(event) => event.stopPropagation()}
>
{data.author.name}さんへの返信
</MomentLinks>
);
}

type UserProps = {
name: string;
username: string;
Expand Down Expand Up @@ -109,6 +142,7 @@ export default function Post(props: Props) {
const postedAt = isRepost ? originalPost.postedAt : props.postedAt;
const author = isRepost ? originalPost.author : props.author;
const repostedBy = isRepost ? props.author : undefined;
const replyToPostId = props.replyToPostId;

const postUrl = `/${author.username}/posts/${id}`;

Expand Down Expand Up @@ -138,6 +172,7 @@ export default function Post(props: Props) {
{repostedBy.name}さんがリポスト
</MomentLinks>
)}
{replyToPostId && <ReplyTo replyToPostId={replyToPostId} />}
<Original>
<AvatarIcon
src={author.profileImageUrl}
Expand Down

0 comments on commit 809bf0e

Please sign in to comment.