Skip to content

Commit

Permalink
Merge pull request tangly1024#1840 from tangly1024/fix/plog-modal-toggle
Browse files Browse the repository at this point in the history
plog 模态框隐藏
  • Loading branch information
tangly1024 authored Jan 31, 2024
2 parents 003b358 + e90ba11 commit 1bb329d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
11 changes: 6 additions & 5 deletions themes/plog/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function Modal(props) {
// 修改当前显示的遮罩内容
function prev() {
setLoading(true)
const index = posts.findIndex(post => post.slug === modalContent.slug)
const index = posts?.findIndex(post => post.slug === modalContent.slug)
if (index === 0) {
setModalContent(posts[posts.length - 1])
} else {
Expand Down Expand Up @@ -90,10 +90,11 @@ export default function Modal(props) {

{!loading && (<>
<div className='absolute bottom-0 left-0 m-4 z-20'>
<div className='flex'>
<h2 style={{ textShadow: '0.1em 0.1em 0.2em black' }} className='text-2xl md:text-5xl text-white mb-4 px-2 py-1 rounded-lg'>{modalContent?.title}</h2>
</div>

<Link href={`${siteConfig('SUB_PATH', '')}/${modalContent.slug}`}>
<div className='flex'>
<h2 style={{ textShadow: '0.1em 0.1em 0.2em black' }} className='text-2xl md:text-5xl text-white mb-4 px-2 py-1 rounded-lg'>{modalContent?.title}</h2>
</div>
</Link>
<Link href={`${siteConfig('SUB_PATH', '')}/${modalContent.slug}`}>
<div style={{ textShadow: '0.1em 0.1em 0.2em black' }} className={'line-clamp-3 md:line-clamp-none overflow-hidden cursor-pointer text-gray-50 rounded-lg m-2'}>
{modalContent?.summary}
Expand Down
15 changes: 15 additions & 0 deletions themes/plog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Modal from './components/Modal'
import { Style } from './style'
import replaceSearchResult from '@/components/Mark'
import CommonHead from '@/components/CommonHead'
import { useRouter } from 'next/router'

// 主题全局状态
const ThemeGlobalPlog = createContext()
Expand All @@ -38,6 +39,20 @@ const LayoutBase = props => {
const [showModal, setShowModal] = useState(false)
const [modalContent, setModalContent] = useState(null)

// 页面切换关闭遮罩
const router = useRouter()
const closeModal = ()=>{
setShowModal(false)
}

useEffect(() => {
router.events.on('routeChangeComplete', closeModal)
return () => {
router.events.off('routeChangeComplete', closeModal)
}
}, [router.events])


return (
<ThemeGlobalPlog.Provider value={{ showModal, setShowModal, modalContent, setModalContent }}>
<div id='theme-plog' className='plog relative dark:text-gray-300 w-full dark:bg-black min-h-screen'>
Expand Down

0 comments on commit 1bb329d

Please sign in to comment.