Skip to content

Commit

Permalink
feat: 尝试react scan
Browse files Browse the repository at this point in the history
  • Loading branch information
coderz-w committed Nov 26, 2024
1 parent 8af2b78 commit bd7cdcb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions .million/store.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"encodings":[],"reactData":{},"unusedFiles":[],"mtime":null}
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export default async function RootLayout({ children }: PropsWithChildren) {
return (
<html lang="zh-CN" className=" noise" suppressHydrationWarning>
<head>
{/* react scan */}
{/* <script src="https://unpkg.com/react-scan/dist/auto.global.js" async></script> */}
<SayHi />
<AccentColorStyleInjector />
</head>
Expand Down
30 changes: 18 additions & 12 deletions src/components/modules/shared/ReadIndicator.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { useEffect, useState } from 'react';
import { memo, useDeferredValue, useEffect, useState } from 'react';

import { MaterialSymbolsProgressActivity } from '@/components/icons/Progress';
import { MotionButtonBase } from '@/components/ui/button';
Expand Down Expand Up @@ -35,21 +35,27 @@ export const ReadIndicator = () => {
}, [Element]);

return (
<div className="text-gray-800 dark:text-neutral-300">
<div className="text-gray-800 dark:text-neutral-300 gap-4">
<div className="flex items-center gap-2">
<MaterialSymbolsProgressActivity progress={readPercent} />
{readPercent}%<br />
</div>
<MotionButtonBase
onClick={springScrollToTop}
className={cn(
'mt-1 flex flex-nowrap items-center gap-2 opacity-50 transition-all duration-500 hover:opacity-100',
readPercent > 10 ? '' : 'pointer-events-none opacity-0',
)}
>
<i className="i-mingcute-arrow-up-circle-line" />
<span className="whitespace-nowrap">回到顶部</span>
</MotionButtonBase>
<BackToTop readPercent={useDeferredValue(readPercent)} />
</div>
);
};

const BackToTop = memo(({ readPercent }: { readPercent: number }) => {
return (
<MotionButtonBase
onClick={springScrollToTop}
className={cn(
'mt-1 flex flex-nowrap items-center gap-2 opacity-50 transition-all duration-500 hover:opacity-100',
readPercent > 10 ? '' : 'pointer-events-none opacity-0',
)}
>
<i className="i-mingcute-arrow-up-circle-line" />
<span className="whitespace-nowrap">回到顶部</span>
</MotionButtonBase>
);
});

0 comments on commit bd7cdcb

Please sign in to comment.