summaryrefslogtreecommitdiffstats
path: root/ui/src/components/post-form.tsx
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-01-24 13:59:50 -0500
committerDessalines <tyhou13@gmx.com>2020-01-24 13:59:50 -0500
commit608856b6cdd42b83f35eee8cb556ac626e75727f (patch)
treeccb74ba0a840d24a69f8ba3f3e95e06b5b5cce26 /ui/src/components/post-form.tsx
parent353891a3d1af878a8ce8d5562f3deaa9be380144 (diff)
Adding autocomplete to post, community, message, and site forms. Fixes #453
Diffstat (limited to 'ui/src/components/post-form.tsx')
-rw-r--r--ui/src/components/post-form.tsx16
1 files changed, 15 insertions, 1 deletions
diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx
index 44061774..677007ca 100644
--- a/ui/src/components/post-form.tsx
+++ b/ui/src/components/post-form.tsx
@@ -30,8 +30,11 @@ import {
debounce,
isImage,
toast,
+ randomStr,
+ setupTribute,
} from '../utils';
import autosize from 'autosize';
+import Tribute from 'tributejs/src/Tribute.js';
import { i18n } from '../i18next';
import { T } from 'inferno-i18next';
@@ -56,6 +59,8 @@ interface PostFormState {
}
export class PostForm extends Component<PostFormProps, PostFormState> {
+ private id = `post-form-${randomStr()}`;
+ private tribute: Tribute;
private subscription: Subscription;
private emptyState: PostFormState = {
postForm: {
@@ -82,6 +87,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
this.fetchSimilarPosts = debounce(this.fetchSimilarPosts).bind(this);
this.fetchPageTitle = debounce(this.fetchPageTitle).bind(this);
+ this.tribute = setupTribute();
this.state = this.emptyState;
if (this.props.post) {
@@ -126,7 +132,14 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
}
componentDidMount() {
- autosize(document.querySelectorAll('textarea'));
+ var textarea: any = document.getElementById(this.id);
+ autosize(textarea);
+ this.tribute.attach(textarea);
+ textarea.addEventListener('tribute-replaced', () => {
+ this.state.postForm.body = textarea.value;
+ this.setState(this.state);
+ autosize.update(textarea);
+ });
}
componentWillUnmount() {
@@ -238,6 +251,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
</label>
<div class="col-sm-10">
<textarea
+ id={this.id}
value={this.state.postForm.body}
onInput={linkEvent(this, this.handlePostBodyChange)}
className={`form-control ${this.state.previewMode && 'd-none'}`}