mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-07 07:26:46 +00:00
fix 随便逛逛两次点击报错
This commit is contained in:
@@ -3,6 +3,7 @@ import { useRouter } from 'next/router'
|
|||||||
import { useEffect, useState, useRef } from 'react'
|
import { useEffect, useState, useRef } from 'react'
|
||||||
import { useGlobal } from '@/lib/global'
|
import { useGlobal } from '@/lib/global'
|
||||||
import { saveDarkModeToCookies, THEMES } from '@/themes/theme'
|
import { saveDarkModeToCookies, THEMES } from '@/themes/theme'
|
||||||
|
import BLOG from '@/blog.config'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义右键菜单
|
* 自定义右键菜单
|
||||||
@@ -17,10 +18,13 @@ export default function CustomContextMenu(props) {
|
|||||||
|
|
||||||
const { latestPosts } = props
|
const { latestPosts } = props
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
/**
|
||||||
|
* 随机跳转文章
|
||||||
|
*/
|
||||||
function handleJumpToRandomPost() {
|
function handleJumpToRandomPost() {
|
||||||
const randomIndex = Math.floor(Math.random() * latestPosts.length)
|
const randomIndex = Math.floor(Math.random() * latestPosts.length)
|
||||||
const randomPost = latestPosts[randomIndex]
|
const randomPost = latestPosts[randomIndex]
|
||||||
router.push(randomPost.slug)
|
router.push(`${BLOG.SUB_PATH}/${randomPost?.slug}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -55,11 +55,13 @@ function BannerGroup(props) {
|
|||||||
function Banner(props) {
|
function Banner(props) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { latestPosts } = props
|
const { latestPosts } = props
|
||||||
// 跳转到任意文章
|
/**
|
||||||
|
* 随机跳转文章
|
||||||
|
*/
|
||||||
function handleClickBanner() {
|
function handleClickBanner() {
|
||||||
const randomIndex = Math.floor(Math.random() * latestPosts.length)
|
const randomIndex = Math.floor(Math.random() * latestPosts.length)
|
||||||
const randomPost = latestPosts[randomIndex]
|
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">
|
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'
|
import { useRouter } from 'next/router'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6,13 +8,18 @@ import { useRouter } from 'next/router'
|
|||||||
export default function RandomPostButton(props) {
|
export default function RandomPostButton(props) {
|
||||||
const { latestPosts } = props
|
const { latestPosts } = props
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const { locale } = useGlobal()
|
||||||
|
/**
|
||||||
|
* 随机跳转文章
|
||||||
|
*/
|
||||||
function handleClick() {
|
function handleClick() {
|
||||||
const randomIndex = Math.floor(Math.random() * latestPosts.length)
|
const randomIndex = Math.floor(Math.random() * latestPosts.length)
|
||||||
const randomPost = latestPosts[randomIndex]
|
const randomPost = latestPosts[randomIndex]
|
||||||
router.push(randomPost.slug)
|
router.push(`${BLOG.SUB_PATH}/${randomPost?.slug}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
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>
|
<i className="fa-solid fa-podcast"></i>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user