This commit is contained in:
Alexander Skvortsov 2021-11-21 19:30:57 -05:00
parent 3c9c67d726
commit 70bd032cc7
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); return Model.attribute<number | undefined>('commentCount').call(this);
} }
replyCount() { 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() { posts() {
return Model.hasMany<Post>('posts').call(this); return Model.hasMany<Post>('posts').call(this);
@ -112,9 +112,9 @@ export default class Discussion extends Model {
* user. * user.
*/ */
unreadCount(): number { 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)); 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 // 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. // 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 getPlainContent(content);
} }
return content as (null | undefined); return content as null | undefined;
}).call(this); }).call(this);
} }

View File

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

View File

@ -163,7 +163,7 @@ export default class Search<T extends SearchAttrs = SearchAttrs> extends Compone
const maxHeight = const maxHeight =
window.innerHeight - this.element.querySelector('.Search-input>.FormControl')!.getBoundingClientRect().bottom - resultsElementMargin; 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>) { onupdate(vnode: Mithril.VnodeDOM<T, this>) {