mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 14:56:01 +00:00
load stores dierctly in roms store
This commit is contained in:
@@ -3,16 +3,12 @@ import type { Emitter } from "mitt";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { inject, watch, computed } from "vue";
|
||||
import { useDisplay } from "vuetify";
|
||||
import storeGalleryFilter from "@/stores/galleryFilter";
|
||||
import storeGalleryView from "@/stores/galleryView";
|
||||
import storePlatforms from "@/stores/platforms";
|
||||
import storeRoms from "@/stores/roms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
|
||||
const { smAndDown } = useDisplay();
|
||||
const romsStore = storeRoms();
|
||||
const platformsStore = storePlatforms();
|
||||
const galleryFilterStore = storeGalleryFilter();
|
||||
const galleryViewStore = storeGalleryView();
|
||||
const { selectedRoms } = storeToRefs(romsStore);
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
@@ -32,8 +28,6 @@ async function fetchRoms() {
|
||||
|
||||
romsStore
|
||||
.fetchRoms({
|
||||
galleryFilter: galleryFilterStore,
|
||||
platformsStore: platformsStore,
|
||||
concat: false,
|
||||
})
|
||||
.then(() => {
|
||||
|
||||
@@ -87,8 +87,6 @@ const onFilterChange = debounce(
|
||||
() => {
|
||||
romsStore.resetPagination();
|
||||
romsStore.fetchRoms({
|
||||
galleryFilter: galleryFilterStore,
|
||||
platformsStore: platformsStore,
|
||||
concat: false,
|
||||
});
|
||||
|
||||
|
||||
@@ -44,8 +44,6 @@ const onFilterChange = debounce(
|
||||
romsStore.resetPagination();
|
||||
galleryFilterStore.setFilterMissing(true);
|
||||
romsStore.fetchRoms({
|
||||
galleryFilter: galleryFilterStore,
|
||||
platformsStore: platformsStore,
|
||||
concat: false,
|
||||
});
|
||||
|
||||
@@ -75,10 +73,7 @@ async function fetchRoms() {
|
||||
|
||||
galleryFilterStore.setFilterMissing(true);
|
||||
romsStore
|
||||
.fetchRoms({
|
||||
galleryFilter: galleryFilterStore,
|
||||
platformsStore: platformsStore,
|
||||
})
|
||||
.fetchRoms({})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching missing games:", error);
|
||||
emitter?.emit("snackbarShow", {
|
||||
@@ -98,10 +93,7 @@ function cleanupAll() {
|
||||
romsStore.setLimit(10000);
|
||||
galleryFilterStore.setFilterMissing(true);
|
||||
romsStore
|
||||
.fetchRoms({
|
||||
galleryFilter: galleryFilterStore,
|
||||
platformsStore: platformsStore,
|
||||
})
|
||||
.fetchRoms({})
|
||||
.then(() => {
|
||||
emitter?.emit("showLoadingDialog", {
|
||||
loading: false,
|
||||
|
||||
@@ -136,10 +136,7 @@ function updateOptions({ sortBy }: { sortBy: SortBy }) {
|
||||
romsStore.resetPagination();
|
||||
romsStore.setOrderBy(key);
|
||||
romsStore.setOrderDir(order);
|
||||
romsStore.fetchRoms({
|
||||
galleryFilter: galleryFilterStore,
|
||||
platformsStore: platformsStore,
|
||||
});
|
||||
romsStore.fetchRoms({});
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -319,8 +319,6 @@ async function fetchRoms() {
|
||||
romsStore.resetPagination();
|
||||
|
||||
const fetchedRoms = await romsStore.fetchRoms({
|
||||
galleryFilter: galleryFilterStore,
|
||||
platformsStore: platformsStore,
|
||||
concat: false,
|
||||
});
|
||||
|
||||
|
||||
@@ -194,19 +194,18 @@ export default defineStore("roms", {
|
||||
}
|
||||
},
|
||||
async fetchRoms({
|
||||
galleryFilter,
|
||||
platformsStore,
|
||||
concat = true,
|
||||
}: {
|
||||
galleryFilter: GalleryFilterStore;
|
||||
platformsStore: PlatformsStore;
|
||||
concat?: boolean;
|
||||
}): Promise<SimpleRom[]> {
|
||||
if (this.fetchingRoms) return Promise.resolve([]);
|
||||
this.fetchingRoms = true;
|
||||
|
||||
const galleryFilterStore = storeGalleryFilter();
|
||||
const platformsStore = storePlatforms();
|
||||
|
||||
// Capture current request parameters to validate background updates
|
||||
const currentRequestParams = this._buildRequestParams(galleryFilter);
|
||||
const currentRequestParams = this._buildRequestParams(galleryFilterStore);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
cachedApiService
|
||||
@@ -214,14 +213,14 @@ export default defineStore("roms", {
|
||||
if (concat && this.fetchOffset != 0) return;
|
||||
|
||||
// Check if parameters have changed since the request was made
|
||||
const currentParams = this._buildRequestParams(galleryFilter);
|
||||
const currentParams = this._buildRequestParams(galleryFilterStore);
|
||||
const paramsChanged =
|
||||
JSON.stringify(currentParams) !==
|
||||
JSON.stringify(currentRequestParams);
|
||||
if (paramsChanged) return;
|
||||
this._postFetchRoms(
|
||||
response,
|
||||
galleryFilter,
|
||||
galleryFilterStore,
|
||||
platformsStore,
|
||||
concat,
|
||||
);
|
||||
@@ -229,7 +228,7 @@ export default defineStore("roms", {
|
||||
.then((response) => {
|
||||
this._postFetchRoms(
|
||||
response.data,
|
||||
galleryFilter,
|
||||
galleryFilterStore,
|
||||
platformsStore,
|
||||
concat,
|
||||
);
|
||||
|
||||
@@ -15,7 +15,6 @@ import GameTable from "@/components/common/Game/VirtualTable.vue";
|
||||
import { type CollectionType } from "@/stores/collections";
|
||||
import storeGalleryFilter from "@/stores/galleryFilter";
|
||||
import storeGalleryView from "@/stores/galleryView";
|
||||
import storePlatforms from "@/stores/platforms";
|
||||
import storeRoms, { type SimpleRom } from "@/stores/roms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import { views } from "@/utils";
|
||||
@@ -30,7 +29,6 @@ const galleryViewStore = storeGalleryView();
|
||||
const galleryFilterStore = storeGalleryFilter();
|
||||
const { scrolledToTop, currentView } = storeToRefs(galleryViewStore);
|
||||
const romsStore = storeRoms();
|
||||
const platformsStore = storePlatforms();
|
||||
const {
|
||||
filteredRoms,
|
||||
selectedRoms,
|
||||
@@ -55,10 +53,7 @@ async function fetchRoms() {
|
||||
});
|
||||
|
||||
romsStore
|
||||
.fetchRoms({
|
||||
galleryFilter: galleryFilterStore,
|
||||
platformsStore: platformsStore,
|
||||
})
|
||||
.fetchRoms({})
|
||||
.then(() => {
|
||||
emitter?.emit("showLoadingDialog", {
|
||||
loading: false,
|
||||
|
||||
@@ -48,10 +48,7 @@ async function fetchRoms() {
|
||||
});
|
||||
|
||||
romsStore
|
||||
.fetchRoms({
|
||||
galleryFilter: galleryFilterStore,
|
||||
platformsStore: platformsStore,
|
||||
})
|
||||
.fetchRoms({})
|
||||
.then(() => {
|
||||
emitter?.emit("showLoadingDialog", {
|
||||
loading: false,
|
||||
|
||||
@@ -13,7 +13,6 @@ import GameCard from "@/components/common/Game/Card/Base.vue";
|
||||
import GameTable from "@/components/common/Game/VirtualTable.vue";
|
||||
import storeGalleryFilter from "@/stores/galleryFilter";
|
||||
import storeGalleryView from "@/stores/galleryView";
|
||||
import storePlatforms from "@/stores/platforms";
|
||||
import storeRoms, { type SimpleRom } from "@/stores/roms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import { views } from "@/utils";
|
||||
@@ -23,7 +22,6 @@ const { scrolledToTop, currentView } = storeToRefs(galleryViewStore);
|
||||
const galleryFilterStore = storeGalleryFilter();
|
||||
const { searchTerm } = storeToRefs(galleryFilterStore);
|
||||
const romsStore = storeRoms();
|
||||
const platformsStore = storePlatforms();
|
||||
const {
|
||||
filteredRoms,
|
||||
selectedRoms,
|
||||
@@ -101,19 +99,14 @@ function onGameTouchEnd() {
|
||||
}
|
||||
|
||||
function fetchRoms() {
|
||||
romsStore
|
||||
.fetchRoms({
|
||||
galleryFilter: galleryFilterStore,
|
||||
platformsStore: platformsStore,
|
||||
})
|
||||
.catch((error) => {
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: `Couldn't fetch roms: ${error}`,
|
||||
icon: "mdi-close-circle",
|
||||
color: "red",
|
||||
timeout: 4000,
|
||||
});
|
||||
romsStore.fetchRoms({}).catch((error) => {
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: `Couldn't fetch roms: ${error}`,
|
||||
icon: "mdi-close-circle",
|
||||
color: "red",
|
||||
timeout: 4000,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const { y: windowY } = useScroll(window, { throttle: 500 });
|
||||
|
||||
Reference in New Issue
Block a user