移除日期未知和修正页面定位
This commit is contained in:
@@ -16,6 +16,7 @@ import { SiteProvider } from '../components/SiteProvider';
|
|||||||
import { ThemeProvider } from '../components/ThemeProvider';
|
import { ThemeProvider } from '../components/ThemeProvider';
|
||||||
import { TokenRefreshManager } from '../components/TokenRefreshManager';
|
import { TokenRefreshManager } from '../components/TokenRefreshManager';
|
||||||
import TopProgressBar from '../components/TopProgressBar';
|
import TopProgressBar from '../components/TopProgressBar';
|
||||||
|
import RouteScrollReset from '../components/RouteScrollReset';
|
||||||
import ChatFloatingWindow from '../components/watch-room/ChatFloatingWindow';
|
import ChatFloatingWindow from '../components/watch-room/ChatFloatingWindow';
|
||||||
import { WatchRoomProvider } from '../components/WatchRoomProvider';
|
import { WatchRoomProvider } from '../components/WatchRoomProvider';
|
||||||
import { DownloadProvider } from '../contexts/DownloadContext';
|
import { DownloadProvider } from '../contexts/DownloadContext';
|
||||||
@@ -268,6 +269,7 @@ export default async function RootLayout({
|
|||||||
disableTransitionOnChange
|
disableTransitionOnChange
|
||||||
>
|
>
|
||||||
<TopProgressBar />
|
<TopProgressBar />
|
||||||
|
<RouteScrollReset />
|
||||||
<TokenRefreshManager />
|
<TokenRefreshManager />
|
||||||
<SiteProvider siteName={siteName} announcement={announcement} tmdbApiKey={tmdbApiKey}>
|
<SiteProvider siteName={siteName} announcement={announcement} tmdbApiKey={tmdbApiKey}>
|
||||||
<WatchRoomProvider>
|
<WatchRoomProvider>
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ function MangaDetailSkeleton() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatChapterMeta(chapter: MangaChapter): string {
|
function formatChapterMeta(chapter: MangaChapter): string | null {
|
||||||
if (typeof chapter.pageCount === 'number' && chapter.pageCount > 0) {
|
if (typeof chapter.pageCount === 'number' && chapter.pageCount > 0) {
|
||||||
return `${chapter.pageCount} 页`;
|
return `${chapter.pageCount} 页`;
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ function formatChapterMeta(chapter: MangaChapter): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return '日期未知';
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function MangaDetailPage() {
|
export default function MangaDetailPage() {
|
||||||
@@ -264,8 +264,11 @@ export default function MangaDetailPage() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className='mt-1 text-xs text-gray-500'>
|
<div className='mt-1 text-xs text-gray-500'>
|
||||||
{formatChapterMeta(chapter)}
|
{(() => {
|
||||||
{active && currentRecord ? ` · 上次看到第 ${currentRecord.pageIndex + 1} 页` : ''}
|
const meta = formatChapterMeta(chapter);
|
||||||
|
const progress = active && currentRecord ? `上次看到第 ${currentRecord.pageIndex + 1} 页` : null;
|
||||||
|
return [meta, progress].filter(Boolean).join(' · ');
|
||||||
|
})()}
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ export default function MangaReadPage() {
|
|||||||
const requestVerticalPageSyncRef = useRef<(() => void) | null>(null);
|
const requestVerticalPageSyncRef = useRef<(() => void) | null>(null);
|
||||||
const currentVerticalPageIndexRef = useRef(0);
|
const currentVerticalPageIndexRef = useRef(0);
|
||||||
const preloadedImageUrlsRef = useRef<Set<string>>(new Set());
|
const preloadedImageUrlsRef = useRef<Set<string>>(new Set());
|
||||||
|
const activeChapterRef = useRef<HTMLAnchorElement | null>(null);
|
||||||
|
|
||||||
const getCurrentVerticalPageIndex = () => {
|
const getCurrentVerticalPageIndex = () => {
|
||||||
if (!verticalPageRefs.current.length) return 0;
|
if (!verticalPageRefs.current.length) return 0;
|
||||||
@@ -642,6 +643,22 @@ export default function MangaReadPage() {
|
|||||||
[chapterList, chapterListDesc]
|
[chapterList, chapterListDesc]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!chapterListOpen) return;
|
||||||
|
|
||||||
|
const rafId = window.requestAnimationFrame(() => {
|
||||||
|
activeChapterRef.current?.scrollIntoView({
|
||||||
|
block: 'center',
|
||||||
|
inline: 'nearest',
|
||||||
|
behavior: 'auto',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.cancelAnimationFrame(rafId);
|
||||||
|
};
|
||||||
|
}, [chapterId, chapterListOpen, orderedChapterList]);
|
||||||
|
|
||||||
const pagedItems = useMemo(() => {
|
const pagedItems = useMemo(() => {
|
||||||
if (readMode === 'single') {
|
if (readMode === 'single') {
|
||||||
return pages[activePage] ? [pages[activePage]] : [];
|
return pages[activePage] ? [pages[activePage]] : [];
|
||||||
@@ -798,6 +815,7 @@ export default function MangaReadPage() {
|
|||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
key={chapter.id}
|
key={chapter.id}
|
||||||
|
ref={active ? activeChapterRef : null}
|
||||||
href={`/manga/read?mangaId=${mangaId}&sourceId=${sourceId}&chapterId=${chapter.id}&title=${encodeURIComponent(title)}&cover=${encodeURIComponent(cover)}&sourceName=${encodeURIComponent(sourceName)}&chapterName=${encodeURIComponent(chapter.name)}&returnTo=${encodeURIComponent(returnTo)}`}
|
href={`/manga/read?mangaId=${mangaId}&sourceId=${sourceId}&chapterId=${chapter.id}&title=${encodeURIComponent(title)}&cover=${encodeURIComponent(cover)}&sourceName=${encodeURIComponent(sourceName)}&chapterName=${encodeURIComponent(chapter.name)}&returnTo=${encodeURIComponent(returnTo)}`}
|
||||||
className={`group relative block rounded-2xl px-4 py-3 text-sm transition ${
|
className={`group relative block rounded-2xl px-4 py-3 text-sm transition ${
|
||||||
active
|
active
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { usePathname } from 'next/navigation';
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
|
export default function RouteScrollReset() {
|
||||||
|
const pathname = usePathname();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof window === 'undefined' || !pathname?.startsWith('/manga') || pathname === '/manga/read') return;
|
||||||
|
|
||||||
|
const reset = () => {
|
||||||
|
window.scrollTo({ top: 0, left: 0, behavior: 'auto' });
|
||||||
|
document.documentElement.scrollTop = 0;
|
||||||
|
document.body.scrollTop = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
reset();
|
||||||
|
const rafId = window.requestAnimationFrame(reset);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.cancelAnimationFrame(rafId);
|
||||||
|
};
|
||||||
|
}, [pathname]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user