diff --git a/web/res/reset.svg b/web/res/reset.svg
new file mode 100644
index 0000000..be0a47f
--- /dev/null
+++ b/web/res/reset.svg
@@ -0,0 +1 @@
+
diff --git a/web/src/index.js b/web/src/index.js
index a215c46..46d9bf6 100644
--- a/web/src/index.js
+++ b/web/src/index.js
@@ -41,10 +41,7 @@ const supportedThemes = ["light", "dark", "black"]
const defaultState = {
packs: [],
- filtering: {
- searchTerm: "",
- packs: [],
- },
+ searchTerm: null,
}
class App extends Component {
@@ -52,7 +49,7 @@ class App extends Component {
super(props)
this.defaultTheme = params.get("theme")
this.state = {
- packs: defaultState.packs,
+ ...defaultState,
loading: true,
error: null,
stickersPerRow: parseInt(localStorage.mauStickersPerRow || "4"),
@@ -63,7 +60,6 @@ class App extends Component {
stickerIDs: frequent.get(),
stickers: [],
},
- filtering: defaultState.filtering,
}
if (!supportedThemes.includes(this.state.theme)) {
this.state.theme = "light"
@@ -77,6 +73,7 @@ class App extends Component {
this.packListRef = null
this.navRef = null
this.searchStickers = this.searchStickers.bind(this)
+ this.resetSearch = this.resetSearch.bind(this)
this.sendSticker = this.sendSticker.bind(this)
this.navScroll = this.navScroll.bind(this)
this.reloadPacks = this.reloadPacks.bind(this)
@@ -101,7 +98,18 @@ class App extends Component {
localStorage.mauFrequentlyUsedStickerCache = JSON.stringify(stickers.map(sticker => [sticker.id, sticker]))
}
+ // Search
+
+ resetSearch() {
+ this.setState({ searchTerm: defaultState.searchTerm })
+ }
+
searchStickers(e) {
+ if (e.key === "Escape") {
+ this.resetSearch()
+ return
+ }
+
const sanitizeString = s => s.toLowerCase().trim()
const searchTerm = sanitizeString(e.target.value)
@@ -115,11 +123,8 @@ class App extends Component {
}))
this.setState({
- filtering: {
- ...this.state.filtering,
- searchTerm,
- packs: packsWithFilteredStickers.filter(({ stickers }) => !!stickers.length),
- },
+ filteredPacks: packsWithFilteredStickers.filter(({ stickers }) => !!stickers.length),
+ searchTerm,
})
}
@@ -145,10 +150,8 @@ class App extends Component {
reloadPacks() {
this.imageObserver.disconnect()
this.sectionObserver.disconnect()
- this.setState({
- packs: defaultState.packs,
- filtering: defaultState.filtering,
- })
+ this.setState({ packs: defaultState.packs })
+ this.resetSearch()
this._loadPacks(true)
}
@@ -258,6 +261,7 @@ class App extends Component {
const sticker = this.stickersByID.get(id)
frequent.add(id)
this.updateFrequentlyUsed()
+ this.resetSearch()
widgetAPI.sendSticker(sticker)
}
@@ -267,8 +271,8 @@ class App extends Component {
render() {
const theme = `theme-${this.state.theme}`
- const filterActive = !!this.state.filtering.searchTerm
- const packs = filterActive ? this.state.filtering.packs : [this.state.frequentlyUsed, ...this.state.packs]
+ const filterActive = !!this.state.searchTerm
+ const packs = filterActive ? this.state.filteredPacks : [this.state.frequentlyUsed, ...this.state.packs]
if (this.state.loading) {
return html`