Skip to content

Commit

Permalink
- add compose poll hero
Browse files Browse the repository at this point in the history
- adapt CreatePollHandler to the new data structure (similar to edit)
- add translations
  • Loading branch information
novacuum committed Feb 6, 2024
1 parent be398e3 commit 26618f1
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 4 deletions.
72 changes: 71 additions & 1 deletion 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.

46 changes: 46 additions & 0 deletions js/src/forum/components/ComposePollHero.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +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";

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;

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('goodie-collection', { id: poll.id() })}
external={true}
target='_blank'>
{t(`${prfx}.goodie_preview`)}
</LinkButton>
)}
</div>
</div>
</div>
</div>
);
}
}
2 changes: 2 additions & 0 deletions js/src/forum/components/ComposePollPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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`;
Expand Down Expand Up @@ -56,6 +57,7 @@ export default class ComposePollPage extends Page {

return (
<div className='ComposeGoodieCollectionPage'>
<ComposePollHero poll={this.poll} />
<div className='container'>
<PollForm poll={this.poll} />
</div>
Expand Down
4 changes: 4 additions & 0 deletions resources/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ fof-polls:
edit_poll: => fof-polls.forum.moderation.edit
no_permission_alert: You do not have permission to start a poll.

compose:
add_title: Add a Poll
polls_manager: Polls Manager

modal:
add_title: Add a Poll
add_option_label: Add an Option
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/CreatePollHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public function handle(CreatePoll $command)
if (is_array($rawOptionsData)) {
foreach ($rawOptionsData as $rawOptionData) {
$optionsData[] = [
'answer' => Arr::get($rawOptionData, 'answer'),
'imageUrl' => Arr::get($rawOptionData, 'imageUrl') ?: null,
'answer' => Arr::get($rawOptionData, 'attributes.answer'),
'imageUrl' => Arr::get($rawOptionData, 'attributes.imageUrl') ?: null,
];
}
}
Expand Down

0 comments on commit 26618f1

Please sign in to comment.