Minor typefixes, fomat

This commit is contained in:
Alexander Skvortsov 2021-12-12 15:46:46 -05:00
parent 4759395186
commit f26ad3e32d
No known key found for this signature in database
GPG Key ID: C4E3BBF9C3412B4C
4 changed files with 21 additions and 27 deletions

View File

@ -203,14 +203,12 @@ export default abstract class Model {
}; };
return app return app
.request<ApiPayloadSingle>( .request<ApiPayloadSingle>({
{ method: this.exists ? 'PATCH' : 'POST',
method: this.exists ? 'PATCH' : 'POST', url: app.forum.attribute('apiUrl') + this.apiEndpoint(),
url: app.forum.attribute('apiUrl') + this.apiEndpoint(), body: request,
body: request, ...options,
...options, })
},
)
.then( .then(
// If everything went well, we'll make sure the store knows that this // If everything went well, we'll make sure the store knows that this
// model exists now (if it didn't already), and we'll push the data that // model exists now (if it didn't already), and we'll push the data that
@ -238,14 +236,12 @@ export default abstract class Model {
if (!this.exists) return Promise.resolve(); if (!this.exists) return Promise.resolve();
return app return app
.request( .request({
{ method: 'DELETE',
method: 'DELETE', url: app.forum.attribute('apiUrl') + this.apiEndpoint(),
url: app.forum.attribute('apiUrl') + this.apiEndpoint(), body,
body, ...options,
...options, })
},
)
.then(() => { .then(() => {
this.exists = false; this.exists = false;

View File

@ -174,14 +174,12 @@ export default class Store {
} }
return app return app
.request<M extends Array<infer _T> ? ApiPayloadPlural : ApiPayloadSingle>( .request<M extends Array<infer _T> ? ApiPayloadPlural : ApiPayloadSingle>({
{ method: 'GET',
method: 'GET', url,
url, params,
params, ...options,
...options, })
}
)
.then((payload) => { .then((payload) => {
if (payloadIsPlural(payload)) { if (payloadIsPlural(payload)) {
return this.pushPayload<FlatArray<M, 1>[]>(payload); return this.pushPayload<FlatArray<M, 1>[]>(payload);

View File

@ -61,7 +61,7 @@ export default class Discussion extends Model {
return computed<boolean, this>('unreadCount', (unreadCount) => !!unreadCount).call(this); return computed<boolean, this>('unreadCount', (unreadCount) => !!unreadCount).call(this);
} }
isRead() { isRead() {
return computed<boolean, this>('unreadCount', (unreadCount) => app.session.user && !unreadCount).call(this); return computed<boolean, this>('unreadCount', (unreadCount) => !!(app.session.user && !unreadCount)).call(this);
} }
hiddenAt() { hiddenAt() {
@ -112,7 +112,7 @@ export default class Discussion extends Model {
* user. * user.
*/ */
unreadCount(): number { unreadCount(): number {
const user: User = app.session.user; const user = app.session.user;
if (user && (user.markedAllAsReadAt()?.getTime() ?? 0) < 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));

View File

@ -38,7 +38,7 @@ export default class DiscussionsSearchSource implements SearchSource {
return ( return (
<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()) || 0)}>
<div className="DiscussionSearchResult-title">{highlight(discussion.title(), query)}</div> <div className="DiscussionSearchResult-title">{highlight(discussion.title(), query)}</div>
{mostRelevantPost ? ( {mostRelevantPost ? (
<div className="DiscussionSearchResult-excerpt">{highlight(mostRelevantPost.contentPlain() ?? '', query, 100)}</div> <div className="DiscussionSearchResult-excerpt">{highlight(mostRelevantPost.contentPlain() ?? '', query, 100)}</div>