Fixed a problem updating the UI after deleting something.

master
Pacman Ghost 2 years ago
parent 197a665b10
commit 81445487f5
  1. 2
      web/src/PublicationSearchResult.js
  2. 4
      web/src/PublisherSearchResult.js
  3. 20
      web/src/SearchResults.js

@ -223,7 +223,7 @@ export class PublicationSearchResult extends React.Component
// update the UI
this.props.onDelete( "pub_id", this.props.data.pub_id ) ;
resp.data.deletedArticles.forEach( article_id => {
this.props.onDelete( "article_id", article_id ) ;
this.props.onDelete( "article_id", article_id, true ) ;
} ) ;
if ( this.props.data._parent_publ )
gAppRef.updatePublisher( this.props.data._parent_publ.publ_id ) ;

@ -191,10 +191,10 @@ export class PublisherSearchResult extends React.Component
// update the UI
this.props.onDelete( "publ_id", this.props.data.publ_id ) ;
resp.data.deletedPublications.forEach( pub_id => {
this.props.onDelete( "pub_id", pub_id ) ;
this.props.onDelete( "pub_id", pub_id, true ) ;
} ) ;
resp.data.deletedArticles.forEach( article_id => {
this.props.onDelete( "article_id", article_id ) ;
this.props.onDelete( "article_id", article_id, true ) ;
} ) ;
// update the UI
if ( resp.data.warnings )

@ -45,16 +45,16 @@ export class SearchResults extends React.Component
this.props.searchResults.forEach( sr => {
if ( sr._type === "publisher" ) {
results.push( <PublisherSearchResult key={"publisher:"+sr.publ_id} data={sr}
onDelete = { (n,v) => this.onDeleteSearchResult( n, v ) }
onDelete = { (n,v,i) => this.onDeleteSearchResult( n, v, i ) }
/> ) ;
} else if ( sr._type === "publication" ) {
results.push( <PublicationSearchResult key={"publication:"+sr.pub_id} data={sr}
onDelete = { (n,v) => this.onDeleteSearchResult( n, v ) }
onDelete = { (n,v,i) => this.onDeleteSearchResult( n, v, i ) }
onArticleClick = { (a) => scrollToArticle(a) }
/> ) ;
} else if ( sr._type === "article" ) {
results.push( <ArticleSearchResult key={"article:"+sr.article_id} data={sr}
onDelete = { (n,v) => this.onDeleteSearchResult( n, v ) }
onDelete = { (n,v,i) => this.onDeleteSearchResult( n, v, i ) }
ref = { r => articleRefs[sr.article_id] = r }
/> ) ;
} else {
@ -65,16 +65,26 @@ export class SearchResults extends React.Component
return <div id="search-results" seqno={this.props.seqNo}> {results} </div> ;
}
onDeleteSearchResult( idName, idVal ) {
onDeleteSearchResult( idName, idVal, ignoreNotFound ) {
// look for the specified search result
for ( let i=0 ; i < this.props.searchResults.length ; ++i ) {
const sr = this.props.searchResults[ i ] ;
if ( sr[idName] === idVal ) {
// found it - remove it the UI
this.props.searchResults.splice( i, 1 ) ;
this.forceUpdate() ;
return ;
}
}
gAppRef.logInternalError( "Tried to delete an unknown search result.", idName+" = "+idVal ) ;
// the search result wasn't found
// NOTE: This would normally indicate an internal coding error, but there is one case where
// it can happen: when a publisher or publication is deleted, we want to also delete all
// their child objects, but they may not necessarily be on-screen.
if ( ! ignoreNotFound ) {
gAppRef.logInternalError(
"Tried to delete an unknown search result.", idName+" = "+idVal
) ;
}
}
}

Loading…
Cancel
Save