Fix scolling to first post via m.route.set

The default first post number is '1', so we scroll to that if we're calling `m.route.set` without a `near` parameter, as that means we're scrolling to the top.

This was present in beta 13's implementation, but accidentially omitted in 3f0b3c7.

We also remove unnecessary typecasting for simpler logic and increased consistency with beta 13.
This commit is contained in:
Alexander Skvortsov 2020-10-16 16:30:27 -04:00
parent 5a5982b2aa
commit 3d5f30453b

View File

@ -16,7 +16,7 @@ function getDiscussionIdFromSlug(slug: string | undefined) {
* in the same discussion.
*/
export default class DiscussionPageResolver extends DefaultResolver {
static scrollToPostNumber: string | number | null = null;
static scrollToPostNumber: string | null = null;
makeKey() {
const params = { ...m.route.param() };
@ -29,7 +29,8 @@ export default class DiscussionPageResolver extends DefaultResolver {
onmatch(args, requestedPath, route) {
if (app.current.matches(DiscussionPage) && getDiscussionIdFromSlug(args.id) === getDiscussionIdFromSlug(m.route.param('id'))) {
DiscussionPageResolver.scrollToPostNumber = args.near === 'reply' ? 'reply' : parseInt(args.near);
// By default, the first post number of any discussion is 1
DiscussionPageResolver.scrollToPostNumber = args.near || '1';
}
return super.onmatch(args, requestedPath, route);