Skip to content

Commit

Permalink
more responsive gallery search with AbortController
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Dec 11, 2024
1 parent 836249a commit 2179de2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
6 changes: 5 additions & 1 deletion components/fullscreen-preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
alt="fullscreen preview"
:aspect-ratio="aspectRatio"
contain
@click="() => { modalOpened = false }"
@click="
() => {
modalOpened = false;
}
"
/>
</v-card>
</v-dialog>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@vitejs/plugin-vue2": "^2.3.3",
"axios": "^1.7.9",
"d3": "7.9.0",
"dompurify": "^3.2.2",
"dompurify": "^3.2.3",
"dotenv": "^16.4.7",
"marked": "~15.0.3",
"moment": "^2.30.1",
Expand Down
4 changes: 1 addition & 3 deletions pages/gallery/gallery-tooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
</div>
</div>
<div class="texture-tags-container">
<span class="encased" v-for="tag in texture.tags" :key="tag">
{{ `${tag}` }}
</span>
<span class="encased" v-for="tag in texture.tags" :key="tag">{{ tag }}</span>
</div>
</div>
</div>
Expand Down
23 changes: 13 additions & 10 deletions pages/gallery/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export default {
ignoredTextures: {},
// go to the top arrow
scrollY: 0,
abortController: new AbortController(),
};
},
methods: {
Expand Down Expand Up @@ -219,9 +220,11 @@ export default {
if (this.$route.path === route) return; // new search is the same as before
this.$router.push(route);
},
updateSearch() {
searchGallery() {
// prevent concurrency issues
if (this.loading) return;
if (this.loading) this.abortController.abort();
// cancel request and set loading true no matter what
this.abortController = new AbortController();
this.loading = true;
this.timer.start = Date.now();
this.textures = [];
Expand All @@ -232,17 +235,17 @@ export default {
// /gallery/{pack}/{edition}/{mc_version}/{tag}
axios
.get(url)
.get(url, { signal: this.abortController.signal })
.then((res) => {
this.textures = res.data;
this.timer.end = Date.now();
this.loading = false;
})
.catch((e) => {
console.error(e);
this.error = `${e.statusCode}: ${e.response.value}`;
})
.finally(() => {
// no matter what it's not loading anymore
.catch((err) => {
// new search started before old one finished, cancel
if (err.code === "ERR_CANCELED") return;
console.error(err);
this.error = `${err.statusCode}: ${err.response.value}`;
this.loading = false;
});
},
Expand Down Expand Up @@ -311,7 +314,7 @@ export default {
} else this.current.pack = params.pack;
// wait until version/edition watcher sync has been done
this.$nextTick(() => this.updateSearch());
this.$nextTick(() => this.searchGallery());
},
deep: true,
immediate: true,
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2179de2

Please sign in to comment.