Skip to content

Commit

Permalink
Minor typefixes, fomat
Browse files Browse the repository at this point in the history
  • Loading branch information
askvortsov1 committed Dec 12, 2021
1 parent 4759395 commit f26ad3e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
28 changes: 12 additions & 16 deletions js/src/common/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,12 @@ export default abstract class Model {
};

return app
.request<ApiPayloadSingle>(
{
method: this.exists ? 'PATCH' : 'POST',
url: app.forum.attribute('apiUrl') + this.apiEndpoint(),
body: request,
...options,
},
)
.request<ApiPayloadSingle>({
method: this.exists ? 'PATCH' : 'POST',
url: app.forum.attribute('apiUrl') + this.apiEndpoint(),
body: request,
...options,
})
.then(
// 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
Expand Down Expand Up @@ -238,14 +236,12 @@ export default abstract class Model {
if (!this.exists) return Promise.resolve();

return app
.request(
{
method: 'DELETE',
url: app.forum.attribute('apiUrl') + this.apiEndpoint(),
body,
...options,
},
)
.request({
method: 'DELETE',
url: app.forum.attribute('apiUrl') + this.apiEndpoint(),
body,
...options,
})
.then(() => {
this.exists = false;

Expand Down
14 changes: 6 additions & 8 deletions js/src/common/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,12 @@ export default class Store {
}

return app
.request<M extends Array<infer _T> ? ApiPayloadPlural : ApiPayloadSingle>(
{
method: 'GET',
url,
params,
...options,
}
)
.request<M extends Array<infer _T> ? ApiPayloadPlural : ApiPayloadSingle>({
method: 'GET',
url,
params,
...options,
})
.then((payload) => {
if (payloadIsPlural(payload)) {
return this.pushPayload<FlatArray<M, 1>[]>(payload);
Expand Down
4 changes: 2 additions & 2 deletions js/src/common/models/Discussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class Discussion extends Model {
return computed<boolean, this>('unreadCount', (unreadCount) => !!unreadCount).call(this);
}
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() {
Expand Down Expand Up @@ -112,7 +112,7 @@ export default class Discussion extends Model {
* user.
*/
unreadCount(): number {
const user: User = app.session.user;
const user = app.session.user;

if (user && (user.markedAllAsReadAt()?.getTime() ?? 0) < this.lastPostedAt()?.getTime()!) {
const unreadCount = Math.max(0, (this.lastPostNumber() ?? 0) - (this.lastReadPostNumber() || 0));
Expand Down
2 changes: 1 addition & 1 deletion js/src/forum/components/DiscussionsSearchSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class DiscussionsSearchSource implements SearchSource {

return (
<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>
{mostRelevantPost ? (
<div className="DiscussionSearchResult-excerpt">{highlight(mostRelevantPost.contentPlain() ?? '', query, 100)}</div>
Expand Down

0 comments on commit f26ad3e

Please sign in to comment.