notifyPost,
setIsoData,
wsSubscribe,
- isBrowser,
communityRSSUrl,
wsUserOp,
wsClient,
authField,
setOptionalAuth,
+ saveScrollPosition,
+ restoreScrollPosition,
} from '../utils';
import { i18n } from '../i18next';
}
componentWillUnmount() {
- if (isBrowser()) {
- this.subscription.unsubscribe();
- window.isoData.path = undefined;
- }
+ saveScrollPosition(this.context);
+ this.subscription.unsubscribe();
+ window.isoData.path = undefined;
}
static getDerivedStateFromProps(props: any): CommunityProps {
this.state.posts = data.posts;
this.state.postsLoading = false;
this.setState(this.state);
+ restoreScrollPosition(this.context);
setupTippy();
} else if (
op == UserOperation.EditPost ||
notifyPost,
setIsoData,
wsSubscribe,
- isBrowser,
wsUserOp,
setOptionalAuth,
wsClient,
authField,
+ saveScrollPosition,
+ restoreScrollPosition,
} from '../utils';
import { i18n } from '../i18next';
import { T } from 'inferno-i18next';
}
componentWillUnmount() {
- if (isBrowser()) {
- this.subscription.unsubscribe();
- window.isoData.path = undefined;
- }
+ saveScrollPosition(this.context);
+ this.subscription.unsubscribe();
+ window.isoData.path = undefined;
}
static getDerivedStateFromProps(props: any): MainProps {
this.state.posts = data.posts;
this.state.loading = false;
this.setState(this.state);
+ restoreScrollPosition(this.context);
setupTippy();
} else if (op == UserOperation.CreatePost) {
let data = wsJsonToRes<PostResponse>(msg).data;
wsClient,
authField,
setOptionalAuth,
+ saveScrollPosition,
+ restoreScrollPosition,
} from '../utils';
import { PostListing } from './post-listing';
import { Sidebar } from './sidebar';
componentWillUnmount() {
this.subscription.unsubscribe();
window.isoData.path = undefined;
+ saveScrollPosition(this.context);
}
componentDidMount() {
this.fetchCrossPosts();
this.setState(this.state);
setupTippy();
+ restoreScrollPosition(this.context);
} else if (op == UserOperation.CreateComment) {
let data = wsJsonToRes<CommentResponse>(msg).data;
wsClient,
authField,
setOptionalAuth,
+ saveScrollPosition,
+ restoreScrollPosition,
} from '../utils';
import { PostListing } from './post-listing';
import { HtmlTags } from './html-tags';
componentWillUnmount() {
this.subscription.unsubscribe();
+ saveScrollPosition(this.context);
}
static getDerivedStateFromProps(props: any): SearchProps {
this.state.loading = false;
window.scrollTo(0, 0);
this.setState(this.state);
+ restoreScrollPosition(this.context);
} else if (op == UserOperation.CreateCommentLike) {
let data = wsJsonToRes<CommentResponse>(msg).data;
createCommentLikeRes(
wsClient,
authField,
setOptionalAuth,
+ saveScrollPosition,
+ restoreScrollPosition,
} from '../utils';
import { UserListing } from './user-listing';
import { HtmlTags } from './html-tags';
componentWillUnmount() {
this.subscription.unsubscribe();
+ saveScrollPosition(this.context);
}
static getDerivedStateFromProps(props: any): UserProps {
this.setUserInfo();
this.state.loading = false;
this.setState(this.state);
+ restoreScrollPosition(this.context);
} else if (op == UserOperation.SaveUserSettings) {
let data = wsJsonToRes<LoginResponse>(msg).data;
UserService.Instance.login(data);
yy: '%dY',
},
});
+
+export function saveScrollPosition(context: any) {
+ let path: string = context.router.route.location.pathname;
+ let y = window.scrollY;
+ sessionStorage.setItem(`scrollPosition_${path}`, y.toString());
+}
+
+export function restoreScrollPosition(context: any) {
+ let path: string = context.router.route.location.pathname;
+ let y = Number(sessionStorage.getItem(`scrollPosition_${path}`));
+ window.scrollTo(0, y);
+}