Fix post edit form closed on nav cancel

This commit is contained in:
Bastian Rihm 2023-07-01 20:28:12 +02:00
parent 61255bf01a
commit 66090326a2
No known key found for this signature in database
GPG key ID: 3C66E93B0CA3991C

View file

@ -219,6 +219,7 @@ const LinkButton = ({
export class Home extends Component<any, HomeState> { export class Home extends Component<any, HomeState> {
private isoData = setIsoData<HomeData>(this.context); private isoData = setIsoData<HomeData>(this.context);
private unregisterHistoryListener: () => void;
state: HomeState = { state: HomeState = {
postsRes: { state: "empty" }, postsRes: { state: "empty" },
commentsRes: { state: "empty" }, commentsRes: { state: "empty" },
@ -291,6 +292,7 @@ export class Home extends Component<any, HomeState> {
} }
componentWillUnmount() { componentWillUnmount() {
this.unregisterHistoryListener();
HomeCacheService.activate(); HomeCacheService.activate();
} }
@ -304,6 +306,15 @@ export class Home extends Component<any, HomeState> {
await Promise.all([this.fetchTrendingCommunities(), this.fetchData()]); await Promise.all([this.fetchTrendingCommunities(), this.fetchData()]);
} }
this.unregisterHistoryListener = this.props.history.listen(() => {
if (!this.state.scrolled) {
this.setState({ scrolled: true });
setTimeout(() => window.scrollTo(0, 0), 0);
}
this.fetchData();
});
setupTippy(); setupTippy();
} }
@ -634,13 +645,6 @@ export class Home extends Component<any, HomeState> {
pathname: "/", pathname: "/",
search: getQueryString(queryParams), search: getQueryString(queryParams),
}); });
if (!this.state.scrolled) {
this.setState({ scrolled: true });
setTimeout(() => window.scrollTo(0, 0), 0);
}
await this.fetchData();
} }
get posts() { get posts() {