From 7df51fb34b74e944f25cef548c3807d4f4a97393 Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sun, 7 Dec 2025 17:21:58 +0900 Subject: [PATCH] =?UTF-8?q?#140=20=E3=81=BC=E3=81=A1=E3=81=BC=E3=81=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/PrefetchLink.tsx | 12 ++++++++---- frontend/src/components/TagLink.tsx | 19 +++++++++++++++---- frontend/src/components/TagSidebar.tsx | 13 +++++++------ frontend/src/pages/posts/PostListPage.tsx | 21 +++++++++++++-------- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/frontend/src/components/PrefetchLink.tsx b/frontend/src/components/PrefetchLink.tsx index 01b53b6..b968c8e 100644 --- a/frontend/src/components/PrefetchLink.tsx +++ b/frontend/src/components/PrefetchLink.tsx @@ -1,15 +1,16 @@ import { useQueryClient } from '@tanstack/react-query' import { useMemo } from 'react' -import { useNavigate } from 'react-router-dom' +import { createPath, useNavigate } from 'react-router-dom' import { useOverlayStore } from '@/components/RouteBlockerOverlay' import { prefetchForURL } from '@/lib/prefetchers' import { cn } from '@/lib/utils' import type { AnchorHTMLAttributes, FC, MouseEvent, TouchEvent } from 'react' +import type { To } from 'react-router-dom' type Props = AnchorHTMLAttributes & { - to: string + to: To replace?: boolean className?: string cancelOnError?: boolean } @@ -25,7 +26,10 @@ export default (({ to, ...rest }: Props) => { const navigate = useNavigate () const qc = useQueryClient () - const url = useMemo (() => (new URL (to, location.origin)).toString (), [to]) + const url = useMemo (() => { + const path = (typeof to === 'string') ? to : createPath (to) + return (new URL (path, location.origin)).toString () + }, [to]) const setOverlay = useOverlayStore (s => s.setActive) const doPrefetch = async () => { @@ -74,7 +78,7 @@ export default (({ to, } return ( - > @@ -24,6 +26,7 @@ export default (({ tag, linkFlg = true, withWiki = true, withCount = true, + prefetch = false, ...props }: Props) => { const spanClass = cn ( `text-${ TAG_COLOUR[tag.category] }-${ LIGHT_COLOUR_SHADE }`, @@ -44,11 +47,19 @@ export default (({ tag, )} {linkFlg ? ( - - {tag.name} - ) + {tag.name} + + : + {tag.name} + ) : ( diff --git a/frontend/src/components/TagSidebar.tsx b/frontend/src/components/TagSidebar.tsx index a2e00b2..d1b2acc 100644 --- a/frontend/src/components/TagSidebar.tsx +++ b/frontend/src/components/TagSidebar.tsx @@ -10,16 +10,17 @@ import { API_BASE_URL } from '@/config' import { CATEGORIES } from '@/consts' import { cn } from '@/lib/utils' -import type { FC } from 'react' +import type { FC, MouseEvent } from 'react' import type { Post, Tag } from '@/types' type TagByCategory = Record -type Props = { posts: Post[] } +type Props = { posts: Post[] + onClick?: (event: MouseEvent) => void } -export default (({ posts }: Props) => { +export default (({ posts, onClick }: Props) => { const navigate = useNavigate () const [tagsVsbl, setTagsVsbl] = useState (false) @@ -64,11 +65,11 @@ export default (({ posts }: Props) => {
タグ
    - {CATEGORIES.flatMap (cat => cat in tags ? ( + {CATEGORIES.flatMap (cat => cat in tags ? tags[cat].map (tag => (
  • - -
  • ))) : [])} + + )) : [])}
関聯 {posts.length > 0 && ( diff --git a/frontend/src/pages/posts/PostListPage.tsx b/frontend/src/pages/posts/PostListPage.tsx index fdda686..5b6a941 100644 --- a/frontend/src/pages/posts/PostListPage.tsx +++ b/frontend/src/pages/posts/PostListPage.tsx @@ -10,6 +10,7 @@ import WikiBody from '@/components/WikiBody' import TabGroup, { Tab } from '@/components/common/TabGroup' import MainArea from '@/components/layout/MainArea' import { API_BASE_URL, SITE_TITLE } from '@/config' +import { fetchPosts } from '@/lib/posts' import type { Post, WikiPage } from '@/types' @@ -28,13 +29,11 @@ export default () => { const loadMore = async (withCursor: boolean) => { setLoading (true) - const res = await axios.get (`${ API_BASE_URL }/posts`, { - params: { tags: tags.join (' '), - match: anyFlg ? 'any' : 'all', - limit: '20', - ...(withCursor && { cursor }) } }) - const data = toCamel (res.data as any, { deep: true }) as { posts: Post[] - nextCursor: string } + const data = await fetchPosts ({ + tags: tags.join (' '), + match: anyFlg ? 'any' : 'all', + limit: 20, + ...(withCursor && { cursor }) }) setPosts (posts => ( [...((new Map ([...(withCursor ? posts : []), ...data.posts] .map (post => [post.id, post]))) @@ -111,7 +110,13 @@ export default () => { - + { + const statesToSave = { + posts, cursor, + scroll: containerRef.current?.scrollTop ?? 0 } + sessionStorage.setItem (`posts:${ tagsQuery }`, + JSON.stringify (statesToSave)) + }}/>