Przeglądaj źródła

usable asynctypeahead

yusuketk 7 lat temu
rodzic
commit
ecf452de2b
1 zmienionych plików z 7 dodań i 9 usunięć
  1. 7 9
      src/client/js/components/PageTagForm.jsx

+ 7 - 9
src/client/js/components/PageTagForm.jsx

@@ -39,7 +39,6 @@ export default class PageTagForm extends React.Component {
           defaultSelected={this.props.pageTags}
           emptyLabel={''}
           isLoading={this.state.isLoading}
-          labelKey="name"
           minLength={1}
           multiple={true}
           newSelectionPrefix=""
@@ -47,15 +46,14 @@ export default class PageTagForm extends React.Component {
           onChange={(selected) => {
             this.setState({ selected });
           }}
-          onSearch={query => {
+          onSearch={async query => {
             this.setState({ isLoading: true });
-            this.crowi.apiGet('/searchTag', { q: query })
-              .then(res => {
-                this.setState({
-                  resultTags: Array.from(new Set([res.data, query])), // use Set for de-duplication
-                  isLoading: false,
-                });
-              });
+            const res = await this.crowi.apiGet('/tags.search', { q: query });
+            res.tags.push(query); // selectable query
+            this.setState({
+              resultTags: Array.from(new Set(res.tags)), // use Set for de-duplication
+              isLoading: false,
+            });
           }}
           options={this.state.resultTags} // Search result (Some tag names)
           placeholder="tag name"