- {this.store.isFetching && }
+ {this.isFetching && }
{this.props.notFound &&
Not Found
@@ -125,7 +147,7 @@ const StyledArrowKeyNavigation = styled(ArrowKeyNavigation)`
}
- {this.store.documents.map((document, index) => (
- index === 0 && this.setFirstDocumentRef(ref)}
- key={document.id}
- document={document}
- highlight={this.store.searchTerm}
- showCollection
- />
- ))}
+ {this.resultIds.map((documentId, index) => {
+ const document = documents.getById(documentId);
+ if (document)
+ return (
+
+ index === 0 && this.setFirstDocumentRef(ref)}
+ key={documentId}
+ document={document}
+ highlight={this.searchTerm}
+ showCollection
+ />
+ );
+ })}
@@ -152,4 +179,4 @@ const StyledArrowKeyNavigation = styled(ArrowKeyNavigation)`
}
}
-export default withRouter(Search);
+export default withRouter(inject('documents')(Search));
diff --git a/frontend/scenes/Search/SearchStore.js b/frontend/scenes/Search/SearchStore.js
deleted file mode 100644
index 68088ce80..000000000
--- a/frontend/scenes/Search/SearchStore.js
+++ /dev/null
@@ -1,37 +0,0 @@
-// @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 = [];
- @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;
diff --git a/frontend/static/flatpages/keyboard.md b/frontend/static/flatpages/keyboard.md
index 8d0eeeb02..56e604a0c 100644
--- a/frontend/static/flatpages/keyboard.md
+++ b/frontend/static/flatpages/keyboard.md
@@ -1,8 +1,9 @@
- `Cmd+Enter` - Save and exit document editor
-- `Cmd+S` - Save document and continue editing
+- `Cmd+s` - Save document and continue editing
- `Cmd+Esc` - Cancel edit
- `/` or `t` - Jump to search
- `d` - Jump to dashboard
- `c` - Compose within a collection
- `e` - Edit document
+- `m` - Move document
- `?` - This guide
diff --git a/frontend/stores/DocumentsStore.js b/frontend/stores/DocumentsStore.js
index cfbb70f99..c7e03e975 100644
--- a/frontend/stores/DocumentsStore.js
+++ b/frontend/stores/DocumentsStore.js
@@ -104,6 +104,14 @@ class DocumentsStore extends BaseStore {
await this.fetchAll('starred');
};
+ @action search = async (query: string): Promise<*> => {
+ const res = await client.get('/documents.search', { query });
+ invariant(res && res.data, 'res or res.data missing');
+ const { data } = res;
+ data.forEach(documentData => this.add(new Document(documentData)));
+ return data.map(documentData => documentData.id);
+ };
+
@action fetch = async (id: string): Promise<*> => {
this.isFetching = true;
diff --git a/frontend/utils/routeHelpers.js b/frontend/utils/routeHelpers.js
index 2a273bd51..e501f2a98 100644
--- a/frontend/utils/routeHelpers.js
+++ b/frontend/utils/routeHelpers.js
@@ -39,6 +39,12 @@ export function notFoundUrl(): string {
return '/404';
}
+export const matchDocumentSlug =
+ ':documentSlug([0-9a-zA-Z-]*-[a-zA-z0-9]{10,15})';
+
+export const matchDocumentEdit = `/doc/${matchDocumentSlug}/edit`;
+export const matchDocumentMove = `/doc/${matchDocumentSlug}/move`;
+
/**
* Replace full url's document part with the new one in case
* the document slug has been updated
diff --git a/server/api/documents.js b/server/api/documents.js
index a179f9830..2eb51b4f9 100644
--- a/server/api/documents.js
+++ b/server/api/documents.js
@@ -281,6 +281,8 @@ router.post('documents.move', auth(), async ctx => {
await collection.deleteDocument(document);
await collection.addDocumentToStructure(document, index);
}
+ // Update collection
+ document.collection = collection;
document.collection = collection;