diff --git a/web/src/giphy.js b/web/src/giphy.js index 35172bb..8e884d4 100644 --- a/web/src/giphy.js +++ b/web/src/giphy.js @@ -1,5 +1,6 @@ import {Component, html} from "../lib/htm/preact.js"; import * as widgetAPI from "./widget-api.js"; +import {Spinner} from "./spinner.js"; import {SearchBox} from "./search-box.js"; const GIPHY_SEARCH_DEBOUNCE = 1000 @@ -34,13 +35,14 @@ export class GiphySearchTab extends Component { async makeGifSearchRequest() { try { + this.setState({gifs: [], loading: true}) const resp = await fetch(`https://api.giphy.com/v1/gifs/search?q=${this.state.searchTerm}&api_key=${GIPHY_API_KEY}`) // TODO handle error responses properly? const data = await resp.json() if (data.data.length === 0) { - this.setState({gifs: [], error: "No results"}) + this.setState({gifs: [], error: "No results", loading: false}) } else { - this.setState({gifs: data.data, error: null}) + this.setState({gifs: data.data, error: null, loading: false}) } } catch (error) { this.setState({error}) @@ -82,24 +84,27 @@ export class GiphySearchTab extends Component { } render() { - // TODO display loading state? return html` <${SearchBox} onInput=${this.updateGifSearchQuery} onKeyUp=${this.searchKeyUp} value=${this.state.searchTerm} placeholder="Find GIFs"/>