From 9f910b667321466f469ed77364f6481d0ce6e9a4 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 21 Sep 2020 09:06:19 -0700 Subject: [PATCH] Add empty states * Default and empty state for `SearchModal` * Empty state for grid when shortcode is not in use --- src/components/SearchModal/SearchModal.css | 16 +++++++++ src/components/SearchModal/SearchModal.tsx | 40 ++++++++++++++++------ src/components/WeaponGrid/WeaponGrid.css | 12 +++++++ src/components/WeaponGrid/WeaponGrid.tsx | 22 ++++-------- 4 files changed, 65 insertions(+), 25 deletions(-) diff --git a/src/components/SearchModal/SearchModal.css b/src/components/SearchModal/SearchModal.css index 30f02471..e773d854 100644 --- a/src/components/SearchModal/SearchModal.css +++ b/src/components/SearchModal/SearchModal.css @@ -25,5 +25,21 @@ .SearchModal #results_container { margin: 0; + max-height: 320px; padding: 0 12px 12px 12px; +} + +.SearchModal #NoResults { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + flex-grow: 1; +} + +.SearchModal #NoResults h2 { + color: #ccc; + font-size: 18px; + font-weight: 500; + margin-top: -32px; } \ No newline at end of file diff --git a/src/components/SearchModal/SearchModal.tsx b/src/components/SearchModal/SearchModal.tsx index 0eee27ea..0aae7e34 100644 --- a/src/components/SearchModal/SearchModal.tsx +++ b/src/components/SearchModal/SearchModal.tsx @@ -80,21 +80,42 @@ class SearchModal extends React.Component { renderSearchResults = () => { const { results } = this.state + console.log(results) + return ( + + ) + } - if (results.length) { - return ( - - ) + renderEmptyState = () => { + let string = '' + + if (this.state.query === '') { + string = 'No weapons' + } else { + string = `No results found for '${this.state.query}'` } + + return ( +
+

{string}

+
+ ) } render() { const { query, loading } = this.state + let content: JSX.Element + if (Object.entries(this.state.results).length == 0) { + content = this.renderEmptyState() + } else { + content = this.renderSearchResults() + } + return ( createPortal(
@@ -115,8 +136,7 @@ class SearchModal extends React.Component {
- { this.renderSearchResults() } - + {content} , diff --git a/src/components/WeaponGrid/WeaponGrid.css b/src/components/WeaponGrid/WeaponGrid.css index ad176b84..206835fc 100644 --- a/src/components/WeaponGrid/WeaponGrid.css +++ b/src/components/WeaponGrid/WeaponGrid.css @@ -25,4 +25,16 @@ #grid_weapons > li { list-style: none; +} + +#NotFound { + display: flex; + flex-direction: column; + align-items: center; + margin-top: 40px; +} + +#NotFound h2 { + color: #444; + font-weight: 500; } \ No newline at end of file diff --git a/src/components/WeaponGrid/WeaponGrid.tsx b/src/components/WeaponGrid/WeaponGrid.tsx index ee8ca6c1..bf181711 100644 --- a/src/components/WeaponGrid/WeaponGrid.tsx +++ b/src/components/WeaponGrid/WeaponGrid.tsx @@ -34,27 +34,19 @@ const WeaponGrid = (props: Props) => { if (props.shortcode) { fetchGrid(props.shortcode) } else { - // There is no need to fetch a weapon + setIsValid(true) } }, []) function fetchGrid(shortcode: string) { return api.endpoints.parties.getOne({ id: shortcode }) .then(response => { - const grid = response.data.party.grid - - let weapons: GridArray = {} - grid.forEach((gridWeapon: GridWeapon) => { - if (gridWeapon.mainhand) { - setMainhand(gridWeapon.weapon) - } - - else if (!gridWeapon.mainhand && gridWeapon.position != null) { - weapons[gridWeapon.position] = gridWeapon.weapon - } - }) - - setWeapons(weapons) + setupGrid(response) + }) + .catch(error => { + if (error.response.status == 404) { + gridNotFound() + } }) }