Example主题调整,规范组件命名

This commit is contained in:
tangly1024.com
2024-04-28 15:03:48 +08:00
parent cda0890785
commit 2385ad868f
26 changed files with 773 additions and 638 deletions

View File

@@ -1,10 +1,14 @@
import { siteConfig } from '@/lib/config'
import { useGlobal } from '@/lib/global'
import { useCallback, useEffect, useRef, useState } from 'react'
import throttle from 'lodash.throttle'
import BlogPostCard from './BlogPostCard'
import { useCallback, useEffect, useRef, useState } from 'react'
import CONFIG from '../config'
import BlogItem from './BlogItem'
/**
* 使用滚动无限加载的博客列表
* @param {*} props
* @returns
*/
export const BlogListScroll = props => {
const { posts } = props
const { locale } = useGlobal()
@@ -13,7 +17,10 @@ export const BlogListScroll = props => {
let hasMore = false
const postsToShow = posts
? Object.assign(posts).slice(0, parseInt(siteConfig('POSTS_PER_PAGE')) * page)
? Object.assign(posts).slice(
0,
parseInt(siteConfig('POSTS_PER_PAGE')) * page
)
: []
if (posts) {
@@ -28,13 +35,19 @@ export const BlogListScroll = props => {
const targetRef = useRef(null)
// 监听滚动自动分页加载
const scrollTrigger = useCallback(throttle(() => {
const scrollS = window.scrollY + window.outerHeight
const clientHeight = targetRef ? (targetRef.current ? (targetRef.current.clientHeight) : 0) : 0
if (scrollS > clientHeight + 100) {
handleGetMore()
}
}, 500))
const scrollTrigger = useCallback(
throttle(() => {
const scrollS = window.scrollY + window.outerHeight
const clientHeight = targetRef
? targetRef.current
? targetRef.current.clientHeight
: 0
: 0
if (scrollS > clientHeight + 100) {
handleGetMore()
}
}, 500)
)
const showPageCover = siteConfig('EXAMPLE_POST_LIST_COVER', null, CONFIG)
useEffect(() => {
@@ -46,21 +59,20 @@ export const BlogListScroll = props => {
})
return (
<div
id='posts-wrapper'
className={`w-full ${showPageCover ? 'md:pr-2' : 'md:pr-12'}} mb-12`}
ref={targetRef}>
{postsToShow?.map(post => (
<BlogItem key={post.id} post={post} />
))}
<div id='posts-wrapper' className={`w-full ${showPageCover ? 'md:pr-2' : 'md:pr-12'}} mb-12`} ref={targetRef}>
{postsToShow?.map(post => (
<BlogPostCard key={post.id} post={post} />
))}
<div
onClick={handleGetMore}
className="w-full my-4 py-4 text-center cursor-pointer "
>
{' '}
{hasMore ? locale.COMMON.MORE : `${locale.COMMON.NO_MORE} 😰`}{' '}
</div>
</div>
<div
onClick={handleGetMore}
className='w-full my-4 py-4 text-center cursor-pointer '>
{' '}
{hasMore ? locale.COMMON.MORE : `${locale.COMMON.NO_MORE} 😰`}{' '}
</div>
</div>
)
}