Fix the status linger problem of drawer toc
This commit is contained in:
@@ -37,7 +37,7 @@ import remarkMath from "remark-math";
|
|||||||
import remarkPrism from "remark-prism";
|
import remarkPrism from "remark-prism";
|
||||||
|
|
||||||
type ReaderPageProps = {
|
type ReaderPageProps = {
|
||||||
source: MDXRemoteSerializeResult;
|
compiledSource: MDXRemoteSerializeResult;
|
||||||
tocList: TTOCItem[];
|
tocList: TTOCItem[];
|
||||||
frontMatter: TFrontmatter;
|
frontMatter: TFrontmatter;
|
||||||
postId: string;
|
postId: string;
|
||||||
@@ -46,14 +46,19 @@ type ReaderPageProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const ReaderPage = (props: ReaderPageProps) => {
|
const ReaderPage = (props: ReaderPageProps) => {
|
||||||
const source = props.source;
|
const compiledSource = props.compiledSource;
|
||||||
const setIsTOCOpen = useDrawerTOCState((state) => state.changeDrawerTOCOpen);
|
const setIsTOCOpen = useDrawerTOCState((state) => state.changeDrawerTOCOpen);
|
||||||
|
|
||||||
|
// Only the TOC length reaches 3 can be displayed.
|
||||||
|
// In order to avoid large blank spaces that ruin the visual perception
|
||||||
|
const isTOCLongEnough = props.tocList.length > 2;
|
||||||
const handleRightSwipe = useSwipeable({
|
const handleRightSwipe = useSwipeable({
|
||||||
onSwipedRight: () => {
|
onSwipedRight: () => {
|
||||||
setIsTOCOpen(true);
|
isTOCLongEnough && setIsTOCOpen(true);
|
||||||
},
|
},
|
||||||
delta: 120,
|
delta: 150,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<SEO
|
<SEO
|
||||||
@@ -101,11 +106,11 @@ const ReaderPage = (props: ReaderPageProps) => {
|
|||||||
}`}
|
}`}
|
||||||
{...handleRightSwipe}
|
{...handleRightSwipe}
|
||||||
>
|
>
|
||||||
{source && (
|
{compiledSource && (
|
||||||
<MDXRemote
|
<MDXRemote
|
||||||
compiledSource={source.compiledSource}
|
compiledSource={compiledSource.compiledSource}
|
||||||
frontmatter={source.frontmatter}
|
frontmatter={compiledSource.frontmatter}
|
||||||
scope={source.scope}
|
scope={compiledSource.scope}
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
components={MDXComponentsSet}
|
components={MDXComponentsSet}
|
||||||
/>
|
/>
|
||||||
@@ -144,13 +149,13 @@ const ReaderPage = (props: ReaderPageProps) => {
|
|||||||
</ul>
|
</ul>
|
||||||
<PostComments postId={props.postId} />
|
<PostComments postId={props.postId} />
|
||||||
</div>
|
</div>
|
||||||
{props.tocList.length > 2 && (
|
{isTOCLongEnough && (
|
||||||
<div className="hidden md:block md:w-1/3">
|
<div className="hidden md:block md:w-1/3">
|
||||||
<TOC data={props.tocList} />
|
<TOC data={props.tocList} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{props.tocList.length > 2 && (
|
{isTOCLongEnough && (
|
||||||
<div className="md:hidden">
|
<div className="md:hidden">
|
||||||
<DrawerTOC data={props.tocList} />
|
<DrawerTOC data={props.tocList} />
|
||||||
</div>
|
</div>
|
||||||
@@ -208,7 +213,7 @@ export const getStaticProps: GetStaticProps<ReaderPageProps> = async (context) =
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
source: mdxSource,
|
compiledSource: mdxSource,
|
||||||
tocList: tocList,
|
tocList: tocList,
|
||||||
frontMatter: frontMatter,
|
frontMatter: frontMatter,
|
||||||
postId: postId,
|
postId: postId,
|
||||||
|
|||||||
Reference in New Issue
Block a user