From 7bd3b6766536e33146bb55506c79619a1ab7d3b3 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sun, 10 Dec 2017 11:10:05 +0100 Subject: Move reducers and actions into seperate folders --- src/client/react/reducers/search.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/client/react/reducers/search.js (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js new file mode 100644 index 0000000..05926c9 --- /dev/null +++ b/src/client/react/reducers/search.js @@ -0,0 +1,21 @@ +const DEFAULT_STATE = { + searchInput: '', + searchResults: [], +}; + +const search = (state = DEFAULT_STATE, action) => { + switch (action.type) { + case 'SEARCH/TYPE': + return { + ...state, + searchInput: action.typedValue, + searchResults: [ + { type: 's', name: '18561' }, + ], + }; + default: + return state; + } +}; + +export default search; -- cgit v1.1 From 1286c6556115f80218a4828d29b288f56b3d795f Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sun, 10 Dec 2017 11:13:08 +0100 Subject: Rename onType to onInputChange --- src/client/react/reducers/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 05926c9..08be519 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -5,7 +5,7 @@ const DEFAULT_STATE = { const search = (state = DEFAULT_STATE, action) => { switch (action.type) { - case 'SEARCH/TYPE': + case 'SEARCH/INPUT_CHANGE': return { ...state, searchInput: action.typedValue, -- cgit v1.1 From 9f6a36d1f1a16c1a777a23fcc8c986c45ee0a116 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sun, 10 Dec 2017 13:25:46 +0100 Subject: Add some basic styling --- src/client/react/reducers/search.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 08be519..a695184 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -1,6 +1,7 @@ const DEFAULT_STATE = { searchInput: '', searchResults: [], + hasFocus: false, }; const search = (state = DEFAULT_STATE, action) => { @@ -13,6 +14,11 @@ const search = (state = DEFAULT_STATE, action) => { { type: 's', name: '18561' }, ], }; + case 'SEARCH/FOCUS_CHANGE': + return { + ...state, + hasFocus: action.hasFocus, + }; default: return state; } -- cgit v1.1 From 7e63aa14ea4298a1511f75e875ca001d2bd61ee8 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sun, 10 Dec 2017 13:53:07 +0100 Subject: Add results --- src/client/react/reducers/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index a695184..50233a7 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -11,7 +11,7 @@ const search = (state = DEFAULT_STATE, action) => { ...state, searchInput: action.typedValue, searchResults: [ - { type: 's', name: '18561' }, + { type: 's', value: '18561' }, ], }; case 'SEARCH/FOCUS_CHANGE': -- cgit v1.1 From 29338e66b28daee52f7fe5a5cdab49140b3e5a60 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sun, 10 Dec 2017 14:06:11 +0100 Subject: Show correct icon based on user type --- src/client/react/reducers/search.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 50233a7..4e2032d 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -12,6 +12,9 @@ const search = (state = DEFAULT_STATE, action) => { searchInput: action.typedValue, searchResults: [ { type: 's', value: '18561' }, + { type: 'c', value: '5H2' }, + { type: 't', value: 'akh' }, + { type: 'r', value: '008-mk' }, ], }; case 'SEARCH/FOCUS_CHANGE': -- cgit v1.1 From 36dc0fb88258af24069f61935656334c35ef13b3 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sun, 10 Dec 2017 14:23:35 +0100 Subject: Make search function --- src/client/react/reducers/search.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 4e2032d..72fa469 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -1,21 +1,36 @@ +/* global USERS */ +import fuzzy from 'fuzzy'; + const DEFAULT_STATE = { searchInput: '', - searchResults: [], + searchResults: [ + { type: 's', value: '18561' }, + ], hasFocus: false, }; +function getSearchResults(query) { + if (query.trim() === '') { + return []; + } + + const allResults = fuzzy.filter(query, USERS, { + extract: user => user.value, + }); + + const firstResults = allResults.splice(0, 4); + const users = firstResults.map(result => result.original); + + return users; +} + const search = (state = DEFAULT_STATE, action) => { switch (action.type) { case 'SEARCH/INPUT_CHANGE': return { ...state, searchInput: action.typedValue, - searchResults: [ - { type: 's', value: '18561' }, - { type: 'c', value: '5H2' }, - { type: 't', value: 'akh' }, - { type: 'r', value: '008-mk' }, - ], + searchResults: getSearchResults(action.typedValue), }; case 'SEARCH/FOCUS_CHANGE': return { -- cgit v1.1 From 797fb96cd0001d6c739c89507befc73d3d8a6614 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sun, 10 Dec 2017 15:58:25 +0100 Subject: Show user icon instead of search icon on exact match --- src/client/react/reducers/search.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 72fa469..dd737ed 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -6,6 +6,7 @@ const DEFAULT_STATE = { searchResults: [ { type: 's', value: '18561' }, ], + exactMatch: null, hasFocus: false, }; @@ -26,12 +27,22 @@ function getSearchResults(query) { const search = (state = DEFAULT_STATE, action) => { switch (action.type) { - case 'SEARCH/INPUT_CHANGE': + case 'SEARCH/INPUT_CHANGE': { + let results = getSearchResults(action.typedValue); + let exactMatch = false; + + if ((results.length > 0) && (action.typedValue === results[0].value)) { + [exactMatch] = results; + results = results.splice(1); + } + return { ...state, searchInput: action.typedValue, - searchResults: getSearchResults(action.typedValue), + searchResults: results, + exactMatch, }; + } case 'SEARCH/FOCUS_CHANGE': return { ...state, -- cgit v1.1 From 088f0a2c1ca5d305d83ff001650cca729643c718 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sun, 10 Dec 2017 19:12:20 +0100 Subject: Use when when there is no exact match --- src/client/react/reducers/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index dd737ed..5d8fee5 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -29,7 +29,7 @@ const search = (state = DEFAULT_STATE, action) => { switch (action.type) { case 'SEARCH/INPUT_CHANGE': { let results = getSearchResults(action.typedValue); - let exactMatch = false; + let exactMatch = null; if ((results.length > 0) && (action.typedValue === results[0].value)) { [exactMatch] = results; -- cgit v1.1 From ddccdcf22bb5008022e93c4789311fb2da95d7cf Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sun, 10 Dec 2017 19:24:53 +0100 Subject: Refactor state names --- src/client/react/reducers/search.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 5d8fee5..52f3b4e 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -2,8 +2,8 @@ import fuzzy from 'fuzzy'; const DEFAULT_STATE = { - searchInput: '', - searchResults: [ + input: '', + results: [ { type: 's', value: '18561' }, ], exactMatch: null, @@ -31,6 +31,8 @@ const search = (state = DEFAULT_STATE, action) => { let results = getSearchResults(action.typedValue); let exactMatch = null; + // Is the typed value exactly the same as the first result? Then show the + // appropiate icon instead of the generic search icon. if ((results.length > 0) && (action.typedValue === results[0].value)) { [exactMatch] = results; results = results.splice(1); @@ -38,8 +40,8 @@ const search = (state = DEFAULT_STATE, action) => { return { ...state, - searchInput: action.typedValue, - searchResults: results, + input: action.typedValue, + results, exactMatch, }; } -- cgit v1.1 From b00e556ebff50558e6532683ff2763825c51646f Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Mon, 11 Dec 2017 20:52:17 +0100 Subject: Move hasFocus to internal state --- src/client/react/reducers/search.js | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 52f3b4e..d61689b 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -7,7 +7,6 @@ const DEFAULT_STATE = { { type: 's', value: '18561' }, ], exactMatch: null, - hasFocus: false, }; function getSearchResults(query) { @@ -45,11 +44,6 @@ const search = (state = DEFAULT_STATE, action) => { exactMatch, }; } - case 'SEARCH/FOCUS_CHANGE': - return { - ...state, - hasFocus: action.hasFocus, - }; default: return state; } -- cgit v1.1 From fe27a0819a60caaa69b059f0c86d95ab0c4084b7 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Wed, 13 Dec 2017 12:26:36 +0100 Subject: Prepair changeSelectedResult --- src/client/react/reducers/search.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index d61689b..f566b49 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -6,7 +6,8 @@ const DEFAULT_STATE = { results: [ { type: 's', value: '18561' }, ], - exactMatch: null, + selectedResult: null, + isExactMatch: false, }; function getSearchResults(query) { @@ -28,12 +29,14 @@ const search = (state = DEFAULT_STATE, action) => { switch (action.type) { case 'SEARCH/INPUT_CHANGE': { let results = getSearchResults(action.typedValue); - let exactMatch = null; + let selectedResult = null; + let isExactMatch = false; // Is the typed value exactly the same as the first result? Then show the // appropiate icon instead of the generic search icon. if ((results.length > 0) && (action.typedValue === results[0].value)) { - [exactMatch] = results; + [selectedResult] = results; + isExactMatch = true; results = results.splice(1); } @@ -41,7 +44,8 @@ const search = (state = DEFAULT_STATE, action) => { ...state, input: action.typedValue, results, - exactMatch, + selectedResult, + isExactMatch, }; } default: -- cgit v1.1 From 503ab5c66ab524dfe36aed84a01899cd07ed2bc5 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Wed, 13 Dec 2017 15:53:19 +0100 Subject: Allow selection of result using keyboard --- src/client/react/reducers/search.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index f566b49..6ef0f4d 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -48,6 +48,34 @@ const search = (state = DEFAULT_STATE, action) => { isExactMatch, }; } + + case 'SEARCH/CHANGE_SELECTED_RESULT': { + const { results, isExactMatch } = state; + const prevSelectedResult = state.selectedResult; + const prevSelectedResultIndex = results.indexOf(prevSelectedResult); + let nextSelectedResultIndex = + prevSelectedResultIndex + action.relativeChange; + + if (nextSelectedResultIndex < -1) { + nextSelectedResultIndex = results.length - 1; + } else if (nextSelectedResultIndex > results.length - 1) { + nextSelectedResultIndex = -1; + } + + let nextSelectedResult = + nextSelectedResultIndex === -1 + ? null + : results[nextSelectedResultIndex]; + + if (isExactMatch) { + nextSelectedResult = prevSelectedResult; + } + + return { + ...state, + selectedResult: nextSelectedResult, + }; + } default: return state; } -- cgit v1.1 From 778dfdc728a101fca9ece3a14e590d3b8e1d43e1 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Thu, 14 Dec 2017 12:32:07 +0100 Subject: Use id's instead of user objects --- src/client/react/reducers/search.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 6ef0f4d..cad491b 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -1,43 +1,42 @@ -/* global USERS */ import fuzzy from 'fuzzy'; +import users from '../users'; const DEFAULT_STATE = { input: '', results: [ - { type: 's', value: '18561' }, + 's/18562', ], selectedResult: null, isExactMatch: false, }; -function getSearchResults(query) { +function getSearchResults(allUsers, query) { if (query.trim() === '') { return []; } - const allResults = fuzzy.filter(query, USERS, { + const allResults = fuzzy.filter(query, allUsers, { extract: user => user.value, }); const firstResults = allResults.splice(0, 4); - const users = firstResults.map(result => result.original); + const userIds = firstResults.map(result => result.original.id); - return users; + return userIds; } const search = (state = DEFAULT_STATE, action) => { switch (action.type) { case 'SEARCH/INPUT_CHANGE': { - let results = getSearchResults(action.typedValue); + const results = getSearchResults(users.allUsers, action.typedValue); let selectedResult = null; let isExactMatch = false; // Is the typed value exactly the same as the first result? Then show the // appropiate icon instead of the generic search icon. - if ((results.length > 0) && (action.typedValue === results[0].value)) { + if ((results.length === 1) && (action.typedValue === users.byId[results[0]].value)) { [selectedResult] = results; isExactMatch = true; - results = results.splice(1); } return { @@ -51,6 +50,9 @@ const search = (state = DEFAULT_STATE, action) => { case 'SEARCH/CHANGE_SELECTED_RESULT': { const { results, isExactMatch } = state; + + if (isExactMatch) return state; + const prevSelectedResult = state.selectedResult; const prevSelectedResultIndex = results.indexOf(prevSelectedResult); let nextSelectedResultIndex = @@ -62,15 +64,11 @@ const search = (state = DEFAULT_STATE, action) => { nextSelectedResultIndex = -1; } - let nextSelectedResult = + const nextSelectedResult = nextSelectedResultIndex === -1 ? null : results[nextSelectedResultIndex]; - if (isExactMatch) { - nextSelectedResult = prevSelectedResult; - } - return { ...state, selectedResult: nextSelectedResult, -- cgit v1.1 From ebb7aaf5d62fea0d3b9ac0ceb7c8b3fa3578ba59 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Thu, 14 Dec 2017 12:47:02 +0100 Subject: Add an extra new line --- src/client/react/reducers/search.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index cad491b..29d0e5c 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -74,6 +74,7 @@ const search = (state = DEFAULT_STATE, action) => { selectedResult: nextSelectedResult, }; } + default: return state; } -- cgit v1.1 From bb5b3629445ed6a52c3a088dbc2dd08b7a326f8a Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Thu, 14 Dec 2017 16:24:10 +0100 Subject: Remove input value from redux --- src/client/react/reducers/search.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 29d0e5c..2a7e7a5 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -2,7 +2,6 @@ import fuzzy from 'fuzzy'; import users from '../users'; const DEFAULT_STATE = { - input: '', results: [ 's/18562', ], @@ -41,7 +40,6 @@ const search = (state = DEFAULT_STATE, action) => { return { ...state, - input: action.typedValue, results, selectedResult, isExactMatch, -- cgit v1.1 From f0c8cf0e79f003514fd65a70def5820205955a77 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Thu, 21 Dec 2017 12:06:41 +0100 Subject: Move to typescript --- src/client/react/reducers/search.js | 81 ------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 src/client/react/reducers/search.js (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js deleted file mode 100644 index 2a7e7a5..0000000 --- a/src/client/react/reducers/search.js +++ /dev/null @@ -1,81 +0,0 @@ -import fuzzy from 'fuzzy'; -import users from '../users'; - -const DEFAULT_STATE = { - results: [ - 's/18562', - ], - selectedResult: null, - isExactMatch: false, -}; - -function getSearchResults(allUsers, query) { - if (query.trim() === '') { - return []; - } - - const allResults = fuzzy.filter(query, allUsers, { - extract: user => user.value, - }); - - const firstResults = allResults.splice(0, 4); - const userIds = firstResults.map(result => result.original.id); - - return userIds; -} - -const search = (state = DEFAULT_STATE, action) => { - switch (action.type) { - case 'SEARCH/INPUT_CHANGE': { - const results = getSearchResults(users.allUsers, action.typedValue); - let selectedResult = null; - let isExactMatch = false; - - // Is the typed value exactly the same as the first result? Then show the - // appropiate icon instead of the generic search icon. - if ((results.length === 1) && (action.typedValue === users.byId[results[0]].value)) { - [selectedResult] = results; - isExactMatch = true; - } - - return { - ...state, - results, - selectedResult, - isExactMatch, - }; - } - - case 'SEARCH/CHANGE_SELECTED_RESULT': { - const { results, isExactMatch } = state; - - if (isExactMatch) return state; - - const prevSelectedResult = state.selectedResult; - const prevSelectedResultIndex = results.indexOf(prevSelectedResult); - let nextSelectedResultIndex = - prevSelectedResultIndex + action.relativeChange; - - if (nextSelectedResultIndex < -1) { - nextSelectedResultIndex = results.length - 1; - } else if (nextSelectedResultIndex > results.length - 1) { - nextSelectedResultIndex = -1; - } - - const nextSelectedResult = - nextSelectedResultIndex === -1 - ? null - : results[nextSelectedResultIndex]; - - return { - ...state, - selectedResult: nextSelectedResult, - }; - } - - default: - return state; - } -}; - -export default search; -- cgit v1.1 From 77dccd31b32ee0a9a53b2186bae231069c5ab152 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sat, 6 Jan 2018 12:11:19 +0100 Subject: Revert "Move to typescript" This reverts commit f0c8cf0e79f003514fd65a70def5820205955a77. --- src/client/react/reducers/search.js | 81 +++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/client/react/reducers/search.js (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js new file mode 100644 index 0000000..2a7e7a5 --- /dev/null +++ b/src/client/react/reducers/search.js @@ -0,0 +1,81 @@ +import fuzzy from 'fuzzy'; +import users from '../users'; + +const DEFAULT_STATE = { + results: [ + 's/18562', + ], + selectedResult: null, + isExactMatch: false, +}; + +function getSearchResults(allUsers, query) { + if (query.trim() === '') { + return []; + } + + const allResults = fuzzy.filter(query, allUsers, { + extract: user => user.value, + }); + + const firstResults = allResults.splice(0, 4); + const userIds = firstResults.map(result => result.original.id); + + return userIds; +} + +const search = (state = DEFAULT_STATE, action) => { + switch (action.type) { + case 'SEARCH/INPUT_CHANGE': { + const results = getSearchResults(users.allUsers, action.typedValue); + let selectedResult = null; + let isExactMatch = false; + + // Is the typed value exactly the same as the first result? Then show the + // appropiate icon instead of the generic search icon. + if ((results.length === 1) && (action.typedValue === users.byId[results[0]].value)) { + [selectedResult] = results; + isExactMatch = true; + } + + return { + ...state, + results, + selectedResult, + isExactMatch, + }; + } + + case 'SEARCH/CHANGE_SELECTED_RESULT': { + const { results, isExactMatch } = state; + + if (isExactMatch) return state; + + const prevSelectedResult = state.selectedResult; + const prevSelectedResultIndex = results.indexOf(prevSelectedResult); + let nextSelectedResultIndex = + prevSelectedResultIndex + action.relativeChange; + + if (nextSelectedResultIndex < -1) { + nextSelectedResultIndex = results.length - 1; + } else if (nextSelectedResultIndex > results.length - 1) { + nextSelectedResultIndex = -1; + } + + const nextSelectedResult = + nextSelectedResultIndex === -1 + ? null + : results[nextSelectedResultIndex]; + + return { + ...state, + selectedResult: nextSelectedResult, + }; + } + + default: + return state; + } +}; + +export default search; -- cgit v1.1 From 70a9b0be3782122750388c24eb98b0d45e6fc6d1 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sat, 6 Jan 2018 13:12:11 +0100 Subject: Save searchText in redux store --- src/client/react/reducers/search.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 2a7e7a5..6027ed7 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -5,6 +5,7 @@ const DEFAULT_STATE = { results: [ 's/18562', ], + searchText: '', selectedResult: null, isExactMatch: false, }; @@ -27,13 +28,14 @@ function getSearchResults(allUsers, query) { const search = (state = DEFAULT_STATE, action) => { switch (action.type) { case 'SEARCH/INPUT_CHANGE': { - const results = getSearchResults(users.allUsers, action.typedValue); + const { searchText } = action; + const results = getSearchResults(users.allUsers, action.searchText); let selectedResult = null; let isExactMatch = false; // Is the typed value exactly the same as the first result? Then show the // appropiate icon instead of the generic search icon. - if ((results.length === 1) && (action.typedValue === users.byId[results[0]].value)) { + if ((results.length === 1) && (action.searchText === users.byId[results[0]].value)) { [selectedResult] = results; isExactMatch = true; } @@ -41,6 +43,7 @@ const search = (state = DEFAULT_STATE, action) => { return { ...state, results, + searchText, selectedResult, isExactMatch, }; -- cgit v1.1 From c0aa588bc8f85b13b5a55ccd6cdf11bf99048a1c Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Sat, 6 Jan 2018 15:42:04 +0100 Subject: Add user page --- src/client/react/reducers/search.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 6027ed7..7c7e917 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -27,6 +27,22 @@ function getSearchResults(allUsers, query) { const search = (state = DEFAULT_STATE, action) => { switch (action.type) { + case 'SEARCH/SET_USER': { + const { user } = action; + + if (user == null) { + return DEFAULT_STATE; + } + + return { + ...state, + results: [], + searchText: users.byId[user].value, + selectedResult: user, + isExactMatch: true, + }; + } + case 'SEARCH/INPUT_CHANGE': { const { searchText } = action; const results = getSearchResults(users.allUsers, action.searchText); @@ -82,3 +98,7 @@ const search = (state = DEFAULT_STATE, action) => { }; export default search; + +export const _test = { + DEFAULT_STATE, +}; -- cgit v1.1 From 71c95bb19be0446bab80abffd9d4fc563374def3 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Wed, 17 Jan 2018 16:47:23 +0100 Subject: Fix typo --- src/client/react/reducers/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 7c7e917..2274a33 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -50,7 +50,7 @@ const search = (state = DEFAULT_STATE, action) => { let isExactMatch = false; // Is the typed value exactly the same as the first result? Then show the - // appropiate icon instead of the generic search icon. + // appropriate icon instead of the generic search icon. if ((results.length === 1) && (action.searchText === users.byId[results[0]].value)) { [selectedResult] = results; isExactMatch = true; -- cgit v1.1 From 0bddf7661d7ece709a18f2d167b928749638f318 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Wed, 24 Jan 2018 15:44:31 +0100 Subject: Add animation to results --- src/client/react/reducers/search.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/client/react/reducers/search.js') diff --git a/src/client/react/reducers/search.js b/src/client/react/reducers/search.js index 2274a33..770cdcb 100644 --- a/src/client/react/reducers/search.js +++ b/src/client/react/reducers/search.js @@ -2,9 +2,10 @@ import fuzzy from 'fuzzy'; import users from '../users'; const DEFAULT_STATE = { - results: [ - 's/18562', - ], + // results: [ + // 's/18562', + // ], + results: [], searchText: '', selectedResult: null, isExactMatch: false, -- cgit v1.1