From fe74ddbe489658efa8ec5225dd1eefb9452ff6ae Mon Sep 17 00:00:00 2001 From: Davide Iadeluca Date: Sun, 27 Oct 2024 11:13:13 +0100 Subject: [PATCH] chore: continue --- js/src/forum/components/Voters.tsx | 6 ++++- js/src/forum/components/VotesUserPage.ts | 3 ++- js/src/forum/useAlternatePostVoteLayout.tsx | 25 ++++++++++++--------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/js/src/forum/components/Voters.tsx b/js/src/forum/components/Voters.tsx index a4a2030..dad1976 100644 --- a/js/src/forum/components/Voters.tsx +++ b/js/src/forum/components/Voters.tsx @@ -109,7 +109,11 @@ export default class Voters extends Component { } async load() { - await app.store.find('posts', this.attrs.post.id(), { + const postId = this.attrs.post.id(); + + if (!postId) return; + + await app.store.find('posts', postId, { include: 'upvotes', }); diff --git a/js/src/forum/components/VotesUserPage.ts b/js/src/forum/components/VotesUserPage.ts index a811a0e..e731c74 100644 --- a/js/src/forum/components/VotesUserPage.ts +++ b/js/src/forum/components/VotesUserPage.ts @@ -1,6 +1,7 @@ import app from 'flarum/forum/app'; import PostsUserPage from 'flarum/forum/components/PostsUserPage'; +import type Post from 'flarum/common/models/Post'; /** * The `VotesUserPage` component shows posts which user voted on. */ @@ -12,7 +13,7 @@ export default class VotesUserPage extends PostsUserPage { * @protected */ loadResults(offset: number) { - return app.store.find('posts', { + return app.store.find('posts', { filter: { type: 'comment', voted: this.user.id(), diff --git a/js/src/forum/useAlternatePostVoteLayout.tsx b/js/src/forum/useAlternatePostVoteLayout.tsx index c9dd6c0..183d20b 100644 --- a/js/src/forum/useAlternatePostVoteLayout.tsx +++ b/js/src/forum/useAlternatePostVoteLayout.tsx @@ -6,13 +6,14 @@ import CommentPost from 'flarum/forum/components/CommentPost'; import Button from 'flarum/common/components/Button'; import abbreviateNumber from 'flarum/common/utils/abbreviateNumber'; import LoadingIndicator from 'flarum/common/components/LoadingIndicator'; -import type ItemList from 'flarum/common/utils/ItemList'; - import setting from './helpers/setting'; import saveVote from './helpers/saveVote'; +import type ItemList from 'flarum/common/utils/ItemList'; +import type Mithril from 'mithril'; + export default function useAlternatePostVoteLayout() { - extend(CommentPost.prototype, 'actionItems', function (this: CommentPost, items: ItemList) { + extend(CommentPost.prototype, 'actionItems', function (this: CommentPost, items: ItemList) { if (this.attrs.post.isHidden()) return; items.remove('votes'); @@ -30,7 +31,11 @@ export default function useAlternatePostVoteLayout() { } }); - extend(CommentPost.prototype, 'headerItems', function (this: CommentPost, items: ItemList) { + extend(CommentPost.prototype, 'oninit', function () { + (this as any).voteLoading = false; + }); + + extend(CommentPost.prototype, 'headerItems', function (this: CommentPost, items: ItemList) { const post = this.attrs.post; if (post.isHidden()) return; @@ -47,9 +52,9 @@ export default function useAlternatePostVoteLayout() { // We set canVote to true for guest users so that they can access the login by clicking the button const canVote = !app.session.user || post.canVote(); - const onclick = (upvoted, downvoted) => - saveVote(post, upvoted, downvoted, (val) => { - this.voteLoading = val; + const onclick = (upvoted: boolean, downvoted: boolean) => + saveVote(post, upvoted, downvoted, (val: boolean) => { + (this as any).voteLoading = val; }); items.add( @@ -59,7 +64,7 @@ export default function useAlternatePostVoteLayout() { className="Post-voteButton Post-voteButton--up Button Button--icon Button--text" icon={`fas fa-fw fa-${icon}-up`} data-active={hasUpvoted} - disabled={!canVote || this.voteLoading || !canSeeVotes} + disabled={!canVote || (this as any).voteLoading || !canSeeVotes} onclick={() => onclick(!hasUpvoted, false)} aria-label={app.translator.trans('fof-gamification.forum.post.upvote_button')} /> @@ -71,13 +76,13 @@ export default function useAlternatePostVoteLayout() { className="Post-voteButton Post-voteButton--down Button Button--icon Button--text" icon={`fas fa-fw fa-${icon}-down`} data-active={hasDownvoted} - disabled={!canVote || this.voteLoading} + disabled={!canVote || (this as any).voteLoading} onclick={() => onclick(false, !hasDownvoted)} aria-label={app.translator.trans('fof-gamification.forum.post.downvote_button')} /> )} - {this.voteLoading && } + {(this as any).voteLoading && } , 10000 );