From e2f997974874aff11dbb9a80e18097e7a86c0bb5 Mon Sep 17 00:00:00 2001 From: miteruzo Date: Fri, 4 Jul 2025 00:54:19 +0900 Subject: [PATCH] #73 --- frontend/src/pages/posts/PostDetailPage.tsx | 16 ++++++++-------- frontend/src/pages/posts/PostListPage.tsx | 11 +++++------ frontend/src/pages/posts/PostNewPage.tsx | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/frontend/src/pages/posts/PostDetailPage.tsx b/frontend/src/pages/posts/PostDetailPage.tsx index 74dafc4..908dc9e 100644 --- a/frontend/src/pages/posts/PostDetailPage.tsx +++ b/frontend/src/pages/posts/PostDetailPage.tsx @@ -99,14 +99,14 @@ export default ({ user }: Props) => { {post.viewed ? '閲覧済' : '未閲覧'} - {['admin', 'member'].some (r => r === user.role) && editing && - - { - setPost (newPost) - toast ({ description: '更新しました.' }) - }} /> - } + {(['admin', 'member'].some (r => r === user.role) && editing) && ( + + { + setPost (newPost) + toast ({ description: '更新しました.' }) + }} /> + )} ) : 'Loading...'} diff --git a/frontend/src/pages/posts/PostListPage.tsx b/frontend/src/pages/posts/PostListPage.tsx index 97cf00a..3debc34 100644 --- a/frontend/src/pages/posts/PostListPage.tsx +++ b/frontend/src/pages/posts/PostListPage.tsx @@ -21,12 +21,12 @@ export default () => { const loaderRef = useRef (null) - const loadMore = async () => { + const loadMore = async withCursor => { setLoading (true) const res = await axios.get (`${ API_BASE_URL }/posts`, { params: { tags: tags.join (' '), match: (anyFlg ? 'any' : 'all'), - cursor } }) + ...(withCursor ? { cursor } : { }) } }) const data = toCamel (res.data, { deep: true }) setPosts (posts => [...(posts || []), ...data.posts]) setCursor (data.nextCursor) @@ -42,7 +42,7 @@ export default () => { useEffect(() => { const observer = new IntersectionObserver (entries => { if (entries[0].isIntersecting && !(loading) && cursor) - loadMore () + loadMore (true) }, { threshold: 1 }) const target = loaderRef.current @@ -52,10 +52,9 @@ export default () => { }, [loaderRef, loading]) useEffect (() => { - console.log ('test') - setCursor ('') setPosts (null) - loadMore () + setCursor ('') + loadMore (false) setWikiPage (null) if (tags.length === 1) diff --git a/frontend/src/pages/posts/PostNewPage.tsx b/frontend/src/pages/posts/PostNewPage.tsx index b62dd93..8fd69a1 100644 --- a/frontend/src/pages/posts/PostNewPage.tsx +++ b/frontend/src/pages/posts/PostNewPage.tsx @@ -145,7 +145,7 @@ export default () => { className="w-full border rounded p-2" value={title} placeholder={titleLoading ? 'Loading...' : ''} - onChange={e => setTitle (e.target.value)} + onChange={ev => setTitle (ev.target.value)} disabled={titleAutoFlg} />