Skip to content

Commit

Permalink
chore: continue
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideIadeluca committed Oct 27, 2024
1 parent 4cf7d8a commit fe74ddb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
6 changes: 5 additions & 1 deletion js/src/forum/components/Voters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ export default class Voters extends Component<VotersAttrs> {
}

async load() {
await app.store.find<Post[]>('posts', this.attrs.post.id(), {
const postId = this.attrs.post.id();

if (!postId) return;

await app.store.find<Post>('posts', postId, {
include: 'upvotes',
});

Expand Down
3 changes: 2 additions & 1 deletion js/src/forum/components/VotesUserPage.ts
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -12,7 +13,7 @@ export default class VotesUserPage extends PostsUserPage {
* @protected
*/
loadResults(offset: number) {
return app.store.find('posts', {
return app.store.find<Post[]>('posts', {
filter: {
type: 'comment',
voted: this.user.id(),
Expand Down
25 changes: 15 additions & 10 deletions js/src/forum/useAlternatePostVoteLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mithril.Children>) {
if (this.attrs.post.isHidden()) return;

items.remove('votes');
Expand All @@ -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<Mithril.Children>) {
const post = this.attrs.post;

if (post.isHidden()) return;
Expand All @@ -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(
Expand All @@ -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')}
/>
Expand All @@ -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 && <LoadingIndicator display="inline" size="small" />}
{(this as any).voteLoading && <LoadingIndicator display="inline" size="small" />}
</div>,
10000
);
Expand Down

0 comments on commit fe74ddb

Please sign in to comment.