mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 15:09:22 +00:00
fix 随便逛逛两次点击报错
This commit is contained in:
@@ -3,6 +3,7 @@ import { useRouter } from 'next/router'
|
||||
import { useEffect, useState, useRef } from 'react'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import { saveDarkModeToCookies, THEMES } from '@/themes/theme'
|
||||
import BLOG from '@/blog.config'
|
||||
|
||||
/**
|
||||
* 自定义右键菜单
|
||||
@@ -17,10 +18,13 @@ export default function CustomContextMenu(props) {
|
||||
|
||||
const { latestPosts } = props
|
||||
const router = useRouter()
|
||||
/**
|
||||
* 随机跳转文章
|
||||
*/
|
||||
function handleJumpToRandomPost() {
|
||||
const randomIndex = Math.floor(Math.random() * latestPosts.length)
|
||||
const randomPost = latestPosts[randomIndex]
|
||||
router.push(randomPost.slug)
|
||||
router.push(`${BLOG.SUB_PATH}/${randomPost?.slug}`)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -55,11 +55,13 @@ function BannerGroup(props) {
|
||||
function Banner(props) {
|
||||
const router = useRouter()
|
||||
const { latestPosts } = props
|
||||
// 跳转到任意文章
|
||||
/**
|
||||
* 随机跳转文章
|
||||
*/
|
||||
function handleClickBanner() {
|
||||
const randomIndex = Math.floor(Math.random() * latestPosts.length)
|
||||
const randomPost = latestPosts[randomIndex]
|
||||
router.push(randomPost.slug)
|
||||
router.push(`${BLOG.SUB_PATH}/${randomPost?.slug}`)
|
||||
}
|
||||
|
||||
return <div id='banners' onClick={handleClickBanner} className="hidden xl:flex xl:flex-col group h-full bg-white dark:bg-[#1e1e1e] rounded-xl border dark:border-gray-700 mb-3 relative overflow-hidden">
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import BLOG from '@/blog.config'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
/**
|
||||
@@ -6,13 +8,18 @@ import { useRouter } from 'next/router'
|
||||
export default function RandomPostButton(props) {
|
||||
const { latestPosts } = props
|
||||
const router = useRouter()
|
||||
const { locale } = useGlobal()
|
||||
/**
|
||||
* 随机跳转文章
|
||||
*/
|
||||
function handleClick() {
|
||||
const randomIndex = Math.floor(Math.random() * latestPosts.length)
|
||||
const randomPost = latestPosts[randomIndex]
|
||||
router.push(randomPost.slug)
|
||||
router.push(`${BLOG.SUB_PATH}/${randomPost?.slug}`)
|
||||
}
|
||||
|
||||
return (
|
||||
<div title={'随机前往一篇文章'} className='cursor-pointer hover:bg-black hover:bg-opacity-10 rounded-full w-10 h-10 flex justify-center items-center duration-200 transition-all' onClick={handleClick}>
|
||||
<div title={locale.MENU.WALK_AROUND} className='cursor-pointer hover:bg-black hover:bg-opacity-10 rounded-full w-10 h-10 flex justify-center items-center duration-200 transition-all' onClick={handleClick}>
|
||||
<i className="fa-solid fa-podcast"></i>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user