summaryrefslogtreecommitdiffstats
path: root/ui/src/components/community-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/community-form.tsx
parent353891a3d1af878a8ce8d5562f3deaa9be380144 (diff)
Adding autocomplete to post, community, message, and site forms. Fixes #453
Diffstat (limited to 'ui/src/components/community-form.tsx')
-rw-r--r--ui/src/components/community-form.tsx22
1 files changed, 20 insertions, 2 deletions
diff --git a/ui/src/components/community-form.tsx b/ui/src/components/community-form.tsx
index 4dc7bfcb..33c63c89 100644
--- a/ui/src/components/community-form.tsx
+++ b/ui/src/components/community-form.tsx
@@ -11,7 +11,14 @@ import {
WebSocketJsonResponse,
} from '../interfaces';
import { WebSocketService } from '../services';
-import { wsJsonToRes, capitalizeFirstLetter, toast } from '../utils';
+import {
+ wsJsonToRes,
+ capitalizeFirstLetter,
+ toast,
+ randomStr,
+ setupTribute,
+} from '../utils';
+import Tribute from 'tributejs/src/Tribute.js';
import autosize from 'autosize';
import { i18n } from '../i18next';
import { T } from 'inferno-i18next';
@@ -36,6 +43,8 @@ export class CommunityForm extends Component<
CommunityFormProps,
CommunityFormState
> {
+ private id = `community-form-${randomStr()}`;
+ private tribute: Tribute;
private subscription: Subscription;
private emptyState: CommunityFormState = {
@@ -53,6 +62,7 @@ export class CommunityForm extends Component<
constructor(props: any, context: any) {
super(props, context);
+ this.tribute = setupTribute();
this.state = this.emptyState;
if (this.props.community) {
@@ -80,7 +90,14 @@ export class CommunityForm extends Component<
}
componentDidMount() {
- autosize(document.querySelectorAll('textarea'));
+ var textarea: any = document.getElementById(this.id);
+ autosize(textarea);
+ this.tribute.attach(textarea);
+ textarea.addEventListener('tribute-replaced', () => {
+ this.state.communityForm.description = textarea.value;
+ this.setState(this.state);
+ autosize.update(textarea);
+ });
}
componentWillUnmount() {
@@ -130,6 +147,7 @@ export class CommunityForm extends Component<
</label>
<div class="col-12">
<textarea
+ id={this.id}
value={this.state.communityForm.description}
onInput={linkEvent(this, this.handleCommunityDescriptionChange)}
class="form-control"