Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Feb 21, 2024
1 parent 7b31b24 commit cb6d8bc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 76 deletions.
72 changes: 34 additions & 38 deletions js/src/forum/components/PollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,17 @@ export default class PollView extends Component<PollAttrs, PollState> {
{/* <div className="Poll-image">
<PollImage image={poll.image()} />
</div> */}
<div className="Poll-wrapper">
{this.createMainView().toArray()}
</div>
<div className="Poll-wrapper">{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()
);
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;
}

Expand All @@ -68,18 +57,25 @@ export default class PollView extends Component<PollAttrs, PollState> {
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>)
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 {
Expand All @@ -92,17 +88,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
70 changes: 35 additions & 35 deletions js/src/forum/components/PollViewPage.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import type Mithril from "mithril";
import type Mithril from 'mithril';
import app from 'flarum/forum/app';
import Page from "flarum/common/components/Page";
import PollModel from "../models/Poll";
import extractText from "flarum/common/utils/extractText";
import LoadingIndicator from "flarum/common/components/LoadingIndicator";
import PollView from "./PollView";
import Page from 'flarum/common/components/Page';
import PollModel from '../models/Poll';
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;
poll: PollModel | null = null;
loading: boolean = false;

oninit(vnode: Mithril.Vnode) {
super.oninit(vnode);
oninit(vnode: Mithril.Vnode) {
super.oninit(vnode);

const editId = m.route.param('id');
this.poll = app.store.getById('poll', editId) as PollModel;
const editId = m.route.param('id');
this.poll = app.store.getById('poll', editId) as PollModel;

if (!this.poll) {
this.loading = true;
if (!this.poll) {
this.loading = true;

app.store.find<PollModel>('fof/polls', editId).then((item) => {
this.poll = item;
this.loading = false;
app.setTitle(extractText(app.translator.trans('fof-polls.forum.page.poll_detail')));
m.redraw();
});
}
app.store.find<PollModel>('fof/polls', editId).then((item) => {
this.poll = item;
this.loading = false;
app.setTitle(extractText(app.translator.trans('fof-polls.forum.page.poll_detail')));
m.redraw();
});
}
}

view(): Mithril.Children {
if (this.loading) {
return <LoadingIndicator/>;
}
view(): Mithril.Children {
if (this.loading) {
return <LoadingIndicator />;
}

if (this.poll) {
return (
<div className="PollsPage">
<div className="container">
<PollView poll={this.poll}/>
</div>
</div>
);
}
if (this.poll) {
return (
<div className="PollsPage">
<div className="container">
<PollView poll={this.poll} />
</div>
</div>
);
}
}
}
}
2 changes: 1 addition & 1 deletion js/src/forum/extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PollOption from './models/PollOption';
import PollVote from './models/PollVote';
import PollsPage from './components/PollsPage';
import ComposePollPage from './components/ComposePollPage';
import PollViewPage from "./components/PollViewPage";
import PollViewPage from './components/PollViewPage';

export default [
new Extend.Routes() //
Expand Down
4 changes: 2 additions & 2 deletions js/src/forum/states/PollState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ export default class PollState {
m.redraw();
}

hasSelectedOptions():boolean {
hasSelectedOptions(): boolean {
return this.pendingSubmit;
}

onsubmit():Promise<void> {
onsubmit(): Promise<void> {
return this.submit(this.pendingOptions!, () => {
this.pendingOptions = null;
this.pendingSubmit = false;
Expand Down

0 comments on commit cb6d8bc

Please sign in to comment.