|
|
@ -41,10 +41,7 @@ const supportedThemes = ["light", "dark", "black"] |
|
|
|
|
|
|
|
|
const defaultState = { |
|
|
const defaultState = { |
|
|
packs: [], |
|
|
packs: [], |
|
|
filtering: { |
|
|
|
|
|
searchTerm: "", |
|
|
|
|
|
packs: [], |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
searchTerm: null, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class App extends Component { |
|
|
class App extends Component { |
|
|
@ -52,7 +49,7 @@ class App extends Component { |
|
|
super(props) |
|
|
super(props) |
|
|
this.defaultTheme = params.get("theme") |
|
|
this.defaultTheme = params.get("theme") |
|
|
this.state = { |
|
|
this.state = { |
|
|
packs: defaultState.packs, |
|
|
|
|
|
|
|
|
...defaultState, |
|
|
loading: true, |
|
|
loading: true, |
|
|
error: null, |
|
|
error: null, |
|
|
stickersPerRow: parseInt(localStorage.mauStickersPerRow || "4"), |
|
|
stickersPerRow: parseInt(localStorage.mauStickersPerRow || "4"), |
|
|
@ -63,7 +60,6 @@ class App extends Component { |
|
|
stickerIDs: frequent.get(), |
|
|
stickerIDs: frequent.get(), |
|
|
stickers: [], |
|
|
stickers: [], |
|
|
}, |
|
|
}, |
|
|
filtering: defaultState.filtering, |
|
|
|
|
|
} |
|
|
} |
|
|
if (!supportedThemes.includes(this.state.theme)) { |
|
|
if (!supportedThemes.includes(this.state.theme)) { |
|
|
this.state.theme = "light" |
|
|
this.state.theme = "light" |
|
|
@ -77,6 +73,7 @@ class App extends Component { |
|
|
this.packListRef = null |
|
|
this.packListRef = null |
|
|
this.navRef = null |
|
|
this.navRef = null |
|
|
this.searchStickers = this.searchStickers.bind(this) |
|
|
this.searchStickers = this.searchStickers.bind(this) |
|
|
|
|
|
this.resetSearch = this.resetSearch.bind(this) |
|
|
this.sendSticker = this.sendSticker.bind(this) |
|
|
this.sendSticker = this.sendSticker.bind(this) |
|
|
this.navScroll = this.navScroll.bind(this) |
|
|
this.navScroll = this.navScroll.bind(this) |
|
|
this.reloadPacks = this.reloadPacks.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])) |
|
|
localStorage.mauFrequentlyUsedStickerCache = JSON.stringify(stickers.map(sticker => [sticker.id, sticker])) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Search
|
|
|
|
|
|
|
|
|
|
|
|
resetSearch() { |
|
|
|
|
|
this.setState({ searchTerm: defaultState.searchTerm }) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
searchStickers(e) { |
|
|
searchStickers(e) { |
|
|
|
|
|
if (e.key === "Escape") { |
|
|
|
|
|
this.resetSearch() |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const sanitizeString = s => s.toLowerCase().trim() |
|
|
const sanitizeString = s => s.toLowerCase().trim() |
|
|
const searchTerm = sanitizeString(e.target.value) |
|
|
const searchTerm = sanitizeString(e.target.value) |
|
|
|
|
|
|
|
|
@ -115,11 +123,8 @@ class App extends Component { |
|
|
})) |
|
|
})) |
|
|
|
|
|
|
|
|
this.setState({ |
|
|
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() { |
|
|
reloadPacks() { |
|
|
this.imageObserver.disconnect() |
|
|
this.imageObserver.disconnect() |
|
|
this.sectionObserver.disconnect() |
|
|
this.sectionObserver.disconnect() |
|
|
this.setState({ |
|
|
|
|
|
packs: defaultState.packs, |
|
|
|
|
|
filtering: defaultState.filtering, |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
this.setState({ packs: defaultState.packs }) |
|
|
|
|
|
this.resetSearch() |
|
|
this._loadPacks(true) |
|
|
this._loadPacks(true) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -258,6 +261,7 @@ class App extends Component { |
|
|
const sticker = this.stickersByID.get(id) |
|
|
const sticker = this.stickersByID.get(id) |
|
|
frequent.add(id) |
|
|
frequent.add(id) |
|
|
this.updateFrequentlyUsed() |
|
|
this.updateFrequentlyUsed() |
|
|
|
|
|
this.resetSearch() |
|
|
widgetAPI.sendSticker(sticker) |
|
|
widgetAPI.sendSticker(sticker) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -267,8 +271,8 @@ class App extends Component { |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|
const theme = `theme-${this.state.theme}` |
|
|
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) { |
|
|
if (this.state.loading) { |
|
|
return html`<main class="spinner ${theme}"><${Spinner} size=${80} green /></main>` |
|
|
return html`<main class="spinner ${theme}"><${Spinner} size=${80} green /></main>` |
|
|
@ -287,7 +291,7 @@ class App extends Component { |
|
|
${this.state.packs.map(pack => html`<${NavBarItem} id=${pack.id} pack=${pack}/>`)} |
|
|
${this.state.packs.map(pack => html`<${NavBarItem} id=${pack.id} pack=${pack}/>`)} |
|
|
<${NavBarItem} pack=${{ id: "settings", title: "Settings" }} iconOverride="settings" /> |
|
|
<${NavBarItem} pack=${{ id: "settings", title: "Settings" }} iconOverride="settings" /> |
|
|
</nav> |
|
|
</nav> |
|
|
<${SearchBox} onKeyUp=${this.searchStickers} /> |
|
|
|
|
|
|
|
|
<${SearchBox} onKeyUp=${this.searchStickers} resetSearch=${this.resetSearch} value=${this.state.searchTerm} /> |
|
|
<div class="pack-list ${isMobileSafari ? "ios-safari-hack" : ""}" ref=${elem => this.packListRef = elem}> |
|
|
<div class="pack-list ${isMobileSafari ? "ios-safari-hack" : ""}" ref=${elem => this.packListRef = elem}> |
|
|
${filterActive && packs.length === 0 ? html`<div class="search-empty"><h1>No stickers match your search</h1></div>` : null} |
|
|
${filterActive && packs.length === 0 ? html`<div class="search-empty"><h1>No stickers match your search</h1></div>` : null} |
|
|
${packs.map(pack => html`<${Pack} id=${pack.id} pack=${pack} send=${this.sendSticker} />`)} |
|
|
${packs.map(pack => html`<${Pack} id=${pack.id} pack=${pack} send=${this.sendSticker} />`)} |
|
|
|