mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-08-04 18:11:49 +00:00
Fixed reuploading the same file
This commit is contained in:
@@ -45,9 +45,12 @@ export class App extends React.Component<RouteComponentProps, {}> {
|
|||||||
private isNewData(
|
private isNewData(
|
||||||
hash: string | undefined,
|
hash: string | undefined,
|
||||||
url: string | undefined,
|
url: string | undefined,
|
||||||
|
gedcom: string | undefined,
|
||||||
): boolean {
|
): boolean {
|
||||||
return (
|
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<RouteComponentProps, {}> {
|
|||||||
|
|
||||||
if (!url && !hash) {
|
if (!url && !hash) {
|
||||||
this.props.history.replace({pathname: '/'});
|
this.props.history.replace({pathname: '/'});
|
||||||
} else if (this.isNewData(hash, url)) {
|
} else if (this.isNewData(hash, url, gedcom)) {
|
||||||
try {
|
try {
|
||||||
// Set loading state.
|
// Set loading state.
|
||||||
this.setState(
|
this.setState(
|
||||||
|
|||||||
@@ -105,7 +105,16 @@ export class TopBar extends React.Component<
|
|||||||
.join('|');
|
.join('|');
|
||||||
// Hash GEDCOM contents with uploaded image file names.
|
// Hash GEDCOM contents with uploaded image file names.
|
||||||
const hash = md5(md5(data) + imageFileNames);
|
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',
|
pathname: '/view',
|
||||||
search: queryString.stringify({file: hash}),
|
search: queryString.stringify({file: hash}),
|
||||||
state: {data, images: imageMap},
|
state: {data, images: imageMap},
|
||||||
|
|||||||
Reference in New Issue
Block a user