mirror of
https://github.com/flarum/core.git
synced 2025-08-06 16:36:47 +02:00
feat: Improve UX with bypass tag requirements (#153)
This commit is contained in:
1
extensions/tags/.gitignore
vendored
1
extensions/tags/.gitignore
vendored
@@ -4,3 +4,4 @@ composer.phar
|
|||||||
Thumbs.db
|
Thumbs.db
|
||||||
node_modules
|
node_modules
|
||||||
js/dist/*
|
js/dist/*
|
||||||
|
composer.lock
|
||||||
|
@@ -12,6 +12,7 @@ import tagLabel from '../../common/helpers/tagLabel';
|
|||||||
import tagIcon from '../../common/helpers/tagIcon';
|
import tagIcon from '../../common/helpers/tagIcon';
|
||||||
import sortTags from '../../common/utils/sortTags';
|
import sortTags from '../../common/utils/sortTags';
|
||||||
import getSelectableTags from '../utils/getSelectableTags';
|
import getSelectableTags from '../utils/getSelectableTags';
|
||||||
|
import ToggleButton from './ToggleButton';
|
||||||
|
|
||||||
export default class TagDiscussionModal extends Modal {
|
export default class TagDiscussionModal extends Modal {
|
||||||
oninit(vnode) {
|
oninit(vnode) {
|
||||||
@@ -28,6 +29,8 @@ export default class TagDiscussionModal extends Modal {
|
|||||||
this.minSecondary = app.forum.attribute('minSecondaryTags');
|
this.minSecondary = app.forum.attribute('minSecondaryTags');
|
||||||
this.maxSecondary = app.forum.attribute('maxSecondaryTags');
|
this.maxSecondary = app.forum.attribute('maxSecondaryTags');
|
||||||
|
|
||||||
|
this.bypassReqs = false;
|
||||||
|
|
||||||
this.navigator = new KeyboardNavigatable();
|
this.navigator = new KeyboardNavigatable();
|
||||||
this.navigator
|
this.navigator
|
||||||
.onUp(() => this.setIndex(this.getCurrentNumericIndex() - 1, true))
|
.onUp(() => this.setIndex(this.getCurrentNumericIndex() - 1, true))
|
||||||
@@ -109,7 +112,7 @@ export default class TagDiscussionModal extends Modal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getInstruction(primaryCount, secondaryCount) {
|
getInstruction(primaryCount, secondaryCount) {
|
||||||
if (app.forum.attribute('canBypassTagCounts')) {
|
if (this.bypassReqs) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,11 +146,11 @@ export default class TagDiscussionModal extends Modal {
|
|||||||
|
|
||||||
// If the number of selected primary/secondary tags is at the maximum, then
|
// If the number of selected primary/secondary tags is at the maximum, then
|
||||||
// we'll filter out all other tags of that type.
|
// we'll filter out all other tags of that type.
|
||||||
if (primaryCount >= this.maxPrimary && !app.forum.attribute('canBypassTagCounts')) {
|
if (primaryCount >= this.maxPrimary && !this.bypassReqs) {
|
||||||
tags = tags.filter(tag => !tag.isPrimary() || this.selected.includes(tag));
|
tags = tags.filter(tag => !tag.isPrimary() || this.selected.includes(tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secondaryCount >= this.maxSecondary && !app.forum.attribute('canBypassTagCounts')) {
|
if (secondaryCount >= this.maxSecondary && !this.bypassReqs) {
|
||||||
tags = tags.filter(tag => tag.isPrimary() || this.selected.includes(tag));
|
tags = tags.filter(tag => tag.isPrimary() || this.selected.includes(tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,12 +228,19 @@ export default class TagDiscussionModal extends Modal {
|
|||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
{!!app.forum.attribute('canBypassTagCounts') && (
|
||||||
|
<div className="TagDiscussionModal-controls">
|
||||||
|
<ToggleButton className="Button" onclick={() => this.bypassReqs = !this.bypassReqs} isToggled={this.bypassReqs}>
|
||||||
|
{app.translator.trans('flarum-tags.forum.choose_tags.bypass_requirements')}
|
||||||
|
</ToggleButton>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
meetsRequirements(primaryCount, secondaryCount) {
|
meetsRequirements(primaryCount, secondaryCount) {
|
||||||
if (app.forum.attribute('canBypassTagCounts')) {
|
if (this.bypassReqs) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
extensions/tags/js/src/forum/components/ToggleButton.js
Normal file
19
extensions/tags/js/src/forum/components/ToggleButton.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import Component from 'flarum/common/Component';
|
||||||
|
import Button from 'flarum/common/components/Button';
|
||||||
|
import classList from 'flarum/common/utils/classList';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @TODO move to core
|
||||||
|
*/
|
||||||
|
export default class ToggleButton extends Component {
|
||||||
|
view(vnode) {
|
||||||
|
const { className, isToggled, ...attrs } = this.attrs;
|
||||||
|
const icon = isToggled ? 'far fa-check-circle' : 'far fa-circle';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button {...attrs} icon={icon} className={classList([className, isToggled && 'Button--toggled'])}>
|
||||||
|
{vnode.children}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -4,6 +4,7 @@
|
|||||||
@import "forum/TagDiscussionModal";
|
@import "forum/TagDiscussionModal";
|
||||||
@import "forum/TagHero";
|
@import "forum/TagHero";
|
||||||
@import "forum/TagTiles";
|
@import "forum/TagTiles";
|
||||||
|
@import "forum/ToggleButton";
|
||||||
|
|
||||||
.Button--tagColored {
|
.Button--tagColored {
|
||||||
--button-primary-bg: var(--color);
|
--button-primary-bg: var(--color);
|
||||||
|
@@ -22,6 +22,10 @@
|
|||||||
padding: 1px 0 0;
|
padding: 1px 0 0;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&-controls {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media @tablet, @desktop, @desktop-hd {
|
@media @tablet, @desktop, @desktop-hd {
|
||||||
|
7
extensions/tags/less/forum/ToggleButton.less
Normal file
7
extensions/tags/less/forum/ToggleButton.less
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
:root {
|
||||||
|
.Button--color-vars(@control-bg, @control-color, 'button-toggled');
|
||||||
|
}
|
||||||
|
|
||||||
|
.Button--toggled {
|
||||||
|
.Button--color-auto('button-toggled');
|
||||||
|
}
|
@@ -66,6 +66,7 @@ flarum-tags:
|
|||||||
|
|
||||||
# These translations are used by the Choose Tags modal dialog.
|
# These translations are used by the Choose Tags modal dialog.
|
||||||
choose_tags:
|
choose_tags:
|
||||||
|
bypass_requirements: Bypass tag requirements
|
||||||
choose_primary_placeholder: "{count, plural, one {Choose a primary tag} other {Choose # primary tags}}"
|
choose_primary_placeholder: "{count, plural, one {Choose a primary tag} other {Choose # primary tags}}"
|
||||||
choose_secondary_placeholder: "{count, plural, one {Choose 1 more tag} other {Choose # more tags}}"
|
choose_secondary_placeholder: "{count, plural, one {Choose 1 more tag} other {Choose # more tags}}"
|
||||||
edit_title: "Edit Tags for {title}"
|
edit_title: "Edit Tags for {title}"
|
||||||
|
Reference in New Issue
Block a user