Skip to content

Commit

Permalink
chore: update files
Browse files Browse the repository at this point in the history
  • Loading branch information
haru52 committed Jun 15, 2024
1 parent 4870265 commit 9852232
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/app/_components/social-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function SocialDetail({
const router = useRouter();
const deleteSocial = api.social.delete.useMutation({
onSuccess: () => {
router.push("/");
router.push("/socials");
router.refresh();
},
});
Expand Down
18 changes: 11 additions & 7 deletions src/app/_components/social.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import type { Avatar } from "~/entities/avatar";
export function Social({
social,
avatar,
isLoggedIn,
}: {
social: SocialEntity;
avatar: Avatar | undefined;
isLoggedIn: boolean;
}) {
return (
<Link
Expand All @@ -32,13 +34,15 @@ export function Social({
</div>
<h2 className="card-title">{social.name}</h2>
<p>{social.description}</p>
<div className="card-actions justify-end">
{avatar === undefined ? (
<JoinSocialButton social={social} />
) : (
<LeaveSocialButton avatarId={avatar.id} />
)}
</div>
{isLoggedIn && (
<div className="card-actions justify-end">
{avatar === undefined ? (
<JoinSocialButton social={social} />
) : (
<LeaveSocialButton avatarId={avatar.id} />
)}
</div>
)}
</div>
</div>
</Link>
Expand Down
8 changes: 5 additions & 3 deletions src/app/_components/socials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ import type { Avatar } from "~/entities/avatar";
export function Socials({
socials,
avatars,
isLoggedIn,
}: {
socials: SocialEntity[];
avatars: Avatar[];
avatars: Avatar[] | null;
isLoggedIn: boolean;
}) {
return socials.length === 0 ? (
<p>まだソーシャルがありません</p>
) : (
<ul className="list-none pl-0">
{socials.map((social) => {
const avatar = avatars.find((avatar) => avatar.socialId === social.id);
const avatar = avatars?.find((avatar) => avatar.socialId === social.id);
return (
<li key={social.id} className="mb-0 mt-0.5 pl-0">
<Social social={social} avatar={avatar} />
<Social social={social} avatar={avatar} isLoggedIn={isLoggedIn} />
</li>
);
})}
Expand Down
8 changes: 6 additions & 2 deletions src/app/socials/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const metadata: Metadata = {
export default async function Page() {
const session = await getServerAuthSession();
const socials = await api.social.getAll();
const avatars = await api.avatar.getMyAvatars();
const avatars = session === null ? null : await api.avatar.getMyAvatars();
return (
<div className="container prose mx-auto mb-10 mt-5">
<h1 className="text-center">ソーシャル</h1>
Expand All @@ -20,7 +20,11 @@ export default async function Page() {
ソーシャルを作成
</Link>
)}
<Socials socials={socials} avatars={avatars} />
<Socials
socials={socials}
avatars={avatars}
isLoggedIn={session !== null}
/>
</div>
);
}

0 comments on commit 9852232

Please sign in to comment.