aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2020-09-10 15:41:09 +0300
committerTulir Asokan <tulir@maunium.net>2020-09-10 15:41:09 +0300
commit05a6e046c2fd67fe5b55260a946b017bddff1880 (patch)
tree281118a949b1b11e4e6ba50c04199a439ef27cce
parent3045faaed89118a9bbf38a6370416839c5c42a2e (diff)
Only reload packs instead of whole page
-rw-r--r--web/index.js29
1 files changed, 21 insertions, 8 deletions
diff --git a/web/index.js b/web/index.js
index 6a90d54..8cab2f0 100644
--- a/web/index.js
+++ b/web/index.js
@@ -41,6 +41,7 @@ class App extends Component {
this.navRef = null
this.sendSticker = this.sendSticker.bind(this)
this.navScroll = this.navScroll.bind(this)
+ this.reloadPacks = this.reloadPacks.bind(this)
}
_getStickersByID(ids) {
@@ -60,8 +61,16 @@ class App extends Component {
localStorage.mauFrequentlyUsedStickerCache = JSON.stringify(stickers.map(sticker => [sticker.id, sticker]))
}
- componentDidMount() {
- fetch(`${PACKS_BASE_URL}/index.json`).then(async indexRes => {
+ reloadPacks() {
+ this.imageObserver.disconnect()
+ this.sectionObserver.disconnect()
+ this.setState({ packs: [] })
+ this._loadPacks(true)
+ }
+
+ _loadPacks(disableCache = false) {
+ const cache = disableCache ? "no-cache" : undefined
+ fetch(`${PACKS_BASE_URL}/index.json`, { cache }).then(async indexRes => {
if (indexRes.status >= 400) {
this.setState({
loading: false,
@@ -73,7 +82,7 @@ class App extends Component {
HOMESERVER_URL = indexData.homeserver_url || HOMESERVER_URL
// TODO only load pack metadata when scrolled into view?
for (const packFile of indexData.packs) {
- const packRes = await fetch(`${PACKS_BASE_URL}/${packFile}`)
+ const packRes = await fetch(`${PACKS_BASE_URL}/${packFile}`, { cache })
const packData = await packRes.json()
for (const sticker of packData.stickers) {
this.stickersByID.set(sticker.id, sticker)
@@ -85,7 +94,10 @@ class App extends Component {
}
this.updateFrequentlyUsed()
}, error => this.setState({ loading: false, error }))
+ }
+ componentDidMount() {
+ this._loadPacks()
this.imageObserver = new IntersectionObserver(this.observeImageIntersections, {
rootMargin: "100px",
})
@@ -118,6 +130,9 @@ class App extends Component {
}
componentDidUpdate() {
+ if (this.packListRef === null) {
+ return
+ }
for (const elem of this.packListRef.getElementsByClassName("sticker")) {
this.imageObserver.observe(elem)
}
@@ -163,19 +178,17 @@ class App extends Component {
<div class="pack-list ${isMobileSafari ? "ios-safari-hack" : ""}" ref=${elem => this.packListRef = elem}>
<${Pack} pack=${this.state.frequentlyUsed} send=${this.sendSticker} />
${this.state.packs.map(pack => html`<${Pack} id=${pack.id} pack=${pack} send=${this.sendSticker} />`)}
- <${Settings} />
+ <${Settings} app=${this}/>
</div>
</main>`
}
}
-const reload = () => isMobileSafari ? (window.location.href = window.location.href) : window.location.reload()
-
-const Settings = () => html`
+const Settings = ({ app }) => html`
<section class="stickerpack settings" id="pack-settings" data-pack-id="settings">
<h1>Settings</h1>
<div class="settings-list">
- <button onClick=${reload}>Reload</button>
+ <button onClick=${app.reloadPacks}>Reload</button>
</div>
</section>
`
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage