Skip to content

Commit

Permalink
export components
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Feb 21, 2024
1 parent 9b3197b commit 87e4d48
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 23 deletions.
66 changes: 43 additions & 23 deletions js/src/forum/components/ComposePollHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,63 @@ import app from 'flarum/forum/app';
import Component, { ComponentAttrs } from 'flarum/common/Component';
import LinkButton from 'flarum/common/components/LinkButton';
import Poll from '../models/Poll';
import ItemList from 'flarum/common/utils/ItemList';

export interface ComposePollHeroAttrs extends ComponentAttrs {
poll: Poll;
}

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

oninit(vnode: Mithril.Vnode<ComposePollHeroAttrs>): void {
super.oninit(vnode);

this.poll = this.attrs.poll;
}

view(): Mithril.Children {
return (
<div className="ComposeGoodieCollectionHero Hero IndexPageHero">
<div className="container">
<div className="containerNarrow">
<h2 className="Hero-title">{app.translator.trans(`fof-polls.forum.compose.${!!poll.id() ? 'edit' : 'add'}_title`)}</h2>
<div className="IndexPageHero-controls">
<LinkButton
icon="far fa-edit"
className="Button Button--secondary IndexPage-newDiscussion GoodiesManagerLink"
itemClassName="App-primaryControl"
href={app.route('fof.polls.list')}
>
{app.translator.trans('fof-polls.forum.compose.polls_manager')}
</LinkButton>
{poll.exists && (
<LinkButton
icon="far fa-arrow-up-right-from-square"
className="Button Button--secondary IndexPage-newDiscussion GoodiePreviewLink"
itemClassName="App-primaryControl"
href={app.route('fof.polls.view', { id: poll.id() })}
>
{app.translator.trans('fof-polls.forum.compose.polls_preview')}
</LinkButton>
)}
</div>
<h2 className="Hero-title">{app.translator.trans(`fof-polls.forum.compose.${!!this.poll.id() ? 'edit' : 'add'}_title`)}</h2>
<div className="IndexPageHero-controls">{this.controlItems().toArray()}</div>
</div>
</div>
</div>
);
}

controlItems(): ItemList<Mithril.Children> {
const items = new ItemList<Mithril.Children>();

items.add(
'edit',
<LinkButton
icon="far fa-edit"
className="Button Button--secondary IndexPage-newDiscussion GoodiesManagerLink"
itemClassName="App-primaryControl"
href={app.route('fof.polls.list')}
>
{app.translator.trans('fof-polls.forum.compose.polls_manager')}
</LinkButton>
);

if (this.poll.exists) {
items.add(
'view',
<LinkButton
icon="far fa-arrow-up-right-from-square"
className="Button Button--secondary IndexPage-newDiscussion GoodiePreviewLink"
itemClassName="App-primaryControl"
href={app.route('fof.polls.view', { id: this.poll.id() })}
>
{app.translator.trans('fof-polls.forum.compose.polls_preview')}
</LinkButton>
);
}

return items;
}
}
10 changes: 10 additions & 0 deletions js/src/forum/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ import PostPoll from './PostPoll';
import EditPollModal from './EditPollModal';
import ListVotersModal from './ListVotersModal';
import PollForm from './PollForm';
import ComposePollHero from './ComposePollHero';
import ComposePollPage from './ComposePollPage';
import PollsPage from './PollsPage';
import PollView from './PollView';
import PollViewPage from './PollViewPage';

export const components = {
CreatePollModal,
PostPoll,
EditPollModal,
ListVotersModal,
PollForm,
ComposePollHero,
ComposePollPage,
PollsPage,
PollView,
PollViewPage,
};

0 comments on commit 87e4d48

Please sign in to comment.