diff --git a/frontend/src/lib/posts.ts b/frontend/src/lib/posts.ts index 3570abb..7ee14c0 100644 --- a/frontend/src/lib/posts.ts +++ b/frontend/src/lib/posts.ts @@ -29,14 +29,17 @@ export const fetchPost = async (id: string): Promise => await apiGet (`/po export const fetchPostChanges = async ( - { id, page, limit }: { + { id, tag, page, limit }: { id?: string + tag?: string page: number limit: number }, ): Promise<{ changes: PostTagChange[] count: number }> => - await apiGet ('/posts/changes', { params: { ...(id && { id }), page, limit } }) + await apiGet ('/posts/changes', { params: { ...(id && { id }), + ...(tag && { tag }), + page, limit } }) export const toggleViewedFlg = async (id: string, viewed: boolean): Promise => { diff --git a/frontend/src/lib/prefetchers.ts b/frontend/src/lib/prefetchers.ts index 0d4f2d8..ad18e1b 100644 --- a/frontend/src/lib/prefetchers.ts +++ b/frontend/src/lib/prefetchers.ts @@ -3,7 +3,7 @@ import { match } from 'path-to-regexp' import { fetchPost, fetchPosts, fetchPostChanges } from '@/lib/posts' import { postsKeys, tagsKeys, wikiKeys } from '@/lib/queryKeys' -import { fetchTagByName, fetchTags } from '@/lib/tags' +import { fetchTagByName, fetchTag, fetchTags } from '@/lib/tags' import { fetchWikiPage, fetchWikiPageByTitle, fetchWikiPages } from '@/lib/wiki' @@ -122,12 +122,24 @@ const prefetchPostShow: Prefetcher = async (qc, url) => { const prefetchPostChanges: Prefetcher = async (qc, url) => { const id = url.searchParams.get ('id') + const tag = url.searchParams.get ('tag') const page = Number (url.searchParams.get ('page') || 1) const limit = Number (url.searchParams.get ('limit') || 20) + if (tag) + { + await qc.prefetchQuery ({ + queryKey: tagsKeys.show (tag), + queryFn: () => fetchTag (tag) }) + } + await qc.prefetchQuery ({ - queryKey: postsKeys.changes ({ ...(id && { id }), page, limit }), - queryFn: () => fetchPostChanges ({ ...(id && { id }), page, limit }) }) + queryKey: postsKeys.changes ({ ...(id && { id }), + ...(tag && { tag }), + page, limit }), + queryFn: () => fetchPostChanges ({ ...(id && { id }), + ...(tag && { tag }), + page, limit }) }) } diff --git a/frontend/src/lib/queryKeys.ts b/frontend/src/lib/queryKeys.ts index b0d42f2..65a8be5 100644 --- a/frontend/src/lib/queryKeys.ts +++ b/frontend/src/lib/queryKeys.ts @@ -5,7 +5,7 @@ export const postsKeys = { index: (p: FetchPostsParams) => ['posts', 'index', p] as const, show: (id: string) => ['posts', id] as const, related: (id: string) => ['related', id] as const, - changes: (p: { id?: string; page: number; limit: number }) => + changes: (p: { id?: string; tag?: string; page: number; limit: number }) => ['posts', 'changes', p] as const } export const tagsKeys = { diff --git a/frontend/src/lib/tags.ts b/frontend/src/lib/tags.ts index 2935934..8a7829f 100644 --- a/frontend/src/lib/tags.ts +++ b/frontend/src/lib/tags.ts @@ -23,6 +23,18 @@ export const fetchTags = async ( ...(order && { order }) } }) +export const fetchTag = async (id: string): Promise => { + try + { + return await apiGet (`/tags/${ id }`) + } + catch + { + return null + } +} + + export const fetchTagByName = async (name: string): Promise => { try { diff --git a/frontend/src/pages/posts/PostHistoryPage.tsx b/frontend/src/pages/posts/PostHistoryPage.tsx index a9a5ea9..4652441 100644 --- a/frontend/src/pages/posts/PostHistoryPage.tsx +++ b/frontend/src/pages/posts/PostHistoryPage.tsx @@ -11,7 +11,8 @@ import Pagination from '@/components/common/Pagination' import MainArea from '@/components/layout/MainArea' import { SITE_TITLE } from '@/config' import { fetchPostChanges } from '@/lib/posts' -import { postsKeys } from '@/lib/queryKeys' +import { postsKeys, tagsKeys } from '@/lib/queryKeys' +import { fetchTag } from '@/lib/tags' import { cn, dateString } from '@/lib/utils' import type { FC } from 'react' @@ -21,15 +22,26 @@ export default (() => { const location = useLocation () const query = new URLSearchParams (location.search) const id = query.get ('id') + const tagId = query.get ('tag') const page = Number (query.get ('page') ?? 1) const limit = Number (query.get ('limit') ?? 20) // 投稿列の結合で使用 let rowsCnt: number + const { data: tag } = + tagId + ? useQuery ({ queryKey: tagsKeys.show (tagId), + queryFn: () => fetchTag (tagId) }) + : { data: null } + const { data, isLoading: loading } = useQuery ({ - queryKey: postsKeys.changes ({ ...(id && { id }), page, limit }), - queryFn: () => fetchPostChanges ({ ...(id && { id }), page, limit }) }) + queryKey: postsKeys.changes ({ ...(id && { id }), + ...(tagId && { tag: tagId }), + page, limit }), + queryFn: () => fetchPostChanges ({ ...(id && { id }), + ...(tagId && { tag: tagId }), + page, limit }) }) const changes = data?.changes ?? [] const totalPages = data ? Math.ceil (data.count / limit) : 0 @@ -48,6 +60,7 @@ export default (() => { 耕作履歴 {id && <>: 投稿 {#{id}}} + {tag && <>()} {loading ? 'Loading...' : ( diff --git a/frontend/src/pages/tags/TagListPage.tsx b/frontend/src/pages/tags/TagListPage.tsx index fd9dc60..e1ce2fc 100644 --- a/frontend/src/pages/tags/TagListPage.tsx +++ b/frontend/src/pages/tags/TagListPage.tsx @@ -3,6 +3,7 @@ import { useEffect, useMemo, useState } from 'react' import { Helmet } from 'react-helmet-async' import { useLocation, useNavigate } from 'react-router-dom' +import PrefetchLink from '@/components/PrefetchLink' import SortHeader from '@/components/SortHeader' import TagLink from '@/components/TagLink' import DateTimeField from '@/components/common/DateTimeField' @@ -211,6 +212,7 @@ export default (() => { + @@ -250,6 +252,7 @@ export default (() => { currentOrder={order} defaultDirection={defaultDirection}/> + @@ -263,6 +266,11 @@ export default (() => { {row.postCount} {dateString (row.createdAt)} {dateString (row.updatedAt)} + + + 耕作履歴 + + ))}