Skip to content

Commit

Permalink
Merge pull request tangly1024#439 from tangly1024/bugfix/blogs-from-tag
Browse files Browse the repository at this point in the history
补充提交
  • Loading branch information
tangly1024 authored Nov 13, 2022
2 parents 7833d0d + e020461 commit 6c07ffe
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions themes/hexo/components/BlogPostListScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import BlogPostCard from './BlogPostCard'
import BlogPostListEmpty from './BlogPostListEmpty'
import { useGlobal } from '@/lib/global'
import throttle from 'lodash.throttle'
import React, { useCallback, useEffect, useRef, useState } from 'react'
import React from 'react'
import CONFIG_HEXO from '../config_hexo'
import { getListByPage } from '@/lib/utils'

Expand All @@ -16,7 +16,7 @@ import { getListByPage } from '@/lib/utils'
*/
const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG_HEXO.POST_LIST_SUMMARY }) => {
const postsPerPage = BLOG.POSTS_PER_PAGE
const [page, updatePage] = useState(1)
const [page, updatePage] = React.useState(1)
const postsToShow = getListByPage(posts, page, postsPerPage)

let hasMore = false
Expand All @@ -31,7 +31,7 @@ const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG_HE
}

// 监听滚动自动分页加载
const scrollTrigger = useCallback(throttle(() => {
const scrollTrigger = React.useCallback(throttle(() => {
const scrollS = window.scrollY + window.outerHeight
const clientHeight = targetRef ? (targetRef.current ? (targetRef.current.clientHeight) : 0) : 0
if (scrollS > clientHeight + 100) {
Expand All @@ -40,14 +40,14 @@ const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG_HE
}, 500))

// 监听滚动
useEffect(() => {
React.useEffect(() => {
window.addEventListener('scroll', scrollTrigger)
return () => {
window.removeEventListener('scroll', scrollTrigger)
}
})

const targetRef = useRef(null)
const targetRef = React.useRef(null)
const { locale } = useGlobal()

if (!postsToShow || postsToShow.length === 0) {
Expand Down

0 comments on commit 6c07ffe

Please sign in to comment.