From 24db3ae6759b8047590ad26a505cc9038c54c7bd Mon Sep 17 00:00:00 2001 From: Simon Hiller Date: Tue, 20 Feb 2024 15:06:50 +0100 Subject: [PATCH] bugfix: fix bug about saving polls from posts etc. and add missing texts --- js/src/forum/components/ComposePollPage.tsx | 44 +++++++++- js/src/forum/components/CreatePollModal.js | 7 +- js/src/forum/components/EditPollModal.js | 15 ++++ js/src/forum/components/Poll.tsx | 5 +- .../forum/components/Poll/PollDescription.tsx | 12 --- js/src/forum/components/Poll/PollListItem.tsx | 27 +++--- js/src/forum/components/Poll/PollResult.tsx | 23 +++-- js/src/forum/components/Poll/PollSubTitle.tsx | 12 +++ js/src/forum/components/PollForm.js | 87 +++++-------------- js/src/forum/extend.ts | 4 +- js/src/forum/states/PollState.ts | 5 +- js/src/forum/utils/PollControls.tsx | 4 +- resources/less/forum.less | 4 +- resources/locale/en.yml | 4 + 14 files changed, 133 insertions(+), 120 deletions(-) delete mode 100644 js/src/forum/components/Poll/PollDescription.tsx create mode 100644 js/src/forum/components/Poll/PollSubTitle.tsx diff --git a/js/src/forum/components/ComposePollPage.tsx b/js/src/forum/components/ComposePollPage.tsx index da765071..055c83f2 100644 --- a/js/src/forum/components/ComposePollPage.tsx +++ b/js/src/forum/components/ComposePollPage.tsx @@ -8,6 +8,7 @@ import Acl from '../../common/Acl'; import PollFormState from '../states/PollFormState'; import { slug } from '../../common'; import ComposePollHero from './ComposePollHero'; +import Button from 'flarum/common/components/Button'; const t = app.translator.trans.bind(app.translator); const prfx = `${slug}.forum.compose`; @@ -44,8 +45,8 @@ export default class ComposePollPage extends Page { this.poll = PollFormState.createNewPoll(); } - app.history.push('compose-goodie-collection'); - this.bodyClass = 'App--compose-goodie-collection'; + app.history.push('compose-poll'); + this.bodyClass = 'App--compose-poll'; app.setTitle(t(`${prfx}.${!!this.poll?.id() ? 'edit' : 'add'}_title`)); } @@ -58,9 +59,46 @@ export default class ComposePollPage extends Page {
- +
); } + + async onsubmit(data: Object, state: PollFormState) { + const isNew = state.poll.id() === undefined; + await state.save(data); + + const alertAttrs = isNew + ? { + type: 'success', + controls: [ + , + ], + } + : { + type: 'success', + }; + + // Show success alert + const alertId = app.alerts.show(alertAttrs, t(`${prfx}.success`)); + + // Hide alert after 10 seconds + setTimeout(() => app.alerts.dismiss(alertId), 10000); + + if (isNew) { + m.route.set(app.route('fof_polls_list')); + } + } } diff --git a/js/src/forum/components/CreatePollModal.js b/js/src/forum/components/CreatePollModal.js index d0725cac..1a59f08d 100755 --- a/js/src/forum/components/CreatePollModal.js +++ b/js/src/forum/components/CreatePollModal.js @@ -12,16 +12,15 @@ export default class CreatePollModal extends Modal { } content() { - //@todo check if bind is needed for onsubmit return [
- +
, ]; } - onsubmit(poll) { + onsubmit(data) { this.hide(); - this.attrs.onsubmit(poll); + this.attrs.onsubmit(data); } } diff --git a/js/src/forum/components/EditPollModal.js b/js/src/forum/components/EditPollModal.js index 304a6470..be113f49 100755 --- a/js/src/forum/components/EditPollModal.js +++ b/js/src/forum/components/EditPollModal.js @@ -5,4 +5,19 @@ export default class EditPollModal extends CreatePollModal { title() { return app.translator.trans('fof-polls.forum.modal.edit_title'); } + + async onsubmit(data, state) { + await state.save(data); + + // Show success alert + const alertId = app.alerts.show( + { + type: 'success', + }, + app.translator.trans('fof-polls.forum.compose.success') + ); + + // Hide alert after 10 seconds + setTimeout(() => app.alerts.dismiss(alertId), 10000); + } } diff --git a/js/src/forum/components/Poll.tsx b/js/src/forum/components/Poll.tsx index d51430af..b4950181 100644 --- a/js/src/forum/components/Poll.tsx +++ b/js/src/forum/components/Poll.tsx @@ -4,10 +4,9 @@ import app from 'flarum/forum/app'; import PollTitle from './Poll/PollTitle'; import PollOptions from './Poll/PollOptions'; import PollImage from './Poll/PollImage'; -import PollDescription from './Poll/PollDescription'; +import PollSubTitle from './Poll/PollSubTitle'; import PollModel from '../models/Poll'; import PollState from '../states/PollState'; -import Tooltip from 'flarum/common/components/Tooltip'; import Button from 'flarum/common/components/Button'; import ItemList from 'flarum/common/utils/ItemList'; import { slug } from '../../common'; @@ -49,7 +48,7 @@ export default class Poll extends Component {
- +
Antworten diff --git a/js/src/forum/components/Poll/PollDescription.tsx b/js/src/forum/components/Poll/PollDescription.tsx deleted file mode 100644 index 96fb4994..00000000 --- a/js/src/forum/components/Poll/PollDescription.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as Mithril from 'mithril'; -import Component, { ComponentAttrs } from 'flarum/common/Component'; - -interface PollDescriptionAttrs extends ComponentAttrs { - text: String; -} - -export default class PollDescription extends Component { - view(): Mithril.Children { - return

{this.attrs.text}

; - } -} diff --git a/js/src/forum/components/Poll/PollListItem.tsx b/js/src/forum/components/Poll/PollListItem.tsx index 3ddce696..36369989 100644 --- a/js/src/forum/components/Poll/PollListItem.tsx +++ b/js/src/forum/components/Poll/PollListItem.tsx @@ -183,28 +183,27 @@ export default class PollListItem{activeView}); const voteCount = poll.voteCount(); - if(voteCount !== undefined){ + if (voteCount !== undefined) { items.add( - 'discussion-count', -
- {icon('fas fa-poll fa-fw')} - {[ - ' ', - t('fof-polls.forum.polls_count', { - count: abbreviateNumber(voteCount), - }), - ]} -
, - 70 + 'discussion-count', +
+ {icon('fas fa-poll fa-fw')} + {[ + ' ', + t('fof-polls.forum.polls_count', { + count: abbreviateNumber(voteCount), + }), + ]} +
, + 70 ); } - return items; } } diff --git a/js/src/forum/components/Poll/PollResult.tsx b/js/src/forum/components/Poll/PollResult.tsx index 6e1ab378..e2ff796c 100644 --- a/js/src/forum/components/Poll/PollResult.tsx +++ b/js/src/forum/components/Poll/PollResult.tsx @@ -1,15 +1,15 @@ import * as Mithril from 'mithril'; -import Component, {ComponentAttrs} from 'flarum/common/Component'; +import Component, { ComponentAttrs } from 'flarum/common/Component'; import PollOptionLabel from './PollOptionLabel'; import PollResultsNumber from './PollResultNumber'; import PollOptionInput from './PollOptionInput'; -import PollOptionModel from "../../models/PollOption"; -import PollState from "../../states/PollState"; -import abbreviateNumber from "flarum/common/utils/abbreviateNumber"; +import PollOptionModel from '../../models/PollOption'; +import PollState from '../../states/PollState'; +import abbreviateNumber from 'flarum/common/utils/abbreviateNumber'; interface PollResultsAttrs extends ComponentAttrs { - option: PollOptionModel; - state: PollState; + option: PollOptionModel; + state: PollState; } export default class PollResults extends Component { @@ -17,16 +17,15 @@ export default class PollResults extends Component { const option = this.attrs.option; const state = this.attrs.state; let voteCount = option.voteCount(); - if(!voteCount){ - voteCount = 0; - } - else { - voteCount = voteCount * 100 / state.overallVoteCount(); + if (!voteCount) { + voteCount = 0; + } else { + voteCount = (voteCount * 100) / state.overallVoteCount(); } return (