From 1ca6ee251c26934fca358196f4d88ca1675d616f Mon Sep 17 00:00:00 2001 From: kant imam Date: Tue, 3 Nov 2020 20:39:30 +0100 Subject: [PATCH] fix(Search): fixed mobile keyboard not closing when a search suggestion is selected (#339) * fixed mobile keyboard not closing when a search suggestion is selected * Restyled by prettier (#340) Co-authored-by: Restyled.io * debug date reset, sorry for hijacking the PR * handle fetch error * use request mode no-cors for now * handle 404 as error * loggggg * try logging headers * try logging headers * remove logging * Restyled by prettier (#345) Co-authored-by: Restyled.io Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io Co-authored-by: Sebastian Herrlinger --- src/components/Search.tsx | 3 ++- src/state/thunks/fetchMappedSet.ts | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/Search.tsx b/src/components/Search.tsx index 8d4b52ba..54319313 100644 --- a/src/components/Search.tsx +++ b/src/components/Search.tsx @@ -104,9 +104,10 @@ export const Search = ({ className = "" }: { className?: string }) => { id: "autocomplete", options: possibilities.results.map((result) => result.name), getOptionLabel: (option) => option, - onChange: (evt, value) => { + onChange: (event, value) => { dispatch(switchViewToPlace(value)); }, + blurOnSelect: true, }); const handleSearch = (event) => { diff --git a/src/state/thunks/fetchMappedSet.ts b/src/state/thunks/fetchMappedSet.ts index 27eeb2ab..c5424854 100644 --- a/src/state/thunks/fetchMappedSet.ts +++ b/src/state/thunks/fetchMappedSet.ts @@ -16,11 +16,23 @@ const fetchAndTransform = async ( transform?: Function, ) => { let dataUrl = url; + let res; + if (typeof dataUrl === "function") { dataUrl = dataUrl(formattedDate, date); } - const res = await fetch(dataUrl as string); + try { + res = await fetch(dataUrl as string, { + mode: "no-cors", + }); + } catch (err) { + return null; + } + + if (res.status === 404) { + return undefined; + } if (res.status === 200) { let json = await res.json(); @@ -32,10 +44,6 @@ const fetchAndTransform = async ( return json; } - if (res.status === 404) { - return undefined; - } - return null; };