Better history state management

Pop the history when closing the image viewer instead of building up a
long list of images. This makes it easier to navigate back to the home
page with the browser back button
This commit is contained in:
2024-01-11 10:36:10 -08:00
parent b6d6cab976
commit c6c651f0b4

View File

@@ -161,8 +161,12 @@ export class Root extends React.PureComponent<Props, State> {
};
private _onImageSelected = (img: Model.Image) => {
if (this.state.selectedImage) {
window.history.replaceState(null, "", `#${img.src}`);
} else {
window.history.pushState(null, "", `#${img.src}`);
}
this.setState({ selectedImage: img });
window.history.pushState(null, "", `#${img.src}`);
};
private _onSetSelected = (set: Model.ImageSet) => {
@@ -188,6 +192,7 @@ export class Root extends React.PureComponent<Props, State> {
private _showGrid = () => {
this.setState({ selectedImage: null });
window.history.go(-1);
this._onSetSelected(this.state.selectedSet as Model.ImageSet);
};