Skip to content

Commit

Permalink
- format code
Browse files Browse the repository at this point in the history
  • Loading branch information
novacuum committed Feb 6, 2024
1 parent 57afdcf commit e02459c
Show file tree
Hide file tree
Showing 16 changed files with 517 additions and 532 deletions.
2 changes: 1 addition & 1 deletion js/dist/forum.js.map

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions js/src/common/Acl.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default class Acl {
static canManagePools():boolean {
return true;
}
static canManagePools(): boolean {
return true;
}

static canStartPoll():boolean {
return true;
//app.forum.attribute('canStartPoll') || !app.session.user;
}
}
static canStartPoll(): boolean {
return true;
//app.forum.attribute('canStartPoll') || !app.session.user;
}
}
2 changes: 1 addition & 1 deletion js/src/common/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const slug = 'fof-polls';
export const slug = 'fof-polls';
78 changes: 39 additions & 39 deletions js/src/forum/components/ComposePollHero.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import Mithril from "mithril";
import app from "flarum/forum/app";
import Component from "flarum/common/Component";
import {slug} from "../../common";
import LinkButton from "flarum/common/components/LinkButton";
import Mithril from 'mithril';
import app from 'flarum/forum/app';
import Component from 'flarum/common/Component';
import { slug } from '../../common';
import LinkButton from 'flarum/common/components/LinkButton';

const t = app.translator.trans.bind(app.translator);
const prfx = `${slug}.forum.compose`;

export default class ComposePollHero extends Component {
view(): Mithril.Children {
const { poll } = this.attrs;
view(): Mithril.Children {
const { poll } = this.attrs;

return (
<div className='ComposeGoodieCollectionHero Hero IndexPageHero'>
<div className='container'>
<div className='containerNarrow'>
<h2 className='Hero-title'>
{t(`${prfx}.${!!poll.id() ? 'edit' : 'add'}_title`)}
</h2>
<div className='IndexPageHero-controls'>
<LinkButton
icon='far fa-edit'
className='Button Button--primary IndexPage-newDiscussion GoodiesManagerLink'
itemClassName='App-primaryControl'
href={app.route('fof_polls_directory')}>
{t(`${prfx}.polls_manager`)}
</LinkButton>
{poll.exists && (
<LinkButton
icon='far fa-arrow-up-right-from-square'
className='Button Button--primary IndexPage-newDiscussion GoodiePreviewLink'
itemClassName='App-primaryControl'
href={app.route('fof_polls_directory', { id: poll.id() })}
external={true}
target='_blank'>
{t(`${prfx}.polls_preview`)}
</LinkButton>
)}
</div>
</div>
</div>
return (
<div className="ComposeGoodieCollectionHero Hero IndexPageHero">
<div className="container">
<div className="containerNarrow">
<h2 className="Hero-title">{t(`${prfx}.${!!poll.id() ? 'edit' : 'add'}_title`)}</h2>
<div className="IndexPageHero-controls">
<LinkButton
icon="far fa-edit"
className="Button Button--primary IndexPage-newDiscussion GoodiesManagerLink"
itemClassName="App-primaryControl"
href={app.route('fof_polls_directory')}
>
{t(`${prfx}.polls_manager`)}
</LinkButton>
{poll.exists && (
<LinkButton
icon="far fa-arrow-up-right-from-square"
className="Button Button--primary IndexPage-newDiscussion GoodiePreviewLink"
itemClassName="App-primaryControl"
href={app.route('fof_polls_directory', { id: poll.id() })}
external={true}
target="_blank"
>
{t(`${prfx}.polls_preview`)}
</LinkButton>
)}
</div>
);
}
}
</div>
</div>
</div>
);
}
}
93 changes: 46 additions & 47 deletions js/src/forum/components/ComposePollPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,64 @@ import app from 'flarum/forum/app';
import Page from 'flarum/common/components/Page';
import Poll from './Poll';
import LoadingIndicator from 'flarum/common/components/LoadingIndicator';
import PollForm from "./PollForm";
import Acl from "../../common/Acl";
import PollFormState from "../states/PollFormState";
import {slug} from "../../common";
import ComposePollHero from "./ComposePollHero";
import PollForm from './PollForm';
import Acl from '../../common/Acl';
import PollFormState from '../states/PollFormState';
import { slug } from '../../common';
import ComposePollHero from './ComposePollHero';

const t = app.translator.trans.bind(app.translator);
const prfx = `${slug}.forum.compose`;

