Enhance book cover handling in components

- Added a timestamp query parameter to book cover URLs that do not start with "data:", "blob:", or "http" to prevent caching issues.
- Updated the state management to refresh the book cover in BookCardItem, BookCoverItem, and BookListItem components.
This commit is contained in:
troyeguo
2026-03-26 10:19:32 +08:00
parent 2d55ce521c
commit 14a09f9ca1
10 changed files with 37 additions and 2 deletions

View File

File diff suppressed because one or more lines are too long

View File

@@ -46,6 +46,14 @@ class BookCardItem extends React.Component<BookCardProps, BookCardState> {
) {
let cover = await CoverUtil.getCover(nextProps.book);
let isCoverExist = await CoverUtil.isCoverExist(nextProps.book);
if (
cover &&
!cover.startsWith("data:") &&
!cover.startsWith("blob:") &&
!cover.startsWith("http")
) {
cover = cover + "?t=" + Date.now();
}
this.setState({
isFavorite:
ConfigService.getAllListConfig("favoriteBooks").indexOf(
@@ -57,6 +65,7 @@ class BookCardItem extends React.Component<BookCardProps, BookCardState> {
this.setState({
isBookOffline: await BookUtil.isBookOffline(nextProps.book.key),
});
this.props.handleRefreshBookCover("");
}
}

View File

@@ -6,6 +6,7 @@ import {
handleDeleteDialog,
handleSelectBook,
handleSelectedBooks,
handleRefreshBookCover,
} from "../../store/actions";
import { withTranslation } from "react-i18next";
import BookCardItem from "./component";
@@ -29,6 +30,7 @@ const actionCreator = {
handleSelectBook,
handleDeleteDialog,
handleSelectedBooks,
handleRefreshBookCover,
};
export default connect(
mapStateToProps,

View File

@@ -17,6 +17,7 @@ export interface BookCardProps extends RouteComponentProps<any> {
handleDragItem: (key: string) => void;
handleSelectedBooks: (selectedBooks: string[]) => void;
handleDeleteDialog: (isShow: boolean) => void;
handleRefreshBookCover: (key: string) => void;
}
export interface BookCardState {
isFavorite: boolean;

View File

@@ -48,6 +48,14 @@ class BookCoverItem extends React.Component<BookCoverProps, BookCoverState> {
) {
let cover = await CoverUtil.getCover(nextProps.book);
let isCoverExist = await CoverUtil.isCoverExist(nextProps.book);
if (
cover &&
!cover.startsWith("data:") &&
!cover.startsWith("blob:") &&
!cover.startsWith("http")
) {
cover = cover + "?t=" + Date.now();
}
this.setState({
isFavorite:
ConfigService.getAllListConfig("favoriteBooks").indexOf(
@@ -59,6 +67,7 @@ class BookCoverItem extends React.Component<BookCoverProps, BookCoverState> {
this.setState({
isBookOffline: await BookUtil.isBookOffline(nextProps.book.key),
});
this.props.handleRefreshBookCover("");
}
}
handleMoreAction = (event: any) => {

View File

@@ -6,6 +6,7 @@ import {
handleDeleteDialog,
handleSelectedBooks,
handleSelectBook,
handleRefreshBookCover,
} from "../../store/actions";
import BookCoverItem from "./component";
import { stateType } from "../../store";
@@ -30,6 +31,7 @@ const actionCreator = {
handleDeleteDialog,
handleSelectBook,
handleSelectedBooks,
handleRefreshBookCover,
};
export default connect(
mapStateToProps,

View File

@@ -12,7 +12,7 @@ export interface BookCoverProps extends RouteComponentProps<any> {
selectedBooks: string[];
refreshBookKey: string;
handleSelectBook: (isSelectBook: boolean) => void;
handleRefreshBookCover: (key: string) => void;
handleReadingBook: (book: BookModel) => void;
handleActionDialog: (isShowActionDialog: boolean) => void;
t: (title: string) => string;

View File

@@ -46,6 +46,14 @@ class BookListItem extends React.Component<BookItemProps, BookItemState> {
) {
let cover = await CoverUtil.getCover(nextProps.book);
let isCoverExist = await CoverUtil.isCoverExist(nextProps.book);
if (
cover &&
!cover.startsWith("data:") &&
!cover.startsWith("blob:") &&
!cover.startsWith("http")
) {
cover = cover + "?t=" + Date.now();
}
this.setState({
isFavorite:
ConfigService.getAllListConfig("favoriteBooks").indexOf(
@@ -57,6 +65,7 @@ class BookListItem extends React.Component<BookItemProps, BookItemState> {
this.setState({
isBookOffline: await BookUtil.isBookOffline(nextProps.book.key),
});
this.props.handleRefreshBookCover("");
}
}
handleDeleteBook = () => {

View File

@@ -9,6 +9,7 @@ import {
handleSelectedBooks,
handleSelectBook,
handleActionDialog,
handleRefreshBookCover,
} from "../../store/actions";
import { withTranslation } from "react-i18next";
@@ -36,6 +37,7 @@ const actionCreator = {
handleSelectBook,
handleFetchBooks,
handleSelectedBooks,
handleRefreshBookCover,
};
export default connect(
mapStateToProps,

View File

@@ -11,6 +11,7 @@ export interface BookItemProps extends RouteComponentProps<any> {
isSelected: boolean;
selectedBooks: string[];
refreshBookKey: string;
handleRefreshBookCover: (key: string) => void;
handleSelectBook: (isSelectBook: boolean) => void;
handleReadingBook: (book: BookModel) => void;
handleEditDialog: (isShow: boolean) => void;