Skip to content

Commit

Permalink
feat: add start global poll button
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideIadeluca committed Feb 2, 2024
1 parent 29269d5 commit 418677b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
36 changes: 35 additions & 1 deletion js/src/forum/components/PollsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Poll from './Poll';
import PollList from './Poll/PollList';
import extractText from 'flarum/common/utils/extractText';
import PollListState from '../states/PollListState';
import Button from 'flarum/common/components/Button';
import SelectDropdown from 'flarum/common/components/SelectDropdown';

export default class PollsPage extends Page {
oninit(vnode: Mithril.Vnode) {
Expand Down Expand Up @@ -44,7 +46,39 @@ export default class PollsPage extends Page {
}

sidebarItems() {
return IndexPage.prototype.sidebarItems();
const items = new ItemList<Mithril.Children>();
const canStartPoll = app.forum.attribute('canStartPoll') || !app.session.user;
console.info(canStartPoll);

items.add(
'newGlobalPoll',
<Button
icon="fas fa-edit"
className="Button Button--primary IndexPage-newDiscussion"
itemClassName="App-primaryControl"
onclick={() => {
// If the user is not logged in, the promise rejects, and a login modal shows up.
// Since that's already handled, we dont need to show an error message in the console.
// return this.newPollAction().catch(() => {});
}}
disabled={!canStartPoll}
>
{app.translator.trans(`fof-polls.forum.poll.${canStartPoll ? 'start_poll_button' : 'cannot_start_poll_button'}`)}
</Button>
);

items.add(
'nav',
<SelectDropdown
buttonClassName="Button"
className="App-titleControl"
accessibleToggleLabel={app.translator.trans('core.forum.index.toggle_sidenav_dropdown_accessible_label')}
>
{this.navItems().toArray()}
</SelectDropdown>
);

return items;
}

// actionItems() {
Expand Down
9 changes: 9 additions & 0 deletions resources/less/forum.less
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@
}
}

@media @desktop-up {
.PollsPage .item-newGlobalPoll .Button {
display: block;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
}

.Poll {
// display: flex;
// gap: 10px;
Expand Down
2 changes: 2 additions & 0 deletions resources/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ fof-polls:
poll:
cannot_change_vote: You cannot change your vote after voting.
submit_button: Vote
start_poll_button: Start Global Poll
cannot_start_poll_button: Cannot Start Poll

composer_discussion:
add_poll: => fof-polls.forum.moderation.add
Expand Down

0 comments on commit 418677b

Please sign in to comment.