This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
outline/frontend/scenes/Search/SearchStore.js
Tom Moor 3b2ad193d5 DocumentPreview Improves (#141)
* Show collection name in search results
Highlight documents modified since last edited
Move views to scope

* Allow ESC key to work on Search page when input not focused

* Update document title with search query
Show loading indicator for search results

* WIP

* 💚 ?

* 💚

* Address PR feedback
2017-07-16 09:24:45 -07:00

38 lines
967 B
JavaScript

// @flow
import { observable, action, runInAction } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
import Document from 'models/Document';
class SearchStore {
@observable documents: Array<Document> = [];
@observable searchTerm: ?string = null;
@observable isFetching = false;
/* Actions */
@action search = async (query: string) => {
this.searchTerm = query;
this.isFetching = true;
if (query) {
try {
const res = await client.get('/documents.search', { query });
invariant(res && res.data, 'res or res.data missing');
const { data } = res;
runInAction('search document', () => {
this.documents = data.map(documentData => new Document(documentData));
});
} catch (e) {
console.error('Something went wrong');
}
} else {
this.documents = [];
}
this.isFetching = false;
};
}
export default SearchStore;