From 6f1f8550832184ff3c1880cd9391b66de94cbef5 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 24 Sep 2020 21:56:37 -0700 Subject: [PATCH] feat: Add tracking of search source in UI --- app/components/InputSearch.js | 6 +++++- app/scenes/Collection.js | 1 + app/scenes/Dashboard.js | 2 +- app/scenes/Drafts.js | 2 +- app/scenes/Starred.js | 2 +- app/utils/routeHelpers.js | 22 +++++++++++++++------- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/components/InputSearch.js b/app/components/InputSearch.js index 526767ec..7d594580 100644 --- a/app/components/InputSearch.js +++ b/app/components/InputSearch.js @@ -12,6 +12,7 @@ import { searchUrl } from "utils/routeHelpers"; type Props = { history: RouterHistory, theme: Object, + source: string, placeholder?: string, collectionId?: string, }; @@ -33,7 +34,10 @@ class InputSearch extends React.Component { handleSearchInput = (ev) => { ev.preventDefault(); this.props.history.push( - searchUrl(ev.target.value, this.props.collectionId) + searchUrl(ev.target.value, { + collectionId: this.props.collectionId, + ref: this.props.source, + }) ); }; diff --git a/app/scenes/Collection.js b/app/scenes/Collection.js index a0bc5d3d..40729510 100644 --- a/app/scenes/Collection.js +++ b/app/scenes/Collection.js @@ -140,6 +140,7 @@ class CollectionScene extends React.Component { <> diff --git a/app/scenes/Dashboard.js b/app/scenes/Dashboard.js index 44d82d06..b0d5d788 100644 --- a/app/scenes/Dashboard.js +++ b/app/scenes/Dashboard.js @@ -67,7 +67,7 @@ class Dashboard extends React.Component { - + diff --git a/app/scenes/Drafts.js b/app/scenes/Drafts.js index f514f0a1..14ae4724 100644 --- a/app/scenes/Drafts.js +++ b/app/scenes/Drafts.js @@ -37,7 +37,7 @@ class Drafts extends React.Component { - + diff --git a/app/scenes/Starred.js b/app/scenes/Starred.js index 25000f7a..8ca71611 100644 --- a/app/scenes/Starred.js +++ b/app/scenes/Starred.js @@ -49,7 +49,7 @@ class Starred extends React.Component { - + diff --git a/app/utils/routeHelpers.js b/app/utils/routeHelpers.js index 1d7c402a..145bb283 100644 --- a/app/utils/routeHelpers.js +++ b/app/utils/routeHelpers.js @@ -63,14 +63,22 @@ export function newDocumentUrl( return `/collections/${collectionId}/new?${queryString.stringify(params)}`; } -export function searchUrl(query?: string, collectionId?: string): string { - let route = "/search"; - if (query) route += `/${encodeURIComponent(query)}`; - - if (collectionId) { - route += `?collectionId=${collectionId}`; +export function searchUrl( + query?: string, + params?: { + collectionId?: string, + ref?: string, } - return route; +): string { + let search = queryString.stringify(params); + let route = "/search"; + + if (query) { + route += `/${encodeURIComponent(query)}`; + } + + search = search ? `?${search}` : ""; + return `${route}${search}`; } export function notFoundUrl(): string {