Add debouncing and axios cache interceptor

This commit is contained in:
Georges-Antoine Assi
2023-06-08 20:46:58 -04:00
parent 3fea169f58
commit 5b4656ebd8
4 changed files with 54 additions and 16 deletions

View File

@@ -10,6 +10,7 @@
"dependencies": {
"@mdi/font": "7.0.96",
"axios": "^1.3.4",
"axios-cache-interceptor": "^1.1.1",
"core-js": "^3.8.3",
"file-saver": "^2.0.5",
"jszip": "^3.10.1",
@@ -2441,6 +2442,25 @@
"proxy-from-env": "^1.1.0"
}
},
"node_modules/axios-cache-interceptor": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/axios-cache-interceptor/-/axios-cache-interceptor-1.1.1.tgz",
"integrity": "sha512-FX2fGHECGE8bhFs4cLZ9FSu1oG4zRoDLKuw2FaYmZCHyrGeg703h751rFD01ICWm3WYb+3/BwrYsv5HOICO2AA==",
"dependencies": {
"cache-parser": "^1.2.4",
"fast-defer": "^1.1.7",
"object-code": "^1.2.4"
},
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/arthurfiorette/axios-cache-interceptor?sponsor=1"
},
"peerDependencies": {
"axios": "^1"
}
},
"node_modules/babel-plugin-polyfill-corejs2": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.3.3.tgz",
@@ -2578,6 +2598,11 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/cache-parser": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/cache-parser/-/cache-parser-1.2.4.tgz",
"integrity": "sha512-O0KwuHuJnbHUrghHi2kGp0SxnWSIBXTYt7M8WVhW0kbPRUNUKoE/Of6e1rRD6AAxmfxFunKnt90yEK09D+sc5g=="
},
"node_modules/call-bind": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
@@ -3556,6 +3581,11 @@
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
"dev": true
},
"node_modules/fast-defer": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/fast-defer/-/fast-defer-1.1.7.tgz",
"integrity": "sha512-tJ01ulDWT2WhqxMKS20nXX6wyX2iInBYpbN3GO7yjKwXMY4qvkdBRxak9IFwBLlFDESox+SwSvqMCZDfe1tqeg=="
},
"node_modules/fast-glob": {
"version": "3.2.12",
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz",
@@ -4770,6 +4800,11 @@
"url": "https://github.com/fb55/nth-check?sponsor=1"
}
},
"node_modules/object-code": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/object-code/-/object-code-1.2.4.tgz",
"integrity": "sha512-uGq4ETUuWe+GA586NXEriiaozNuff+YNFXlpD8cVrM1GoiuTZpCABP+bZCWDrvQDoCiSTyiWAFHD/HF/iwhb2w=="
},
"node_modules/object-inspect": {
"version": "1.12.3",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz",

View File

@@ -11,6 +11,7 @@
"dependencies": {
"@mdi/font": "7.0.96",
"axios": "^1.3.4",
"axios-cache-interceptor": "^1.1.1",
"core-js": "^3.8.3",
"file-saver": "^2.0.5",
"jszip": "^3.10.1",

View File

@@ -1,17 +1,21 @@
import axios from "axios";
import Axios from "axios";
import { setupCache } from "axios-cache-interceptor";
const axios = setupCache(Axios); // axios instance with cache
export async function fetchPlatformsApi() {
return axios.get("/api/platforms");
}
export async function fetchRomsApi({ platform, cursor = "", size = 50, searchTerm = "" }) {
const params = new URLSearchParams([
["size", size],
["cursor", cursor],
["search_term", searchTerm],
]);
return axios.get(`/api/platforms/${platform}/roms`, { params });
export async function fetchRomsApi({
platform,
cursor = "",
size = 50,
searchTerm = "",
}) {
return axios.get(
`/api/platforms/${platform}/roms?cursor=${cursor}&size=${size}&search_term=${searchTerm}`
);
}
export async function fetchRomApi(platform, rom) {
@@ -31,11 +35,7 @@ export async function deleteRomApi(rom, deleteFromFs) {
}
export async function searchRomIGDBApi(searchTerm, searchBy, rom) {
const params = new URLSearchParams([
["search_term", searchTerm],
["search_by", searchBy],
["rom", rom],
]);
return axios.get("/api/search/roms/igdb", { params });
return axios.get(
`/api/search/roms/igdb/?search_term=${searchTerm}&search_by=${searchBy}&rom=${rom}`
);
}

View File

@@ -112,6 +112,8 @@ onMounted(async () => {
onBeforeRouteUpdate(async (to, _) => {
cursor.value = "";
roms.value = [];
filteredRoms.value = [];
fetchMoreRoms(to.params.platform);
});
</script>