fix: completed books now have 100% progress (#625)

This commit is contained in:
Huang Xin
2025-03-18 13:00:33 +08:00
committed by GitHub
parent 7648aa47b2
commit 72e6c058f5
8 changed files with 18 additions and 10 deletions
@@ -13,7 +13,8 @@ const getProgressPercentage = (book: Book) => {
if (book.progress && book.progress[1] === 1) {
return 100;
}
return Math.round((book.progress[0] / book.progress[1]) * 100);
const percentage = Math.round((book.progress[0] / book.progress[1]) * 100);
return Math.max(0, Math.min(100, percentage));
};
const ReadingProgress: React.FC<ReadingProgressProps> = memo(
@@ -85,9 +85,8 @@ export const useBooksSync = ({ onSyncStart, onSyncEnd }: UseBooksSyncProps) => {
}
const mergedBook =
matchingBook.updatedAt > oldBook.updatedAt
? { ...oldBook, ...matchingBook, updatedAt: oldBook.updatedAt }
: { ...matchingBook, ...oldBook, updatedAt: oldBook.updatedAt };
mergedBook.progress = matchingBook.progress ?? oldBook.progress;
? { ...oldBook, ...matchingBook }
: { ...matchingBook, ...oldBook };
return mergedBook;
}
return oldBook;
@@ -70,7 +70,9 @@ const FooterBar: React.FC<FooterBarProps> = ({
const isVisible = hoveredBookKey === bookKey;
const progressInfo = bookFormat === 'PDF' ? section : pageinfo;
const progressValid = !!progressInfo;
const progressFraction = progressValid ? (progressInfo!.current + 1) / progressInfo!.total : 0;
const progressFraction = progressValid
? ((progressInfo!.next ?? progressInfo!.current) + 1) / progressInfo!.total
: 0;
return (
<>
@@ -32,7 +32,7 @@ const PageInfoView: React.FC<PageInfoProps> = ({
? _(
isVertical ? '{{currentPage}} · {{totalPage}}' : 'Loc. {{currentPage}} / {{totalPage}}',
{
currentPage: pageinfo.current + 1,
currentPage: (pageinfo.next ?? pageinfo.current) + 1,
totalPage: pageinfo.total,
},
)
@@ -32,7 +32,12 @@ const SectionInfo: React.FC<SectionInfoProps> = ({
: { paddingLeft: `${horizontalGap}%` }
}
>
<h2 className={clsx('text-neutral-content text-center font-sans text-xs font-light')}>
<h2
className={clsx(
'text-neutral-content text-center font-sans text-xs font-light',
isVertical ? '' : 'line-clamp-1',
)}
>
{section || ''}
</h2>
</div>
@@ -66,6 +66,7 @@ export const useBookDataStore = create<BookDataState>((set, get) => ({
const bookIndex = library.findIndex((b) => b.hash === bookKey.split('-')[0]);
if (bookIndex == -1) return;
const book = library.splice(bookIndex, 1)[0]!;
book.progress = config.progress;
book.updatedAt = Date.now();
library.unshift(book);
setLibrary(library);
+1 -1
View File
@@ -222,7 +222,7 @@ export const useReaderStore = create<ReaderStore>((set, get) => ({
const viewState = state.viewStates[key];
if (!viewState || !bookData) return state;
const progress: [number, number] = [pageinfo.current, pageinfo.total];
const progress: [number, number] = [(pageinfo.next ?? pageinfo.current) + 1, pageinfo.total];
// Update library book progress
const { library, setLibrary } = useLibraryStore.getState();
+2 -2
View File
@@ -24,7 +24,7 @@ export interface Book {
downloadedAt?: number | null;
lastUpdated?: number; // deprecated in favor of updatedAt
progress?: [number, number]; // Add progress field: [current, total]
progress?: [number, number]; // Add progress field: [current, total], 1-based page number
}
export interface BookGroupType {
@@ -149,7 +149,7 @@ export interface BookSearchResult {
export interface BookConfig {
bookHash?: string;
progress?: [number, number];
progress?: [number, number]; // [current pagenum, total pagenum], 1-based page number
location?: string;
booknotes?: BookNote[];
searchConfig?: Partial<BookSearchConfig>;