From 177c721c2fe3b75fbbce18ecbeb12a68542d6850 Mon Sep 17 00:00:00 2001 From: Przemek Wiech Date: Tue, 9 Apr 2019 00:12:21 +0200 Subject: [PATCH] Fixed reuploading the same file --- src/app.tsx | 7 +++++-- src/top_bar.tsx | 11 ++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/app.tsx b/src/app.tsx index 1e8ff43..a2bf164 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -45,9 +45,12 @@ export class App extends React.Component { private isNewData( hash: string | undefined, url: string | undefined, + gedcom: string | undefined, ): boolean { return ( - !!(hash && hash !== this.state.hash) || !!(url && this.state.url !== url) + !!(hash && hash !== this.state.hash) || + !!(url && this.state.url !== url) || + (!!gedcom && !this.state.loading && !this.state.data) ); } @@ -77,7 +80,7 @@ export class App extends React.Component { if (!url && !hash) { this.props.history.replace({pathname: '/'}); - } else if (this.isNewData(hash, url)) { + } else if (this.isNewData(hash, url, gedcom)) { try { // Set loading state. this.setState( diff --git a/src/top_bar.tsx b/src/top_bar.tsx index 63a558d..b845834 100644 --- a/src/top_bar.tsx +++ b/src/top_bar.tsx @@ -105,7 +105,16 @@ export class TopBar extends React.Component< .join('|'); // Hash GEDCOM contents with uploaded image file names. const hash = md5(md5(data) + imageFileNames); - this.props.history.push({ + + // Use history.replace() when reuploading the same file and history.push() when loading + // a new file. + const search = queryString.parse(this.props.location.search); + const historyPush = + search.file === hash + ? this.props.history.replace + : this.props.history.push; + + historyPush({ pathname: '/view', search: queryString.stringify({file: hash}), state: {data, images: imageMap},