|
|
@@ -21,12 +21,12 @@ export default () => { |
|
|
|
|
|
|
|
const loaderRef = useRef<HTMLDivElement | null> (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) |
|
|
|