export default class ComposePollPage extends Page {
poll: Poll | null = null;

poll: Poll | null = null;
loading: boolean = false;

loading: boolean = false;
oninit(vnode) {
super.oninit(vnode);

oninit(vnode) {
super.oninit(vnode);

// If user not allowed to manage goodie collections, redirect to home
if (!Acl.canManagePools()) {
m.route.set(app.route('home'));
}

// Get the `edit` parameter from the URL
const editId = m.route.param('id');
if (editId) {
this.poll = app.store.getById('poll', editId);
// If user not allowed to manage goodie collections, redirect to home
if (!Acl.canManagePools()) {
m.route.set(app.route('home'));
}

if (!this.poll) {
this.loading = true;
// Get the `edit` parameter from the URL
const editId = m.route.param('id');
if (editId) {
this.poll = app.store.getById('poll', editId);

app.store.find('fof/polls', editId).then((item) => {
this.poll = item;
this.loading = false;
app.setTitle(t(`${prfx}.${!!this.poll?.id() ? 'edit' : 'add'}_title`));
m.redraw();
});
}
} else {
this.poll = PollFormState.createNewPoll();
}
if (!this.poll) {
this.loading = true;

app.history.push('compose-goodie-collection');
this.bodyClass = 'App--compose-goodie-collection';
app.setTitle(t(`${prfx}.${!!this.poll?.id() ? 'edit' : 'add'}_title`));
app.store.find('fof/polls', editId).then((item) => {
this.poll = item;
this.loading = false;
app.setTitle(t(`${prfx}.${!!this.poll?.id() ? 'edit' : 'add'}_title`));
m.redraw();
});
}
} else {
this.poll = PollFormState.createNewPoll();
}

view(): Mithril.Children {
if (this.loading) {
return <LoadingIndicator />;
}
app.history.push('compose-goodie-collection');
this.bodyClass = 'App--compose-goodie-collection';
app.setTitle(t(`${prfx}.${!!this.poll?.id() ? 'edit' : 'add'}_title`));
}

return (
<div className='ComposeGoodieCollectionPage'>
<ComposePollHero poll={this.poll} />
<div className='container'>
<PollForm poll={this.poll} />
</div>
</div>
);
view(): Mithril.Children {
if (this.loading) {
return <LoadingIndicator />;
}
}

return (
<div className="ComposeGoodieCollectionPage">
<ComposePollHero poll={this.poll} />
<div className="container">
<PollForm poll={this.poll} />
</div>
</div>
);
}
}
1 change: 0 additions & 1 deletion js/src/forum/components/CreatePollModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Modal from 'flarum/common/components/Modal';
import PollForm from './PollForm';

export default class CreatePollModal extends Modal {

title() {
return app.translator.trans('fof-polls.forum.modal.add_title');
}
Expand Down
4 changes: 2 additions & 2 deletions js/src/forum/components/Poll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import PollImage from './Poll/PollImage';

export default class IndexPolls extends Component {
view(): Mithril.Children {
/* @type Poll */
const poll = this.attrs.poll;
/* @type Poll */
const poll = this.attrs.poll;

return (
<div className="Poll">
Expand Down
22 changes: 11 additions & 11 deletions js/src/forum/components/Poll/PollOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import PollOptionLabel from './PollOptionLabel';
import PollOptionInput from './PollOptionInput';

export default class PollOption extends Component {
view(): Mithril.Children {
const option = this.attrs.option;
return (
<label className="PollOption-tmp">
<PollOptionInput id={option.id()} isResult={false} name="vote" value="Vote for this option"/>
<span className="PollOption-information">
<PollOptionLabel id={option.id()} text={option.answer()}/>
</span>
</label>
);
}
view(): Mithril.Children {
const option = this.attrs.option;
return (
<label className="PollOption-tmp">
<PollOptionInput id={option.id()} isResult={false} name="vote" value="Vote for this option" />
<span className="PollOption-information">
<PollOptionLabel id={option.id()} text={option.answer()} />
</span>
</label>
);
}
}
3 changes: 1 addition & 2 deletions js/src/forum/components/Poll/PollOptionLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import Component, { ComponentAttrs } from 'flarum/common/Component';

interface PollOptionLabelAttrs extends ComponentAttrs {
text: String;
id: Number;
id: Number;
}

export default class PollOptionLabel extends Component<PollOptionLabelAttrs> {
view(): Mithril.Children {

return (
<span id={`vote_${this.attrs.id}_label`} className="PollOption-label">
{this.attrs.text}
Expand Down
4 changes: 2 additions & 2 deletions js/src/forum/components/Poll/PollOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export default class PollOptions extends Component {

pollOptions(): ItemList<Mithril.Children> {
const items = new ItemList<Mithril.Children>();
this.attrs.options.forEach((option:PollOptionModel):void => {
items.add('option' + option.id(), <PollOption option={option} />);
this.attrs.options.forEach((option: PollOptionModel): void => {
items.add('option' + option.id(), <PollOption option={option} />);
});

items.add('test5', <PollResult />);
Expand Down
Loading

0 comments on commit e02459c

Please sign in to comment.