-
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.
ページ管理機能を動的インポートに変更し、クライアントコンポーネントを追加しました。また、ページデータの取得ロジックを整理しました。 (#644)
- Loading branch information
Showing
3 changed files
with
93 additions
and
43 deletions.
There are no files selected for viewing
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
62 changes: 62 additions & 0 deletions
62
...]/(common-layout)/user/[handle]/page-management/components/page-management-tab/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,62 @@ | ||
import { getGeoViewData } from "../../components/page-view-data/view-data"; | ||
import { fetchPaginatedOwnPages } from "../../db/queries.server"; | ||
import { PageManagementTabClient } from "./client"; | ||
|
||
interface PageManagementTabProps { | ||
currentUserId: string; | ||
locale: string; | ||
page: string; | ||
query: string; | ||
handle: string; | ||
} | ||
|
||
export async function PageManagementTab({ | ||
currentUserId, | ||
locale, | ||
page, | ||
query, | ||
handle, | ||
}: PageManagementTabProps) { | ||
const { pagesWithTitle, totalPages, currentPage } = | ||
await fetchPaginatedOwnPages( | ||
currentUserId, | ||
locale, | ||
Number(page), | ||
10, | ||
query, | ||
); | ||
const pagesWithTitleAndViewData = await Promise.all( | ||
pagesWithTitle.map(async (pageData) => { | ||
const path = `/user/${handle}/page/${pageData.slug}`; | ||
try { | ||
const geoViewData = await getGeoViewData(path); | ||
const totalViews = geoViewData.reduce( | ||
(sum, item) => sum + item.views, | ||
0, | ||
); | ||
|
||
return { | ||
...pageData, | ||
viewCount: totalViews, | ||
geoViewData, | ||
}; | ||
} catch (error) { | ||
console.error(`Failed to fetch view data for ${path}:`, error); | ||
return { | ||
...pageData, | ||
viewCount: 0, | ||
geoViewData: [], | ||
}; | ||
} | ||
}), | ||
); | ||
|
||
return ( | ||
<PageManagementTabClient | ||
pagesWithTitleAndViewData={pagesWithTitleAndViewData} | ||
totalPages={totalPages} | ||
currentPage={currentPage} | ||
handle={handle} | ||
/> | ||
); | ||
} |
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