This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import axios from 'axios'
|
||||
import toCamel from 'camelcase-keys'
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { Helmet } from 'react-helmet-async'
|
||||
import { Link, useLocation } from 'react-router-dom'
|
||||
|
||||
@@ -10,7 +10,7 @@ import TabGroup, { Tab } from '@/components/common/TabGroup'
|
||||
import MainArea from '@/components/layout/MainArea'
|
||||
import { API_BASE_URL, SITE_TITLE } from '@/config'
|
||||
|
||||
import type { Post, Tag, WikiPage } from '@/types'
|
||||
import type { Post, WikiPage } from '@/types'
|
||||
|
||||
|
||||
export default () => {
|
||||
@@ -21,13 +21,14 @@ export default () => {
|
||||
|
||||
const loaderRef = useRef<HTMLDivElement | null> (null)
|
||||
|
||||
const loadMore = async withCursor => {
|
||||
const loadMore = async (withCursor: boolean) => {
|
||||
setLoading (true)
|
||||
const res = await axios.get (`${ API_BASE_URL }/posts`, {
|
||||
params: { tags: tags.join (' '),
|
||||
match: (anyFlg ? 'any' : 'all'),
|
||||
...(withCursor ? { cursor } : { }) } })
|
||||
const data = toCamel (res.data, { deep: true })
|
||||
const data = toCamel (res.data as any, { deep: true }) as { posts: Post[]
|
||||
nextCursor: string }
|
||||
setPosts (posts => [...(withCursor ? posts : []), ...data.posts])
|
||||
setCursor (data.nextCursor)
|
||||
setLoading (false)
|
||||
@@ -48,7 +49,9 @@ export default () => {
|
||||
const target = loaderRef.current
|
||||
target && observer.observe (target)
|
||||
|
||||
return () => target && observer.unobserve (target)
|
||||
return () => {
|
||||
target && observer.unobserve (target)
|
||||
}
|
||||
}, [loaderRef, loading])
|
||||
|
||||
useEffect (() => {
|
||||
@@ -62,8 +65,8 @@ export default () => {
|
||||
try
|
||||
{
|
||||
const tagName = tags[0]
|
||||
const { data } = await axios.get (`${ API_BASE_URL }/wiki/title/${ tagName }`)
|
||||
setWikiPage (toCamel (data, { deep: true }))
|
||||
const res = await axios.get (`${ API_BASE_URL }/wiki/title/${ tagName }`)
|
||||
setWikiPage (toCamel (res.data as any, { deep: true }) as WikiPage)
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -84,7 +87,7 @@ export default () => {
|
||||
</Helmet>
|
||||
<TagSidebar posts={posts.slice (0, 20)} />
|
||||
<MainArea>
|
||||
<TabGroup key={wikiPage}>
|
||||
<TabGroup>
|
||||
<Tab name="広場">
|
||||
{posts.length
|
||||
? (
|
||||
@@ -93,9 +96,9 @@ export default () => {
|
||||
<Link to={`/posts/${ post.id }`}
|
||||
key={post.id}
|
||||
className="w-40 h-40 overflow-hidden rounded-lg shadow-md hover:shadow-lg">
|
||||
<img src={post.thumbnail || post.thumbnailBase || null}
|
||||
<img src={post.thumbnail || post.thumbnailBase || undefined}
|
||||
alt={post.title || post.url}
|
||||
title={post.title || post.url || null}
|
||||
title={post.title || post.url || undefined}
|
||||
className="object-none w-full h-full" />
|
||||
</Link>))}
|
||||
</div>)
|
||||
|
||||
Reference in New Issue
Block a user