This commit is contained in:
Alexander Skvortsov 2021-11-21 19:30:57 -05:00
parent 3a8d640dab
commit 09a55258a0
No known key found for this signature in database
GPG Key ID: C4E3BBF9C3412B4C
4 changed files with 10 additions and 6 deletions

View File

@ -42,7 +42,7 @@ export default class Discussion extends Model {
return Model.attribute<number | undefined>('commentCount').call(this);
}
replyCount() {
return computed<Number, this>('commentCount', (commentCount) => Math.max(0, (commentCount as number ?? 0) - 1)).call(this);
return computed<Number, this>('commentCount', (commentCount) => Math.max(0, ((commentCount as number) ?? 0) - 1)).call(this);
}
posts() {
return Model.hasMany<Post>('posts').call(this);
@ -112,9 +112,9 @@ export default class Discussion extends Model {
* user.
*/
unreadCount(): number {
const user = app.session.user;
const user: User = app.session.user;
if (user && user.markedAllAsReadAt().getTime() < this.lastPostedAt()?.getTime()!) {
if (user && (user.markedAllAsReadAt()?.getTime() ?? 0) < this.lastPostedAt()?.getTime()!) {
const unreadCount = Math.max(0, (this.lastPostNumber() ?? 0) - (this.lastReadPostNumber() || 0));
// If posts have been deleted, it's possible that the unread count could exceed the
// actual post count. As such, we take the min of the two to ensure this isn't an issue.

View File

@ -37,7 +37,7 @@ export default class Post extends Model {
return getPlainContent(content);
}
return content as (null | undefined);
return content as null | undefined;
}).call(this);
}

View File

@ -40,7 +40,11 @@ export default class DiscussionsSearchSource implements SearchSource {
<li className="DiscussionSearchResult" data-index={'discussions' + discussion.id()}>
<Link href={app.route.discussion(discussion, mostRelevantPost && mostRelevantPost.number())}>
<div className="DiscussionSearchResult-title">{highlight(discussion.title(), query)}</div>
{mostRelevantPost ? <div className="DiscussionSearchResult-excerpt">{highlight(mostRelevantPost.contentPlain() ?? '', query, 100)}</div> : ''}
{mostRelevantPost ? (
<div className="DiscussionSearchResult-excerpt">{highlight(mostRelevantPost.contentPlain() ?? '', query, 100)}</div>
) : (
''
)}
</Link>
</li>
);

View File

@ -163,7 +163,7 @@ export default class Search<T extends SearchAttrs = SearchAttrs> extends Compone
const maxHeight =
window.innerHeight - this.element.querySelector('.Search-input>.FormControl')!.getBoundingClientRect().bottom - resultsElementMargin;
(this.element.querySelector('.Search-results') as HTMLElement).style?.setProperty('max-height', `${maxHeight}px`);
this.element.querySelector<HTMLElement>('.Search-results')?.style?.setProperty('max-height', `${maxHeight}px`);
}
onupdate(vnode: Mithril.VnodeDOM<T, this>) {