-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ページ管理機能の型を修正し、検索パラメータのロジックを整理しました。また、新しいページリストコンポーネントとユーザー情報コンポーネントを追…
…加しました。 (#645)
- Loading branch information
Showing
6 changed files
with
224 additions
and
170 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
next/src/app/[locale]/(common-layout)/user/[handle]/components/page-list.server.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { PageCard } from "@/app/[locale]/components/page-card"; | ||
import { fetchPaginatedPublicPagesWithInfo } from "@/app/[locale]/db/queries.server"; | ||
import { fetchUserByHandle } from "@/app/db/queries.server"; | ||
import { getCurrentUser } from "@/auth"; | ||
import { getGuestId } from "@/lib/get-guest-id"; | ||
import { notFound } from "next/navigation"; | ||
import { PaginationControls } from "./pagination-controls"; | ||
interface PageListServerProps { | ||
handle: string; | ||
page: number; | ||
locale: string; | ||
} | ||
|
||
export async function PageListServer({ | ||
handle, | ||
page, | ||
locale, | ||
}: PageListServerProps) { | ||
const currentUser = await getCurrentUser(); | ||
const guestId = !currentUser ? await getGuestId() : undefined; | ||
const isOwner = currentUser?.handle === handle; | ||
|
||
const pageOwner = await fetchUserByHandle(handle); | ||
if (!pageOwner) { | ||
return notFound(); | ||
} | ||
const { pagesWithInfo, totalPages, currentPage } = | ||
await fetchPaginatedPublicPagesWithInfo({ | ||
page: page, | ||
pageSize: 9, | ||
currentUserId: currentUser?.id, | ||
currentGuestId: guestId, | ||
pageOwnerId: pageOwner.id, | ||
onlyUserOwn: true, | ||
locale, | ||
}); | ||
|
||
if (pagesWithInfo.length === 0) { | ||
return ( | ||
<p className="text-center text-gray-500 mt-10"> | ||
{isOwner ? "You haven't created any pages yet." : "No pages yet."} | ||
</p> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="grid gap-6 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3"> | ||
{pagesWithInfo.map((pageWithInfo) => ( | ||
<PageCard | ||
key={pageWithInfo.id} | ||
pageCard={pageWithInfo} | ||
pageLink={`/user/${handle}/page/${pageWithInfo.slug}`} | ||
userLink={`/user/${handle}`} | ||
showOwnerActions={isOwner} | ||
/> | ||
))} | ||
</div> | ||
|
||
<div className="mt-8 flex justify-center"> | ||
<PaginationControls currentPage={currentPage} totalPages={totalPages} /> | ||
</div> | ||
</> | ||
); | ||
} |
107 changes: 107 additions & 0 deletions
107
next/src/app/[locale]/(common-layout)/user/[handle]/components/user-info.server.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { fetchUserByHandle } from "@/app/db/queries.server"; | ||
import { getCurrentUser } from "@/auth"; | ||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card"; | ||
import { Link } from "@/i18n/routing"; | ||
import Linkify from "linkify-react"; | ||
import { Settings } from "lucide-react"; | ||
import { | ||
fetchFollowerList, | ||
fetchFollowingList, | ||
getFollowCounts, | ||
} from "../db/queries.server"; | ||
import { FollowButton } from "./follow-button"; | ||
import { FollowStats } from "./follow-stats"; | ||
|
||
export async function UserInfo({ | ||
handle, | ||
}: { | ||
handle: string; | ||
}) { | ||
const pageOwner = await fetchUserByHandle(handle); | ||
if (!pageOwner) { | ||
const error = new Error("Unauthorized"); | ||
error.message = "Unauthorized"; | ||
throw error; | ||
} | ||
|
||
const currentUser = await getCurrentUser(); | ||
|
||
const isOwner = currentUser?.handle === handle; | ||
|
||
const followCounts = await getFollowCounts(pageOwner.id); | ||
const followerList = await fetchFollowerList(pageOwner.id); | ||
const followingList = await fetchFollowingList(pageOwner.id); | ||
|
||
return ( | ||
<Card className="mb-8"> | ||
<CardHeader className="pb-4"> | ||
<div className="flex w-full flex-col md:flex-row"> | ||
<div> | ||
<Link href={`${pageOwner.image}`}> | ||
<Avatar className="w-20 h-20 md:w-24 md:h-24"> | ||
<AvatarImage src={pageOwner.image} alt={pageOwner.name} /> | ||
<AvatarFallback> | ||
{pageOwner.name.charAt(0).toUpperCase()} | ||
</AvatarFallback> | ||
</Avatar> | ||
</Link> | ||
</div> | ||
<div className="mt-2 md:mt-0 md:ml-4 flex items-center justify-between w-full"> | ||
<div> | ||
<CardTitle className="text-xl md:text-2xl font-bold"> | ||
{pageOwner.name} | ||
</CardTitle> | ||
<div> | ||
<CardDescription className="text-sm text-gray-500"> | ||
@{pageOwner.handle} | ||
</CardDescription> | ||
<FollowStats | ||
followingCount={followCounts.following} | ||
followersCount={followCounts.followers} | ||
followingList={followingList.map((item) => ({ | ||
handle: item.following.handle, | ||
name: item.following.name, | ||
image: item.following.image, | ||
}))} | ||
followerList={followerList.map((item) => ({ | ||
handle: item.follower.handle, | ||
name: item.follower.name, | ||
image: item.follower.image, | ||
}))} | ||
/> | ||
</div> | ||
</div> | ||
|
||
{isOwner ? ( | ||
<Link href={`/user/${pageOwner.handle}/edit`}> | ||
<Button | ||
variant="secondary" | ||
className="flex items-center rounded-full" | ||
> | ||
<Settings className="w-4 h-4" /> | ||
<span className="ml-2 text-sm">Edit Profile</span> | ||
</Button> | ||
</Link> | ||
) : ( | ||
<FollowButton targetUserId={pageOwner.id} /> | ||
)} | ||
</div> | ||
</div> | ||
</CardHeader> | ||
|
||
<CardContent className="mt-4"> | ||
<Linkify options={{ className: "underline" }}> | ||
{pageOwner.profile} | ||
</Linkify> | ||
</CardContent> | ||
</Card> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.