diff --git a/extend.php b/extend.php index d4073bf0..6d4be766 100755 --- a/extend.php +++ b/extend.php @@ -17,8 +17,9 @@ use Flarum\Api\Serializer\PostSerializer; use Flarum\Discussion\Discussion; use Flarum\Extend; -use Flarum\Post\Event\Saving; +use Flarum\Post\Event\Saving as PostSaving; use Flarum\Post\Post; +use Flarum\Settings\Event\Saved as SettingsSaved; use FoF\Polls\Api\Controllers; use FoF\Polls\Api\Serializers\PollSerializer; @@ -47,7 +48,16 @@ ->hasMany('polls', Poll::class, 'post_id', 'first_post_id'), (new Extend\Event()) - ->listen(Saving::class, Listeners\SavePollsToDatabase::class), + ->listen(PostSaving::class, Listeners\SavePollsToDatabase::class) + ->listen(SettingsSaved::class, function (SettingsSaved $event) { + foreach ($event->settings as $key => $value) { + if ($key === 'fof-polls.optionsColorBlend') { + resolve('fof-user-bio.formatter')->flush(); + + return; + } + } + }), (new Extend\ApiSerializer(DiscussionSerializer::class)) ->attribute('hasPoll', function (DiscussionSerializer $serializer, Discussion $discussion): bool { @@ -100,8 +110,12 @@ (new Extend\Settings()) ->default('fof-polls.maxOptions', 10) + ->default('fof-polls.optionsColorBlend', true) ->serializeToForum('allowPollOptionImage', 'fof-polls.allowOptionImage', 'boolval') - ->serializeToForum('pollMaxOptions', 'fof-polls.maxOptions', 'intval'), + ->serializeToForum('pollMaxOptions', 'fof-polls.maxOptions', 'intval') + ->registerLessConfigVar('fof-polls-options-color-blend', 'fof-polls.optionsColorBlend', function ($value) { + return $value ? 'true' : 'false'; + }), (new Extend\ModelVisibility(Poll::class)) ->scope(Access\ScopePollVisibility::class), diff --git a/js/src/admin/index.ts b/js/src/admin/index.ts index f1f97eb6..e45965af 100755 --- a/js/src/admin/index.ts +++ b/js/src/admin/index.ts @@ -8,6 +8,12 @@ app.initializers.add('fof/polls', () => { type: 'switch', label: app.translator.trans('fof-polls.admin.settings.allow_option_image'), }) + .registerSetting({ + setting: 'fof-polls.optionsColorBlend', + type: 'switch', + label: app.translator.trans('fof-polls.admin.settings.options_color_blend'), + help: app.translator.trans('fof-polls.admin.settings.options_color_blend_help'), + }) .registerSetting({ setting: 'fof-polls.maxOptions', type: 'number', diff --git a/js/src/forum/components/PostPoll.js b/js/src/forum/components/PostPoll.js index 1ed159ce..c312f98e 100644 --- a/js/src/forum/components/PostPoll.js +++ b/js/src/forum/components/PostPoll.js @@ -7,6 +7,7 @@ import ListVotersModal from './ListVotersModal'; import classList from 'flarum/common/utils/classList'; import ItemList from 'flarum/common/utils/ItemList'; import Tooltip from 'flarum/common/components/Tooltip'; +import icon from 'flarum/common/helpers/icon'; import EditPollModal from './EditPollModal'; export default class PostPoll extends Component { @@ -149,24 +150,21 @@ export default class PostPoll extends Component { const showCheckmark = !app.session.user || (!poll.hasEnded() && poll.canVote() && (!hasVoted || poll.canChangeVote())); const bar = ( -
+
{showCheckmark && ( -