Skip to content

Commit

Permalink
chor: revert customization changes back to original functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
novacuum committed Mar 6, 2024
1 parent aed0f1a commit 68a4645
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion js/src/forum/components/PollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class PollView extends Component<PollAttrs, PollState> {
'sticky',
<div className="Poll-sticky">
{!infoItems.isEmpty() && <div className="helpText PollInfoText">{infoItems.toArray()}</div>}
<PollSubmitButton state={state} />
{state.showButton() && (<PollSubmitButton state={state} />)}
</div>
);
return items;
Expand Down
28 changes: 21 additions & 7 deletions js/src/forum/states/PollState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ import { ApiPayloadSingle } from 'flarum/common/Store';

export default class PollState {
protected poll: Poll;
protected pendingSubmit: boolean;
protected pendingOptions: Set<string> | null;
public loadingOptions: boolean;
protected pendingSubmit: boolean = false;
protected pendingOptions: Set<string> | null = null;
public loadingOptions: boolean = false;
public useSubmitUI: boolean;
public showCheckMarks: boolean;
public canSeeVoteCount: boolean;

constructor(poll: Poll) {
this.poll = poll;
this.pendingSubmit = false;
this.pendingOptions = null;
this.loadingOptions = false;
this.useSubmitUI = !poll?.canChangeVote() && poll?.allowMultipleVotes();
this.showCheckMarks = !app.session.user || (!poll.hasEnded() && poll.canVote() && (!this.hasVoted() || poll.canChangeVote()));
this.canSeeVoteCount = typeof poll.voteCount() === 'number';
this.init();
}

/**
* used as en extendable entry point for init customizations
*/
init():void {

}

isShowResult(): boolean {
Expand Down Expand Up @@ -75,7 +80,16 @@ export default class PollState {

this.pendingOptions = optionIds.size ? optionIds : null;
this.pendingSubmit = !!this.pendingOptions;
m.redraw();


if (this.useSubmitUI) {
this.pendingOptions = optionIds.size ? optionIds : null;
this.pendingSubmit = !!this.pendingOptions;
m.redraw();
return;
}

this.submit(optionIds, null, () => (target.checked = isUnvoting));
}

hasSelectedOptions(): boolean {
Expand Down

0 comments on commit 68a4645

Please sign in to comment.