Add empty states
* Default and empty state for `SearchModal` * Empty state for grid when shortcode is not in use
This commit is contained in:
parent
d3d437235f
commit
9f910b6673
4 changed files with 65 additions and 25 deletions
|
|
@ -25,5 +25,21 @@
|
||||||
|
|
||||||
.SearchModal #results_container {
|
.SearchModal #results_container {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
max-height: 320px;
|
||||||
padding: 0 12px 12px 12px;
|
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;
|
||||||
|
}
|
||||||
|
|
@ -80,21 +80,42 @@ class SearchModal extends React.Component<Props, State> {
|
||||||
|
|
||||||
renderSearchResults = () => {
|
renderSearchResults = () => {
|
||||||
const { results } = this.state
|
const { results } = this.state
|
||||||
|
console.log(results)
|
||||||
|
return (
|
||||||
|
<ul id="results_container">
|
||||||
|
{ results.map( (result: Weapon) => {
|
||||||
|
return <WeaponResult key={result.id} data={result} onClick={() => { this.sendData(result) }} />
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (results.length) {
|
renderEmptyState = () => {
|
||||||
return (
|
let string = ''
|
||||||
<ul id="results_container">
|
|
||||||
{ results.map( (result: Weapon) => {
|
if (this.state.query === '') {
|
||||||
return <WeaponResult key={result.id} data={result} onClick={() => { this.sendData(result) }} />
|
string = 'No weapons'
|
||||||
})}
|
} else {
|
||||||
</ul>
|
string = `No results found for '${this.state.query}'`
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div id="NoResults">
|
||||||
|
<h2>{string}</h2>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { query, loading } = this.state
|
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 (
|
return (
|
||||||
createPortal(
|
createPortal(
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -115,8 +136,7 @@ class SearchModal extends React.Component<Props, State> {
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{ this.renderSearchResults() }
|
{content}
|
||||||
|
|
||||||
</Modal>
|
</Modal>
|
||||||
<Overlay onClick={this.props.close} />
|
<Overlay onClick={this.props.close} />
|
||||||
</div>,
|
</div>,
|
||||||
|
|
|
||||||
|
|
@ -26,3 +26,15 @@
|
||||||
#grid_weapons > li {
|
#grid_weapons > li {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#NotFound {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
margin-top: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#NotFound h2 {
|
||||||
|
color: #444;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
@ -34,27 +34,19 @@ const WeaponGrid = (props: Props) => {
|
||||||
if (props.shortcode) {
|
if (props.shortcode) {
|
||||||
fetchGrid(props.shortcode)
|
fetchGrid(props.shortcode)
|
||||||
} else {
|
} else {
|
||||||
// There is no need to fetch a weapon
|
setIsValid(true)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
function fetchGrid(shortcode: string) {
|
function fetchGrid(shortcode: string) {
|
||||||
return api.endpoints.parties.getOne({ id: shortcode })
|
return api.endpoints.parties.getOne({ id: shortcode })
|
||||||
.then(response => {
|
.then(response => {
|
||||||
const grid = response.data.party.grid
|
setupGrid(response)
|
||||||
|
})
|
||||||
let weapons: GridArray = {}
|
.catch(error => {
|
||||||
grid.forEach((gridWeapon: GridWeapon) => {
|
if (error.response.status == 404) {
|
||||||
if (gridWeapon.mainhand) {
|
gridNotFound()
|
||||||
setMainhand(gridWeapon.weapon)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
else if (!gridWeapon.mainhand && gridWeapon.position != null) {
|
|
||||||
weapons[gridWeapon.position] = gridWeapon.weapon
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
setWeapons(weapons)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue