From 565b3ac194ce3797f7d141e0430681c8d9ebfe34 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 22 Dec 2021 16:22:17 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E7=9B=AE=E5=BD=95=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=99=BE=E5=88=86=E6=AF=94=E8=BF=9B=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/ArticleDetail.js | 7 +++++-- components/JumpToBottomButton.js | 2 +- components/JumpToTopButton.js | 4 ++-- components/Progress.js | 7 ++++--- components/SideAreaLeft.js | 7 ++++--- components/Toc.js | 10 +++++++--- components/TocDrawer.js | 8 ++++---- layouts/BaseLayout.js | 4 ++-- lib/cache/cache_manager.js | 7 ++++--- 9 files changed, 33 insertions(+), 23 deletions(-) diff --git a/components/ArticleDetail.js b/components/ArticleDetail.js index e00fa544..3469ff17 100644 --- a/components/ArticleDetail.js +++ b/components/ArticleDetail.js @@ -165,10 +165,13 @@ export default function ArticleDetail ({ post, blockMap, recommendPosts, prev, n {/* 悬浮目录按钮 */}
{ drawerRight.current.handleSwitchVisible() }} /> - +
- + {/* 移动端顶部进度条 */} + {/*
+ +
*/} ) } diff --git a/components/JumpToBottomButton.js b/components/JumpToBottomButton.js index dbebfca2..7b87eaf1 100644 --- a/components/JumpToBottomButton.js +++ b/components/JumpToBottomButton.js @@ -12,7 +12,7 @@ import smoothscroll from 'smoothscroll-polyfill' * @returns {JSX.Element} * @constructor */ -const JumpToBottomButton = ({ targetRef, showPercent = true }) => { +const JumpToBottomButton = ({ targetRef, showPercent = false }) => { const { locale } = useGlobal() const [show, switchShow] = useState(false) const [percent, changePercent] = useState(0) diff --git a/components/JumpToTopButton.js b/components/JumpToTopButton.js index 792d9c93..a1d4454b 100644 --- a/components/JumpToTopButton.js +++ b/components/JumpToTopButton.js @@ -12,7 +12,7 @@ import smoothscroll from 'smoothscroll-polyfill' * @returns {JSX.Element} * @constructor */ -const JumpToTopButton = ({ targetRef, showPercent = true }) => { +const JumpToTopButton = ({ targetRef, showPercent = false }) => { const { locale } = useGlobal() const [show, switchShow] = useState(false) const [percent, changePercent] = useState(0) @@ -39,7 +39,7 @@ const JumpToTopButton = ({ targetRef, showPercent = true }) => { return (
window.scrollTo({ top: 0, behavior: 'smooth' })} - className={(show ? '' : 'hidden') + ' animate__fadeInRight animate__animated animate__faster shadow-card rounded-xl glassmorphism py-1 cursor-pointer '}> + className={(show ? '' : 'hidden') + ' animate__fadeInRight animate__animated animate__faster shadow-card rounded-xl glassmorphism py-3 cursor-pointer '}>
diff --git a/components/Progress.js b/components/Progress.js index 1ce7083a..7a35457f 100644 --- a/components/Progress.js +++ b/components/Progress.js @@ -8,7 +8,7 @@ import React, { useEffect, useState } from 'react' const Progress = ({ targetRef }) => { const [percent, changePercent] = useState(0) const scrollListener = () => { - if (targetRef.current) { + if (targetRef?.current) { const clientHeight = targetRef ? (targetRef.current.clientHeight) : 0 const scrollY = window.pageYOffset const fullHeight = clientHeight - window.outerHeight @@ -23,8 +23,9 @@ const Progress = ({ targetRef }) => { return () => document.removeEventListener('scroll', scrollListener) }, [percent]) - return (
-
+ return (
+
{percent}%
+
) } diff --git a/components/SideAreaLeft.js b/components/SideAreaLeft.js index 025480e1..aa089ae4 100644 --- a/components/SideAreaLeft.js +++ b/components/SideAreaLeft.js @@ -8,6 +8,7 @@ import { faAngleDoubleRight, faChartBar, faThList } from '@fortawesome/free-soli import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import Link from 'next/link' import React from 'react' +import Progress from './Progress' /** * 侧边平铺 @@ -21,7 +22,7 @@ import React from 'react' * @returns {JSX.Element} * @constructor */ -const SideAreaLeft = ({ title, tags, currentTag, post, posts, categories, currentCategory, currentSearch }) => { +const SideAreaLeft = ({ title, tags, currentTag, post, posts, categories, currentCategory, currentSearch, targetRef }) => { const { locale } = useGlobal() const showToc = post && post.toc && post.toc.length > 1 const postCount = posts?.length || 0 @@ -71,10 +72,10 @@ const SideAreaLeft = ({ title, tags, currentTag, post, posts, categories, curren {showToc && (
-
+
{locale.COMMON.TABLE_OF_CONTENTS}
- +
)} diff --git a/components/Toc.js b/components/Toc.js index 55c640e1..5818a16d 100644 --- a/components/Toc.js +++ b/components/Toc.js @@ -1,6 +1,7 @@ import React, { useCallback } from 'react' import throttle from 'lodash.throttle' import { uuidToId } from 'notion-utils' +import Progress from './Progress' // import { cs } from 'react-notion-x' /** @@ -9,7 +10,7 @@ import { uuidToId } from 'notion-utils' * @returns {JSX.Element} * @constructor */ -const Toc = ({ toc }) => { +const Toc = ({ toc, targetRef }) => { // 无目录就直接返回空 if (!toc || toc.length < 1) return <> @@ -51,6 +52,9 @@ const Toc = ({ toc }) => { }, throttleMs)) return <> +
+ +