From 5c43e1221837d3b11c88a15b01d5a7cd7ea6f700 Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Tue, 12 Sep 2017 19:55:01 -0700 Subject: [PATCH] Moved document matching to use urlId to prevent issues with renamed documents --- frontend/scenes/Document/Document.js | 4 ++++ frontend/stores/DocumentsStore.js | 5 ++++- server/presenters/document.js | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/scenes/Document/Document.js b/frontend/scenes/Document/Document.js index 4bc09784..b7f80090 100644 --- a/frontend/scenes/Document/Document.js +++ b/frontend/scenes/Document/Document.js @@ -90,6 +90,10 @@ type Props = { if (document) { this.props.ui.setActiveDocument(document); document.view(); + + // Update url to match the current one + const urlParts = this.props.match.url.split('/'); + this.props.history.replace([document.url, urlParts.slice(3)].join('/')); } else { // Render 404 with search this.setState({ notFound: true }); diff --git a/frontend/stores/DocumentsStore.js b/frontend/stores/DocumentsStore.js index 7ccedcad..cfbb70f9 100644 --- a/frontend/stores/DocumentsStore.js +++ b/frontend/stores/DocumentsStore.js @@ -138,8 +138,11 @@ class DocumentsStore extends BaseStore { return this.data.get(id); }; + /** + * Match documents by the url ID as the title slug can change + */ getByUrl = (url: string): ?Document => { - return _.find(this.data.values(), { url }); + return _.find(this.data.values(), doc => url.endsWith(doc.urlId)); }; constructor(options: Options) { diff --git a/server/presenters/document.js b/server/presenters/document.js index 0ca0ea18..5927a83d 100644 --- a/server/presenters/document.js +++ b/server/presenters/document.js @@ -17,6 +17,7 @@ async function present(ctx: Object, document: Document, options: ?Options) { const data = { id: document.id, url: document.getUrl(), + urlId: document.urlId, private: document.private, title: document.title, text: document.text,