summaryrefslogtreecommitdiffstats
path: root/ui/src/components/post-form.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/components/post-form.tsx')
-rw-r--r--ui/src/components/post-form.tsx85
1 files changed, 50 insertions, 35 deletions
diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx
index a88d38c7..e5efeaac 100644
--- a/ui/src/components/post-form.tsx
+++ b/ui/src/components/post-form.tsx
@@ -33,14 +33,14 @@ import {
randomStr,
setupTribute,
setupTippy,
- emojiPicker,
hostname,
pictrsDeleteToast,
+ validTitle,
} from '../utils';
import autosize from 'autosize';
import Tribute from 'tributejs/src/Tribute.js';
import emojiShortName from 'emoji-short-name';
-import Selectr from 'mobius1-selectr';
+import Choices from 'choices.js';
import { i18n } from '../i18next';
const MAX_POST_TITLE_LENGTH = 200;
@@ -70,6 +70,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
private id = `post-form-${randomStr()}`;
private tribute: Tribute;
private subscription: Subscription;
+ private choices: Choices;
private emptyState: PostFormState = {
postForm: {
name: null,
@@ -95,7 +96,6 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
this.fetchPageTitle = debounce(this.fetchPageTitle).bind(this);
this.tribute = setupTribute();
- this.setupEmojiPicker();
this.state = this.emptyState;
@@ -166,6 +166,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
componentWillUnmount() {
this.subscription.unsubscribe();
+ this.choices && this.choices.destroy();
window.onbeforeunload = null;
}
@@ -271,12 +272,19 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
value={this.state.postForm.name}
id="post-title"
onInput={linkEvent(this, this.handlePostNameChange)}
- class="form-control"
+ class={`form-control ${
+ !validTitle(this.state.postForm.name) && 'is-invalid'
+ }`}
required
rows={2}
minLength={3}
maxLength={MAX_POST_TITLE_LENGTH}
/>
+ {!validTitle(this.state.postForm.name) && (
+ <div class="invalid-feedback">
+ {i18n.t('invalid_post_title')}
+ </div>
+ )}
{this.state.suggestedPosts.length > 0 && (
<>
<div class="my-1 text-muted small font-weight-bold">
@@ -332,15 +340,6 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
<use xlinkHref="#icon-help-circle"></use>
</svg>
</a>
- <span
- onClick={linkEvent(this, this.handleEmojiPickerClick)}
- class="pointer unselectable d-inline-block mr-3 float-right text-muted font-weight-bold"
- data-tippy-content={i18n.t('emoji_picker')}
- >
- <svg class="icon icon-inline">
- <use xlinkHref="#icon-smile"></use>
- </svg>
- </span>
</div>
</div>
{!this.props.post && (
@@ -420,20 +419,6 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
);
}
- setupEmojiPicker() {
- emojiPicker.on('emoji', twemojiHtmlStr => {
- if (this.state.postForm.body == null) {
- this.state.postForm.body = '';
- }
- var el = document.createElement('div');
- el.innerHTML = twemojiHtmlStr;
- let nativeUnicode = (el.childNodes[0] as HTMLElement).getAttribute('alt');
- let shortName = `:${emojiShortName[nativeUnicode]}:`;
- this.state.postForm.body += shortName;
- this.setState(this.state);
- });
- }
-
handlePostSubmit(i: PostForm, event: any) {
event.preventDefault();
@@ -596,10 +581,6 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
});
}
- handleEmojiPickerClick(_i: PostForm, event: any) {
- emojiPicker.togglePicker(event.target);
- }
-
parseMessage(msg: WebSocketJsonResponse) {
let res = wsJsonToRes(msg);
if (msg.error) {
@@ -625,11 +606,45 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
// Set up select searching
let selectId: any = document.getElementById('post-community');
if (selectId) {
- let selector = new Selectr(selectId, { nativeDropdown: false });
- selector.on('selectr.select', option => {
- this.state.postForm.community_id = Number(option.value);
- this.setState(this.state);
+ this.choices = new Choices(selectId, {
+ shouldSort: false,
+ classNames: {
+ containerOuter: 'choices',
+ containerInner: 'choices__inner bg-secondary border-0',
+ input: 'form-control',
+ inputCloned: 'choices__input--cloned',
+ list: 'choices__list',
+ listItems: 'choices__list--multiple',
+ listSingle: 'choices__list--single',
+ listDropdown: 'choices__list--dropdown',
+ item: 'choices__item bg-secondary',
+ itemSelectable: 'choices__item--selectable',
+ itemDisabled: 'choices__item--disabled',
+ itemChoice: 'choices__item--choice',
+ placeholder: 'choices__placeholder',
+ group: 'choices__group',
+ groupHeading: 'choices__heading',
+ button: 'choices__button',
+ activeState: 'is-active',
+ focusState: 'is-focused',
+ openState: 'is-open',
+ disabledState: 'is-disabled',
+ highlightedState: 'text-info',
+ selectedState: 'text-info',
+ flippedState: 'is-flipped',
+ loadingState: 'is-loading',
+ noResults: 'has-no-results',
+ noChoices: 'has-no-choices',
+ },
});
+ this.choices.passedElement.element.addEventListener(
+ 'choice',
+ (e: any) => {
+ this.state.postForm.community_id = Number(e.detail.choice.value);
+ this.setState(this.state);
+ },
+ false
+ );
}
} else if (res.op == UserOperation.CreatePost) {
let data = res.data as PostResponse;