Skip to content

Commit

Permalink
refactor: merged Subtitle and title component into PollView using Lis…
Browse files Browse the repository at this point in the history
…tItems & the vote button is now showing up and working
  • Loading branch information
novacuum committed Feb 21, 2024
1 parent 8bc4235 commit 7b31b24
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 169 deletions.
151 changes: 47 additions & 104 deletions js/dist/forum.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/dist/forum.js.map

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions js/src/forum/components/Poll/PollSubTitle.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions js/src/forum/components/Poll/PollTitle.tsx

This file was deleted.

80 changes: 49 additions & 31 deletions js/src/forum/components/PollView.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import type Mithril from 'mithril';
import Component, { ComponentAttrs } from 'flarum/common/Component';
import app from 'flarum/forum/app';
import PollTitle from './Poll/PollTitle';
import PollOptions from './Poll/PollOptions';
import PollImage from './Poll/PollImage';
import PollSubTitle from './Poll/PollSubTitle';
import PollModel from '../models/Poll';
import PollState from '../states/PollState';
import Button from 'flarum/common/components/Button';
Expand All @@ -24,7 +22,6 @@ export default class PollView extends Component<PollAttrs, PollState> {

view(): Mithril.Children {
const poll = this.attrs.poll;
const infoItems = this.infoItems(poll.maxVotes());
const state = this.state;
const controls = PollControls.controls(poll, this);

Expand All @@ -42,28 +39,49 @@ export default class PollView extends Component<PollAttrs, PollState> {
<PollImage image={poll.image()} />
</div> */}
<div className="Poll-wrapper">
<PollTitle text={poll.question()} />
<PollSubTitle text={poll.subtitle()} />
<form>
<fieldset>
<legend className="sr-only">Antworten</legend>
<PollOptions options={poll.options()} state={state} />
</fieldset>
<div className="Poll-sticky">
{!infoItems.isEmpty() && <div className="helpText PollInfoText">{infoItems.toArray()}</div>}

{state.showButton() && (
<Button className="Button Button--primary Poll-submit" loading={state.loadingOptions} onclick={state.onsubmit.bind(this)}>
{app.translator.trans('fof-polls.forum.poll.submit_button')}
</Button>
)}
</div>
</form>
{this.createMainView().toArray()}
</div>
</div>
);
}

createMainView(): ItemList<Mithril.Children> {
const items = new ItemList<Mithril.Children>();
const poll = this.attrs.poll;
items.add(
'title',
<h2 className="Poll-title">{poll.question()}</h2>
);
items.add(
'subtitle',
<p className="Poll-subtitle">{poll.subtitle()}</p>
);
items.add(
'form',
this.createFormView()
);
return items;
}

createFormView(): Mithril.Children {
const state = this.state;
const poll = this.attrs.poll;
const infoItems = this.infoItems(poll.maxVotes());

return (<form>
<fieldset>
<legend className="sr-only">Antworten</legend>
<PollOptions options={poll.options()} state={state}/>
</fieldset>
<div className="Poll-sticky">
{!infoItems.isEmpty() && <div className="helpText PollInfoText">{infoItems.toArray()}</div>}
<Button className="Button Button--primary Poll-submit" loading={state.loadingOptions} onclick={state.onsubmit.bind(state)} disabled={!state.hasSelectedOptions()}>
{app.translator.trans('fof-polls.forum.poll.submit_button')}
</Button>
</div>
</form>)
}

deletePoll(): void {
PollControls.deleteAction(this.attrs.poll);
}
Expand All @@ -74,17 +92,17 @@ export default class PollView extends Component<PollAttrs, PollState> {

controlsView(controls: Mithril.ChildArray): Mithril.Children {
return (
!!controls.length && (
<Dropdown
icon="fas fa-ellipsis-v"
className="PollListItem-controls"
menuClassName="Dropdown-menu--right"
buttonClassName="Button Button--icon Button--flat"
accessibleToggleLabel={app.translator.trans('fof-polls.forum.poll_controls.toggle_dropdown_accessible_label')}
>
{controls}
</Dropdown>
)
!!controls.length && (
<Dropdown
icon="fas fa-ellipsis-v"
className="PollListItem-controls"
menuClassName="Dropdown-menu--right"
buttonClassName="Button Button--icon Button--flat"
accessibleToggleLabel={app.translator.trans('fof-polls.forum.poll_controls.toggle_dropdown_accessible_label')}
>
{controls}
</Dropdown>
)
);
}

Expand Down
1 change: 0 additions & 1 deletion js/src/forum/components/PollViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import extractText from "flarum/common/utils/extractText";
import LoadingIndicator from "flarum/common/components/LoadingIndicator";
import PollView from "./PollView";


export default class PollViewPage extends Page {
poll: PollModel | null = null;
loading: boolean = false;
Expand Down
Loading

0 comments on commit 7b31b24

Please sign in to comment.