From b9f1882a57f5546eda37182515cff2750de46c28 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 9 Jan 2024 19:27:16 +0200 Subject: [PATCH] Fixed: Refresh book files after renaming --- .../Author/Details/AuthorDetailsConnector.js | 1 - .../src/Book/Details/BookDetailsConnector.js | 41 +++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/frontend/src/Author/Details/AuthorDetailsConnector.js b/frontend/src/Author/Details/AuthorDetailsConnector.js index e68c9d023..c2c0571fd 100644 --- a/frontend/src/Author/Details/AuthorDetailsConnector.js +++ b/frontend/src/Author/Details/AuthorDetailsConnector.js @@ -155,7 +155,6 @@ function createMapStateToProps() { const isRefreshing = isAuthorRefreshing || allAuthorRefreshing; const isSearching = isCommandExecuting(findCommand(commands, { name: commandNames.AUTHOR_SEARCH, authorId: author.id })); const isRenamingFiles = isCommandExecuting(findCommand(commands, { name: commandNames.RENAME_FILES, authorId: author.id })); - const isRenamingAuthorCommand = findCommand(commands, { name: commandNames.RENAME_AUTHOR }); const isRenamingAuthor = ( isCommandExecuting(isRenamingAuthorCommand) && diff --git a/frontend/src/Book/Details/BookDetailsConnector.js b/frontend/src/Book/Details/BookDetailsConnector.js index 473c038f5..98778ff61 100644 --- a/frontend/src/Book/Details/BookDetailsConnector.js +++ b/frontend/src/Book/Details/BookDetailsConnector.js @@ -69,16 +69,21 @@ function createMapStateToProps() { const previousBook = sortedBooks[bookIndex - 1] || _.last(sortedBooks); const nextBook = sortedBooks[bookIndex + 1] || _.first(sortedBooks); + const isRefreshingCommand = findCommand(commands, { name: commandNames.REFRESH_BOOK }); + const isRefreshing = ( + isCommandExecuting(isRefreshingCommand) && + isRefreshingCommand.body.bookId === book.id + ); const isSearchingCommand = findCommand(commands, { name: commandNames.BOOK_SEARCH }); const isSearching = ( isCommandExecuting(isSearchingCommand) && isSearchingCommand.body.bookIds.indexOf(book.id) > -1 ); - - const isRefreshingCommand = findCommand(commands, { name: commandNames.REFRESH_BOOK }); - const isRefreshing = ( - isCommandExecuting(isRefreshingCommand) && - isRefreshingCommand.body.bookId === book.id + const isRenamingFiles = isCommandExecuting(findCommand(commands, { name: commandNames.RENAME_FILES, authorId: author.id })); + const isRenamingAuthorCommand = findCommand(commands, { name: commandNames.RENAME_AUTHOR }); + const isRenamingAuthor = ( + isCommandExecuting(isRenamingAuthorCommand) && + isRenamingAuthorCommand.body.authorIds.indexOf(author.id) > -1 ); const isFetching = isBookFilesFetching || editions.isFetching; @@ -90,6 +95,8 @@ function createMapStateToProps() { author, isRefreshing, isSearching, + isRenamingFiles, + isRenamingAuthor, isFetching, isPopulated, bookFilesError, @@ -125,9 +132,27 @@ class BookDetailsConnector extends Component { } componentDidUpdate(prevProps) { - if (prevProps.id !== this.props.id || + const { + id, + anyReleaseOk, + isRenamingFiles, + isRenamingAuthor + } = this.props; + + if ( + (prevProps.isRenamingFiles && !isRenamingFiles) || + (prevProps.isRenamingAuthor && !isRenamingAuthor) || !_.isEqual(getMonitoredEditions(prevProps), getMonitoredEditions(this.props)) || - (prevProps.anyReleaseOk === false && this.props.anyReleaseOk === true)) { + (prevProps.anyReleaseOk === false && anyReleaseOk === true) + ) { + this.unpopulate(); + this.populate(); + } + + // If the id has changed we need to clear the book + // files and fetch from the server. + + if (prevProps.id !== id) { this.unpopulate(); this.populate(); } @@ -197,6 +222,8 @@ class BookDetailsConnector extends Component { BookDetailsConnector.propTypes = { id: PropTypes.number, anyReleaseOk: PropTypes.bool, + isRenamingFiles: PropTypes.bool.isRequired, + isRenamingAuthor: PropTypes.bool.isRequired, isBookFetching: PropTypes.bool, isBookPopulated: PropTypes.bool, titleSlug: PropTypes.string.isRequired,