working filters in gallery

This commit is contained in:
Zurdi
2024-02-05 20:54:52 +01:00
parent a3dbd3a26a
commit c4d95969c4
14 changed files with 382 additions and 242 deletions

View File

@@ -8,21 +8,20 @@ import socket from "@/services/socket";
import { onBeforeMount } from "vue";
import cookie from "js-cookie";
import storeGalleryFilter from "@/stores/galleryFilter";
import storePlatforms, { type Platform } from "@/stores/platforms";
import storeRoms from "@/stores/roms";
import storeScanning from "@/stores/scanning";
import type { Events } from "@/types/emitter";
import { normalizeString } from "@/utils";
import type { Emitter } from "mitt";
import { storeToRefs } from "pinia";
import { inject, onBeforeUnmount, ref } from "vue";
import { inject, onBeforeUnmount } from "vue";
// Props
const scanningStore = storeScanning();
const { scanningPlatforms } = storeToRefs(scanningStore);
const romsStore = storeRoms();
const galleryFilter = storeGalleryFilter();
const isFiltered = normalizeString(galleryFilter.filter).trim() != "";
const isFiltered = normalizeString(galleryFilter.filterSearch).trim() != "";
const emitter = inject<Emitter<Events>>("emitter");
// Props
@@ -39,30 +38,41 @@ socket.on("scan:scanning_platform", ({ name, slug, id }) => {
window.setTimeout(scrollToBottom, 100);
});
socket.on(
"scan:scanning_rom",
({ platform_name, platform_slug, ...rom }) => {
romsStore.add([rom]);
if (isFiltered) {
romsStore.setFiltered(romsStore.filteredRoms);
} else {
romsStore.setFiltered(romsStore.allRoms);
}
let scannedPlatform = scanningPlatforms.value.find(
(p) => p.slug === platform_slug
socket.on("scan:scanning_rom", ({ platform_name, platform_slug, ...rom }) => {
romsStore.add([rom]);
if (isFiltered) {
romsStore.setFiltered(
romsStore.filteredRoms,
galleryFilter.filterUnmatched,
galleryFilter.selectedGenre,
galleryFilter.selectedFranchise,
galleryFilter.selectedCollection,
galleryFilter.selectedCompany
);
} else {
romsStore.setFiltered(
romsStore.allRoms,
galleryFilter.filterUnmatched,
galleryFilter.selectedGenre,
galleryFilter.selectedFranchise,
galleryFilter.selectedCollection,
galleryFilter.selectedCompany
);
// Add the platform if the socket dropped and it's missing
if (scannedPlatform) {
scanningPlatforms.value.push(scannedPlatform);
scannedPlatform = scanningPlatforms.value.pop();
}
scannedPlatform?.roms.push(rom);
window.setTimeout(scrollToBottom, 100);
}
);
let scannedPlatform = scanningPlatforms.value.find(
(p) => p.slug === platform_slug
);
// Add the platform if the socket dropped and it's missing
if (scannedPlatform) {
scanningPlatforms.value.push(scannedPlatform);
scannedPlatform = scanningPlatforms.value.pop();
}
scannedPlatform?.roms.push(rom);
window.setTimeout(scrollToBottom, 100);
});
socket.on("scan:done", () => {
scanningStore.set(false);

View File

@@ -15,9 +15,8 @@ const auth = storeAuth();
<template>
<v-app-bar id="gallery-app-bar" elevation="0" density="compact">
<sort-btn />
<!-- <sort-btn /> -->
<filter-btn />
<filter-unmatched-btn />
<filter-text-field />
<gallery-view-btn />
<template v-if="auth.scopes.includes('roms.write')">
@@ -37,9 +36,10 @@ const auth = storeAuth();
</template>
</v-app-bar>
<sort-bar />
<v-expand-transition>
<sort-bar />
</v-expand-transition>
<v-expand-transition>
<filter-bar />
</v-expand-transition>
</template>

View File

@@ -1,22 +1,19 @@
<script setup lang="ts">
import { inject } from "vue";
import { useRoute } from "vue-router";
import type { Emitter } from "mitt";
import storeRoms from "@/stores/roms";
import type { Events } from "@/types/emitter";
import storePlatforms from "@/stores/platforms";
import type { Emitter } from "mitt";
import { inject } from "vue";
// Props
const platformsStore = storePlatforms();
const emitter = inject<Emitter<Events>>("emitter");
const route = useRoute();
const platform = platformsStore.get(Number(route.params.platform));
const romsStore = storeRoms();
</script>
<template>
<v-list-item
v-if="platform"
v-if="romsStore.platform"
class="py-4 pr-5 text-romm-red"
@click="emitter?.emit('showDeletePlatformDialog', platform)"
@click="emitter?.emit('showDeletePlatformDialog', romsStore.platform)"
>
<v-list-item-title class="d-flex">
<v-icon icon="mdi-delete" color="red" class="mr-2" />

View File

@@ -1,6 +1,9 @@
<script setup lang="ts">
import FilterUnmatchedBtn from "@/components/Gallery/AppBar/FilterUnmatchedBtn.vue";
import storeGalleryFilter from "@/stores/galleryFilter";
import type { Events } from "@/types/emitter";
import type { Emitter } from "mitt";
import { storeToRefs } from "pinia";
import { inject, ref } from "vue";
// Props
@@ -9,68 +12,70 @@ const emitter = inject<Emitter<Events>>("emitter");
emitter?.on("filterBarShow", () => {
showFilterBar.value = !showFilterBar.value;
});
emitter?.on("filterBarReset", () => {});
const galleryFilterStore = storeGalleryFilter();
const {
selectedGenre,
selectedFranchise,
selectedCollection,
selectedCompany,
} = storeToRefs(galleryFilterStore);
</script>
<template>
<v-expand-transition>
<div v-if="showFilterBar">
<v-row no-gutters class="pt-1 px-1">
<v-col cols="6" sm="" md="" lg="4" xl="3">
<v-select
hide-details
label="Genre"
density="compact"
variant="outlined"
class="ma-1"
></v-select>
</v-col>
<v-col cols="6" sm="" md="" lg="4" xl="3">
<v-select
hide-details
label="Publisher"
density="compact"
variant="outlined"
class="ma-1"
></v-select>
</v-col>
<v-col cols="6" sm="" md="" lg="4" xl="3">
<v-select
hide-details
label="Developer"
density="compact"
variant="outlined"
class="ma-1"
></v-select>
</v-col>
<v-col cols="6" sm="" md="" lg="4" xl="3">
<v-select
hide-details
label="Theme"
density="compact"
variant="outlined"
class="ma-1"
></v-select>
</v-col>
<v-col cols="6" sm="" md="" lg="4" xl="3">
<v-select
hide-details
label="Series"
density="compact"
variant="outlined"
class="ma-1"
></v-select>
</v-col>
<v-col cols="6" sm="" md="" lg="4" xl="3">
<v-select
hide-details
label="Franchises"
density="compact"
variant="outlined"
class="ma-1"
></v-select>
</v-col>
</v-row>
<v-divider :thickness="2" class="mx-2 mt-1 border-opacity-25" color="romm-accent-1" />
</div>
</v-expand-transition>
<div v-if="showFilterBar">
<v-row no-gutters class="pa-1">
<filter-unmatched-btn />
<v-select
hide-details
clearable
label="Genre"
density="compact"
variant="outlined"
class="ma-1"
@update:model-value="emitter?.emit('filter', null);"
v-model="selectedGenre"
:items="galleryFilterStore.filterGenres"
></v-select>
<v-select
hide-details
clearable
label="Franchise"
density="compact"
variant="outlined"
class="ma-1"
@update:model-value="emitter?.emit('filter', null)"
v-model="selectedFranchise"
:items="galleryFilterStore.filterFranchises"
></v-select>
<v-select
hide-details
clearable
label="Collection"
density="compact"
variant="outlined"
class="ma-1"
@update:model-value="emitter?.emit('filter', null)"
v-model="selectedCollection"
:items="galleryFilterStore.filterCollections"
></v-select>
<v-select
hide-details
clearable
label="Company"
density="compact"
variant="outlined"
class="ma-1"
@update:model-value="emitter?.emit('filter', null)"
v-model="selectedCompany"
:items="galleryFilterStore.filterCompanies"
></v-select>
</v-row>
<v-divider
:thickness="2"
class="mx-2 border-opacity-25"
color="romm-accent-1"
/>
</div>
</template>

View File

@@ -1,39 +1,33 @@
<script setup lang="ts">
import storeGalleryFilter from "@/stores/galleryFilter";
import type { Events } from "@/types/emitter";
import { debounce } from "lodash";
import type { Emitter } from "mitt";
import { inject, onMounted, ref } from "vue";
import storeGalleryFilter from "@/stores/galleryFilter";
// Props
const galleryFilter = storeGalleryFilter();
const filterValue = ref("");
const filter = ref("");
// Event listeners bus
const emitter = inject<Emitter<Events>>("emitter");
function clearFilter() {
galleryFilter.set("");
emitter?.emit("filter", null);
}
// Functions
const filterRoms = debounce(() => {
galleryFilter.set(filterValue.value);
emitter?.emit("filter", null);
galleryFilter.setFilterSearch(filter?.value ?? "");
emitter?.emit('filter', null);
}, 500);
onMounted(() => {
filterValue.value = galleryFilter.filter;
filter.value = galleryFilter.filterSearch;
});
</script>
<template>
<v-text-field
prepend-inner-icon="mdi-filter-outline"
@click:clear="clearFilter"
@keyup="filterRoms"
v-model="filterValue"
@update:model-value="filterRoms"
v-model="filter"
label="Filter"
rounded="0"
hide-details

View File

@@ -1,20 +1,17 @@
<script setup lang="ts">
import storeRoms from "@/stores/roms";
import storeGalleryFilter from "@/stores/galleryFilter";
import { storeToRefs } from "pinia";
import type { Events } from "@/types/emitter";
import type { Emitter } from "mitt";
import { inject, ref } from "vue";
import { inject } from "vue";
// Props
const galleryFilterStore = storeGalleryFilter();
const { filterUnmatched } = storeToRefs(galleryFilterStore);
const emitter = inject<Emitter<Events>>("emitter");
const romsStore = storeRoms();
const isShowUnmatched = ref(false);
function showUnmatched() {
isShowUnmatched.value = !isShowUnmatched.value;
if (isShowUnmatched.value) {
romsStore.setFilteredUnmatched();
} else {
emitter?.emit("filter", null);
}
function setUnmatched(){
galleryFilterStore.setFilterUnmatched()
emitter?.emit('filter', null);
}
</script>
@@ -27,14 +24,16 @@ function showUnmatched() {
open-delay="1000"
><template v-slot:activator="{ props }">
<v-btn
rounded="0"
variant="text"
class="ml-0"
:color="isShowUnmatched ? 'romm-accent-1' : ''"
icon="mdi-file-find-outline"
class="ma-1"
variant="outlined"
size="compact"
:color="filterUnmatched ? 'romm-accent-1' : 'romm-gray'"
v-bind="props"
@click="showUnmatched" /></template
></v-tooltip>
@click="setUnmatched()"
><v-icon class="mx-5">mdi-file-find-outline</v-icon></v-btn
></template
></v-tooltip
>
</template>
<style scoped>
.tooltip :deep(.v-overlay__content) {

View File

@@ -1,33 +1,11 @@
<script setup lang="ts">
import socket from "@/services/socket";
import storeGalleryFilter from "@/stores/galleryFilter";
import storePlatforms from "@/stores/platforms";
import storeRoms from "@/stores/roms";
import storeScanning from "@/stores/scanning";
import type { Events } from "@/types/emitter";
import { normalizeString } from "@/utils";
import type { Emitter } from "mitt";
import { inject, onBeforeUnmount } from "vue";
import { useRoute } from "vue-router";
// Props
const emitter = inject<Emitter<Events>>("emitter");
const platformsStore = storePlatforms();
const route = useRoute();
const platform = platformsStore.get(Number(route.params.platform));
const scanningStore = storeScanning();
const romsStore = storeRoms();
const galleryFilter = storeGalleryFilter();
const isFiltered = normalizeString(galleryFilter.filter).trim() != "";
// socket.on("scan:scanning_rom", ({ ...rom }) => {
// romsStore.add([rom]);
// if (isFiltered) {
// romsStore.setFiltered(romsStore.filteredRoms);
// } else {
// romsStore.setFiltered(romsStore.allRoms);
// }
// });
async function scan() {
scanningStore.set(true);
@@ -35,20 +13,14 @@ async function scan() {
if (!socket.connected) socket.connect();
socket.emit("scan", {
platforms: [platform?.id],
platforms: [romsStore.platform.id],
completeRescan: false,
});
}
// onBeforeUnmount(() => {
// socket.off("scan:scanning_rom_s");
// socket.off("scan:done_s");
// socket.off("scan:done_ko_s");
// });
</script>
<template>
<v-list-item v-if="platform" @click="scan" class="py-4 pr-5">
<v-list-item v-if="romsStore.platform" @click="scan" class="py-4 pr-5">
<v-list-item-title class="d-flex"
><v-icon icon="mdi-magnify-scan" class="mr-2" />Scan
platform</v-list-item-title

View File

@@ -1,21 +1,25 @@
<script setup lang="ts">
import storeRoms from "@/stores/roms";
import type { Events } from "@/types/emitter";
import type { Emitter } from "mitt";
import { inject, ref } from "vue";
// Props
const showSortBar = ref(false);
const romsStore = storeRoms();
const emitter = inject<Emitter<Events>>("emitter");
emitter?.on("sortBarShow", () => {
showSortBar.value = !showSortBar.value;
});
const sortBy = ["IGDB rating", "Release date"];
const sorted = ref([]);
function sort() {}
</script>
<template>
<v-expand-transition>
<div v-if="showSortBar">
<v-row no-gutters class="pt-1 px-1">
<v-col cols="6" sm="6" md="6" lg="6" xl="6">
<div v-if="showSortBar">
<v-row no-gutters class="pt-1 px-1">
<!-- <v-col cols="6" sm="6" md="6" lg="6" xl="6">
<v-select
hide-details
label="Release date"
@@ -32,9 +36,26 @@ emitter?.on("sortBarShow", () => {
variant="outlined"
class="pa-1"
></v-select>
</v-col>
</v-row>
<v-divider :thickness="2" class="mx-2 mt-1 border-opacity-25" color="romm-accent-1" />
</div>
</v-expand-transition>
</v-col> -->
<v-col>
<v-select
hide-details
label="Order by"
density="compact"
variant="outlined"
class="pa-1"
multiple
chips
:items="sortBy"
:model="sorted"
@update:model-value="sort"
></v-select>
</v-col>
</v-row>
<v-divider
:thickness="2"
class="mx-2 mt-1 border-opacity-25"
color="romm-accent-1"
/>
</div>
</template>

View File

@@ -1,21 +1,18 @@
<script setup lang="ts">
import { inject } from "vue";
import { useRoute } from "vue-router";
import type { Emitter } from "mitt";
import type { Events } from "@/types/emitter";
import storePlatforms from "@/stores/platforms";
import storeRoms from "@/stores/roms";
// Props
const platformsStore = storePlatforms();
const emitter = inject<Emitter<Events>>("emitter");
const route = useRoute();
const platform = platformsStore.get(Number(route.params.platform));
const romsStore = storeRoms();
</script>
<template>
<v-list-item
v-if="platform"
@click="emitter?.emit('showUploadRomDialog', platform)"
v-if="romsStore.platform"
@click="emitter?.emit('showUploadRomDialog', romsStore.platform)"
class="py-4 pr-5"
>
<v-list-item-title class="d-flex"

View File

@@ -2,11 +2,68 @@ import { defineStore } from "pinia";
import { normalizeString } from "@/utils";
export default defineStore("galleryFilter", {
state: () => ({ filter: "" }),
state: () => ({
filterSearch: "",
filterGenres: [] as string[],
filterFranchises: [] as string[],
filterCollections: [] as string[],
filterCompanies: [] as string[],
filterUnmatched: false,
selectedGenre: null as string | null,
selectedFranchise: null as string | null,
selectedCollection: null as string | null,
selectedCompany: null as string | null,
}),
actions: {
set(filter: string) {
this.filter = normalizeString(filter);
setFilterSearch(filterSearch: string) {
this.filterSearch = normalizeString(filterSearch);
},
setFilterGenre(genres: string[]) {
this.filterGenres = genres;
},
setFilterFranchise(franchises: string[]) {
this.filterFranchises = franchises;
},
setFilterCollection(collections: string[]) {
this.filterCollections = collections;
},
setFilterCompany(companies: string[]) {
this.filterCompanies = companies;
},
setSelectedGenre(genre: string) {
this.selectedGenre = genre;
},
setSelectedFilterFranchise(franchise: string) {
this.selectedFranchise = franchise;
},
setSelectedFilterCollection(collection: string) {
this.selectedCollection = collection;
},
setSelectedFilterCompany(company: string) {
this.selectedCompany = company;
},
setFilterUnmatched() {
this.filterUnmatched = !this.filterUnmatched;
},
isFiltered() {
return (
normalizeString(this.filterSearch).trim() != "" ||
this.selectedGenre ||
this.filterFranchises ||
this.selectedCollection ||
this.selectedCompany
);
},
reset() {
this.filterGenres = [];
this.filterFranchises = [];
this.filterCollections = [];
this.filterCompanies = [];
this.selectedGenre = null;
this.selectedFranchise = null;
this.selectedCollection = null;
this.selectedCompany = null;
},
},
});

View File

@@ -1,8 +1,7 @@
import { uniqBy, groupBy, isNull } from "lodash";
import { defineStore } from "pinia";
import type { PlatformSchema, RomSchema } from "@/__generated__/";
import { groupBy, isNull, uniqBy } from "lodash";
import { nanoid } from "nanoid";
import type { RomSchema, PlatformSchema } from "@/__generated__/";
import { defineStore } from "pinia";
export type Rom = RomSchema & {
sibling_roms?: RomSchema[]; // Returned by the API
@@ -110,14 +109,70 @@ export default defineStore("roms", {
this.lastSelectedIndex = -1;
},
// Filtered roms
setFiltered(roms: Rom[]) {
setFiltered(
roms: Rom[],
filterUnmatched: boolean,
filterGenre: string | null = null,
filterFranchise: string | null = null,
filterCollection: string | null = null,
filterCompany: string | null = null
) {
this._filteredIDs = roms.map((rom) => rom.id);
if (filterUnmatched) {
this.filterUnmatched();
}
if (filterGenre) {
this.filterGenre(filterGenre);
}
if (filterFranchise) {
this.filterFranchise(filterFranchise);
}
if (filterCollection) {
this.filterCollection(filterCollection);
}
if (filterCompany) {
this.filterCompany(filterCompany);
}
},
setFilteredUnmatched() {
filterUnmatched() {
this._filteredIDs = this.filteredRoms
.filter((rom) => !rom.igdb_id)
.map((roms) => roms.id);
},
filterGenre(genreToFilter: string) {
this._filteredIDs = this.filteredRoms
.filter((rom) =>
rom.genres.some((genre) => genre.name === genreToFilter)
)
.map((rom) => rom.id);
},
filterFranchise(franchiseToFilter: string) {
this._filteredIDs = this.filteredRoms
.filter((rom) =>
rom.franchises.some(
(franchise) => franchise.name === franchiseToFilter
)
)
.map((rom) => rom.id);
},
filterCollection(collectionToFilter: string) {
this._filteredIDs = this.filteredRoms
.filter((rom) =>
rom.collections.some(
(collection) => collection.name === collectionToFilter
)
)
.map((rom) => rom.id);
},
filterCompany(companyToFilter: string) {
this._filteredIDs = this.filteredRoms
.filter((rom) =>
rom.companies.some(
(company) => company.company.name === companyToFilter
)
)
.map((rom) => rom.id);
},
// Search roms
setSearch(roms: Rom[]) {
this._searchIDs = roms.map((rom) => rom.id);

View File

@@ -63,6 +63,7 @@ export type Events = {
openFabMenu: boolean;
filter: null;
filterBarShow: null;
filterBarReset: null;
sortBarShow: null;
romUpdated: Rom;
};

View File

@@ -20,12 +20,12 @@ import { normalizeString, toTop, views } from "@/utils";
import type { Emitter } from "mitt";
import { storeToRefs } from "pinia";
import { inject, onBeforeUnmount, onMounted, ref } from "vue";
import { onBeforeRouteLeave, onBeforeRouteUpdate, useRoute } from "vue-router";
import { onBeforeRouteUpdate, useRoute } from "vue-router";
// Props
const route = useRoute();
const galleryView = storeGalleryView();
const galleryFilter = storeGalleryFilter();
const galleryViewStore = storeGalleryView();
const galleryFilterStore = storeGalleryFilter();
const gettingRoms = ref(false);
const fabMenu = ref(false);
const scrolledToTop = ref(true);
@@ -49,12 +49,9 @@ emitter?.on("openFabMenu", (open) => {
// Functions
async function fetchRoms() {
console.log(`Fetginh roms from: ${platform.value.name}`);
const isFiltered = normalizeString(galleryFilter.filter).trim() != "";
if (
(searchCursor.value === null && isFiltered) ||
(cursor.value === null && !isFiltered) ||
(searchCursor.value === null && galleryFilterStore.isFiltered()) ||
(cursor.value === null && !galleryFilterStore.isFiltered()) ||
gettingRoms.value
)
return;
@@ -68,21 +65,37 @@ async function fetchRoms() {
await romApi
.getRoms({
platformId: platform.value.id,
cursor: isFiltered ? searchCursor.value : cursor.value,
searchTerm: normalizeString(galleryFilter.filter),
cursor: galleryFilterStore.isFiltered()
? searchCursor.value
: cursor.value,
searchTerm: normalizeString(galleryFilterStore.filterSearch),
})
.then(({ data }) => {
// Add any new roms to the store
const allRomsSet = [...allRoms.value, ...data.items];
romsStore.set(allRomsSet);
romsStore.setFiltered(allRomsSet);
romsStore.setFiltered(
allRomsSet,
galleryFilterStore.filterUnmatched,
galleryFilterStore.selectedGenre,
galleryFilterStore.selectedFranchise,
galleryFilterStore.selectedCollection,
galleryFilterStore.selectedCompany
);
if (isFiltered) {
if (galleryFilterStore.isFiltered()) {
if (data.next_page !== undefined) searchCursor.value = data.next_page;
const serchedRomsSet = [...searchRoms.value, ...data.items];
romsStore.setSearch(serchedRomsSet);
romsStore.setFiltered(serchedRomsSet);
romsStore.setFiltered(
serchedRomsSet,
galleryFilterStore.filterUnmatched,
galleryFilterStore.selectedGenre,
galleryFilterStore.selectedFranchise,
galleryFilterStore.selectedCollection,
galleryFilterStore.selectedCompany
);
} else if (data.next_page !== undefined) {
cursor.value = data.next_page;
}
@@ -105,19 +118,25 @@ async function fetchRoms() {
});
}
function onFilterChange() {
async function onFilterChange() {
searchCursor.value = "";
romsStore.setSearch([]);
if (galleryFilter.filter === "") {
romsStore.setFiltered(allRoms.value);
if (!galleryFilterStore.isFiltered()) {
romsStore.setFiltered(
allRoms.value,
galleryFilterStore.filterUnmatched,
galleryFilterStore.selectedGenre,
galleryFilterStore.selectedFranchise,
galleryFilterStore.selectedCollection,
galleryFilterStore.selectedCompany
);
return;
}
fetchRoms(Number(route.params.platform));
await fetchRoms();
}
function onScroll() {
async function onScroll() {
// Fetch more roms if near to bottom page
const { scrollTop, scrollHeight, clientHeight } = document.documentElement;
scrolledToTop.value = scrollTop === 0;
@@ -125,11 +144,13 @@ function onScroll() {
const scrollOffset = 60;
if (scrollTop + clientHeight + scrollOffset >= scrollHeight) {
fetchRoms(Number(route.params.platform));
await fetchRoms();
setFilters();
}
}
function selectRom({ event, index, selected }: RomSelectEvent) {
// Add rom to selected roms
if (event.shiftKey) {
const [start, end] = [romsStore.lastSelectedIndex, index].sort(
(a, b) => a - b
@@ -149,11 +170,43 @@ function selectRom({ event, index, selected }: RomSelectEvent) {
}
}
function setFilters() {
galleryFilterStore.setFilterGenre([
...new Set(
romsStore.filteredRoms
.flatMap((rom) => rom.genres.map((genre) => genre.name))
.sort()
),
]);
galleryFilterStore.setFilterFranchise([
...new Set(
romsStore.filteredRoms
.flatMap((rom) => rom.franchises.map((franchise) => franchise.name))
.sort()
),
]);
galleryFilterStore.setFilterCompany([
...new Set(
romsStore.filteredRoms
.flatMap((rom) => rom.companies.map((company) => company.company.name))
.sort()
),
]);
galleryFilterStore.setFilterCollection([
...new Set(
romsStore.filteredRoms
.flatMap((rom) => rom.collections.map((collection) => collection.name))
.sort()
),
]);
}
function resetGallery() {
cursor.value = "";
searchCursor.value = "";
romsStore.reset();
scrolledToTop.value = true;
galleryFilterStore.reset();
}
onMounted(async () => {
@@ -165,30 +218,20 @@ onMounted(async () => {
// If platform is different, reset store and fetch roms
if (platform.id != romsStore.platform.id) {
resetGallery();
fetchRoms();
await fetchRoms();
}
// If platform is the same but there are no roms, fetch them
if (filteredRoms.value.length == 0) {
fetchRoms();
await fetchRoms();
}
setFilters();
});
onBeforeUnmount(() => {
romsStore.resetSelection();
});
onBeforeRouteLeave((to, from, next) => {
// Reset only the selection if platform is the same
if (to.fullPath.includes(from.path)) {
romsStore.resetSelection();
// Otherwise reset the entire store
} else {
resetGallery();
}
next();
});
onBeforeRouteUpdate(async (to, _) => {
// Reset store if switching to another platform
resetGallery();
@@ -196,7 +239,8 @@ onBeforeRouteUpdate(async (to, _) => {
Number(to.params.platform)
);
romsStore.setPlatform(newPlatform);
fetchRoms();
await fetchRoms();
setFilters();
});
</script>
@@ -208,13 +252,13 @@ onBeforeRouteUpdate(async (to, _) => {
<!-- Gallery cards view -->
<v-col
class="pa-1"
v-show="galleryView.current != 2"
:cols="views[galleryView.current]['size-cols']"
:xs="views[galleryView.current]['size-xs']"
:sm="views[galleryView.current]['size-sm']"
:md="views[galleryView.current]['size-md']"
:lg="views[galleryView.current]['size-lg']"
:xl="views[galleryView.current]['size-xl']"
v-show="galleryViewStore.current != 2"
:cols="views[galleryViewStore.current]['size-cols']"
:xs="views[galleryViewStore.current]['size-xs']"
:sm="views[galleryViewStore.current]['size-sm']"
:md="views[galleryViewStore.current]['size-md']"
:lg="views[galleryViewStore.current]['size-lg']"
:xl="views[galleryViewStore.current]['size-xl']"
v-for="rom in filteredRoms"
:key="rom.id"
>
@@ -228,7 +272,7 @@ onBeforeRouteUpdate(async (to, _) => {
</v-col>
<!-- Gallery list view -->
<v-col v-show="galleryView.current == 2">
<v-col v-show="galleryViewStore.current == 2">
<game-data-table />
</v-col>
</v-row>

View File

@@ -1,15 +1,10 @@
<script setup lang="ts">
import PlatformIcon from "@/components/Platform/PlatformIcon.vue";
import socket from "@/services/socket";
import storeGalleryFilter from "@/stores/galleryFilter";
import storePlatforms, { type Platform } from "@/stores/platforms";
import storeRoms from "@/stores/roms";
import storeScanning from "@/stores/scanning";
import type { Events } from "@/types/emitter";
import { normalizeString } from "@/utils";
import type { Emitter } from "mitt";
import { storeToRefs } from "pinia";
import { inject, onBeforeUnmount, ref } from "vue";
import { ref } from "vue";
// Props
const scanningStore = storeScanning();
@@ -31,13 +26,6 @@ async function scan() {
rescanUnidentified: rescanUnidentified.value,
});
}
onBeforeUnmount(() => {
// socket.off("scan:scanning_platform");
// socket.off("scan:scanning_rom");
// socket.off("scan:done");
// socket.off("scan:done_ko");
});
</script>
<template>