mirror of
https://github.com/rommapp/romm.git
synced 2026-12-06 07:54:18 +01:00
Merge pull request #2045 from rommapp/url-search-params
Use URL to store and load search params
This commit is contained in:
22 files changed
+212
-261
No files matched your search
@@ -11,6 +11,10 @@ ln -sf /app/romm/assets /app/frontend/assets/romm/assets
|
||||
# Define a signal handler to propagate termination signals
|
||||
function handle_termination() {
|
||||
echo "Terminating child processes..."
|
||||
# Cleanup symlinks
|
||||
rm -f /app/frontend/assets/romm/resources
|
||||
rm -f /app/frontend/assets/romm/assets
|
||||
# Kill all background jobs
|
||||
# trunk-ignore(shellcheck)
|
||||
kill -TERM $(jobs -p) 2>/dev/null
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import SearchTextField from "@/components/Gallery/AppBar/Search/SearchTextField.vue";
|
||||
import FilterTextField from "@/components/Gallery/AppBar/common/FilterTextField.vue";
|
||||
import SearchBtn from "@/components/Gallery/AppBar/Search/SearchBtn.vue";
|
||||
import FilterBtn from "@/components/Gallery/AppBar/common/FilterBtn.vue";
|
||||
import FilterDrawer from "@/components/Gallery/AppBar/common/FilterDrawer/Base.vue";
|
||||
import SelectingBtn from "@/components/Gallery/AppBar/common/SelectingBtn.vue";
|
||||
import GalleryViewBtn from "@/components/Gallery/AppBar/common/GalleryViewBtn.vue";
|
||||
import CharIndexBar from "@/components/Gallery/AppBar/common/CharIndexBar.vue";
|
||||
import { useDisplay } from "vuetify";
|
||||
import { calculateMainLayoutWidth } from "@/utils";
|
||||
|
||||
// Props
|
||||
@@ -15,17 +12,14 @@ withDefaults(
|
||||
defineProps<{
|
||||
showPlayablesFilter?: boolean;
|
||||
showPlatformsFilter?: boolean;
|
||||
showFilterBar?: boolean;
|
||||
showSearchBar?: boolean;
|
||||
}>(),
|
||||
{
|
||||
showPlayablesFilter: true,
|
||||
showPlatformsFilter: false,
|
||||
showFilterBar: false,
|
||||
showSearchBar: false,
|
||||
},
|
||||
);
|
||||
const { xs } = useDisplay();
|
||||
const { calculatedWidth } = calculateMainLayoutWidth();
|
||||
</script>
|
||||
<template>
|
||||
@@ -40,7 +34,6 @@ const { calculatedWidth } = calculateMainLayoutWidth();
|
||||
<slot name="prepend" />
|
||||
<filter-btn />
|
||||
</template>
|
||||
<filter-text-field v-if="!xs && showFilterBar" />
|
||||
<search-text-field v-if="showSearchBar" />
|
||||
<slot name="content" />
|
||||
<template #append>
|
||||
@@ -53,7 +46,7 @@ const { calculatedWidth } = calculateMainLayoutWidth();
|
||||
<filter-drawer
|
||||
:show-playables-filter="showPlayablesFilter"
|
||||
:show-platforms-filter="showPlatformsFilter"
|
||||
:show-filter-bar="showFilterBar"
|
||||
:show-search-bar="showSearchBar"
|
||||
/>
|
||||
<char-index-bar />
|
||||
</template>
|
||||
@@ -5,16 +5,17 @@ import RAvatar from "@/components/common/Collection/RAvatar.vue";
|
||||
import storeNavigation from "@/stores/navigation";
|
||||
import storeRoms from "@/stores/roms";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed } from "vue";
|
||||
import { useDisplay } from "vuetify";
|
||||
|
||||
// Props
|
||||
const { xs } = useDisplay();
|
||||
const navigationStore = storeNavigation();
|
||||
const romsStore = storeRoms();
|
||||
const { currentCollection } = storeToRefs(romsStore);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<base-gallery-app-bar show-platforms-filter show-filter-bar>
|
||||
<base-gallery-app-bar show-platforms-filter :show-search-bar="!xs">
|
||||
<template #prepend>
|
||||
<r-avatar
|
||||
v-if="currentCollection"
|
||||
|
||||
@@ -8,8 +8,10 @@ import PlatformInfoDrawer from "@/components/Gallery/AppBar/Platform/PlatformInf
|
||||
import storeRoms from "@/stores/roms";
|
||||
import storeNavigation from "@/stores/navigation";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { useDisplay } from "vuetify";
|
||||
|
||||
// Props
|
||||
const { xs } = useDisplay();
|
||||
const romsStore = storeRoms();
|
||||
const navigationStore = storeNavigation();
|
||||
const { currentPlatform } = storeToRefs(romsStore);
|
||||
@@ -17,7 +19,7 @@ const { activePlatformInfoDrawer } = storeToRefs(navigationStore);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<base-gallery-app-bar :show-playables-filter="false" show-filter-bar>
|
||||
<base-gallery-app-bar :show-playables-filter="false" :show-search-bar="!xs">
|
||||
<template #prepend>
|
||||
<missing-from-f-s-icon
|
||||
v-if="currentPlatform && currentPlatform.missing_from_fs"
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, inject } from "vue";
|
||||
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";
|
||||
|
||||
const romsStore = storeRoms();
|
||||
const { fetchingRoms, initialSearch } = storeToRefs(romsStore);
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
const galleryFilterStore = storeGalleryFilter();
|
||||
const { searchTerm } = storeToRefs(galleryFilterStore);
|
||||
|
||||
function fetchRoms() {
|
||||
if (searchTerm.value == null) return;
|
||||
|
||||
const inputElement = document.getElementById("search-text-field");
|
||||
inputElement?.blur();
|
||||
initialSearch.value = true;
|
||||
romsStore.fetchRoms(galleryFilterStore).catch((error) => {
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: `Couldn't fetch roms: ${error}`,
|
||||
icon: "mdi-close-circle",
|
||||
color: "red",
|
||||
timeout: 4000,
|
||||
});
|
||||
});
|
||||
|
||||
galleryFilterStore.activeFilterDrawer = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<v-btn
|
||||
rounded="0"
|
||||
id="search-btn"
|
||||
type="submit"
|
||||
@click="fetchRoms"
|
||||
class="bg-toplayer"
|
||||
variant="text"
|
||||
icon="mdi-magnify"
|
||||
:disabled="fetchingRoms || !searchTerm"
|
||||
/>
|
||||
</template>
|
||||
@@ -1,13 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import storeRoms from "@/stores/roms";
|
||||
import storeGalleryFilter, { type FilterType } from "@/stores/galleryFilter";
|
||||
import storeGalleryFilter from "@/stores/galleryFilter";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import type { Emitter } from "mitt";
|
||||
import { inject, nextTick, onMounted, watch } from "vue";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { debounce } from "lodash";
|
||||
|
||||
// Props
|
||||
const { t } = useI18n();
|
||||
@@ -18,63 +17,16 @@ const emitter = inject<Emitter<Events>>("emitter");
|
||||
const galleryFilterStore = storeGalleryFilter();
|
||||
const { searchTerm } = storeToRefs(galleryFilterStore);
|
||||
|
||||
async function fetchRoms() {
|
||||
async function refetchRoms() {
|
||||
if (searchTerm.value === null) return;
|
||||
|
||||
initialSearch.value = true;
|
||||
romsStore
|
||||
.fetchRoms(galleryFilterStore)
|
||||
.catch((error) => {
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: `Couldn't fetch roms: ${error}`,
|
||||
icon: "mdi-close-circle",
|
||||
color: "red",
|
||||
timeout: 4000,
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
galleryFilterStore.activeFilterDrawer = false;
|
||||
});
|
||||
emitter?.emit("filterRoms", null);
|
||||
}
|
||||
|
||||
const refetchRoms = debounce(async () => {
|
||||
if (searchTerm.value === null) return;
|
||||
|
||||
// Update URL with search term
|
||||
router.replace({ query: { search: searchTerm.value } });
|
||||
|
||||
romsStore.resetPagination();
|
||||
initialSearch.value = true;
|
||||
romsStore
|
||||
.fetchRoms(galleryFilterStore, false)
|
||||
.catch((error) => {
|
||||
emitter?.emit("snackbarShow", {
|
||||
msg: `Couldn't fetch roms: ${error}`,
|
||||
icon: "mdi-close-circle",
|
||||
color: "red",
|
||||
timeout: 4000,
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
galleryFilterStore.activeFilterDrawer = false;
|
||||
});
|
||||
}, 500);
|
||||
|
||||
function clearInput() {
|
||||
searchTerm.value = null;
|
||||
}
|
||||
|
||||
const filterToSetFilter: Record<FilterType, Function> = {
|
||||
genres: galleryFilterStore.setSelectedFilterGenre,
|
||||
franchises: galleryFilterStore.setSelectedFilterFranchise,
|
||||
collections: galleryFilterStore.setSelectedFilterCollection,
|
||||
companies: galleryFilterStore.setSelectedFilterCompany,
|
||||
age_ratings: galleryFilterStore.setSelectedFilterAgeRating,
|
||||
status: galleryFilterStore.setSelectedFilterStatus,
|
||||
regions: galleryFilterStore.setSelectedFilterRegion,
|
||||
languages: galleryFilterStore.setSelectedFilterLanguage,
|
||||
};
|
||||
|
||||
function resetGallery() {
|
||||
romsStore.setCurrentPlatform(null);
|
||||
romsStore.setCurrentCollection(null);
|
||||
@@ -83,41 +35,14 @@ function resetGallery() {
|
||||
galleryFilterStore.activeFilterDrawer = false;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
resetGallery();
|
||||
|
||||
const {
|
||||
search: searchParam,
|
||||
filter: filterParam,
|
||||
value: valueParam,
|
||||
} = router.currentRoute.value.query;
|
||||
if (searchParam !== undefined && searchParam !== searchTerm.value) {
|
||||
searchTerm.value = searchParam as string;
|
||||
}
|
||||
|
||||
// Check for query params to set filters
|
||||
if (filterParam && valueParam) {
|
||||
const filter = filterParam as FilterType;
|
||||
const value = valueParam as string;
|
||||
filterToSetFilter[filter](value);
|
||||
emitter?.emit("filter", null);
|
||||
router.replace({ query: {} }); // Clear query params
|
||||
}
|
||||
|
||||
// Check if search term is set in the URL (empty string is ok)
|
||||
if (searchTerm.value !== null) {
|
||||
romsStore.resetPagination();
|
||||
fetchRoms();
|
||||
}
|
||||
});
|
||||
onMounted(() => resetGallery());
|
||||
|
||||
watch(
|
||||
() => router.currentRoute.value.query,
|
||||
(query) => {
|
||||
if (query.search !== undefined && query.search !== searchTerm.value) {
|
||||
searchTerm.value = query.search as string;
|
||||
romsStore.resetPagination();
|
||||
fetchRoms();
|
||||
refetchRoms();
|
||||
}
|
||||
},
|
||||
{ deep: true },
|
||||
|
||||
@@ -8,7 +8,7 @@ import FilterDuplicatesBtn from "@/components/Gallery/AppBar/common/FilterDrawer
|
||||
import FilterPlayablesBtn from "@/components/Gallery/AppBar/common/FilterDrawer/FilterPlayablesBtn.vue";
|
||||
import FilterVerifiedBtn from "@/components/Gallery/AppBar/common/FilterDrawer/FilterVerifiedBtn.vue";
|
||||
import FilterRaBtn from "@/components/Gallery/AppBar/common/FilterDrawer/FilterRaBtn.vue";
|
||||
import FilterTextField from "@/components/Gallery/AppBar/common/FilterTextField.vue";
|
||||
import SearchTextField from "@/components/Gallery/AppBar/Search/SearchTextField.vue";
|
||||
import MissingFromFSIcon from "@/components/common/MissingFromFSIcon.vue";
|
||||
import storeGalleryFilter from "@/stores/galleryFilter";
|
||||
import storeRoms from "@/stores/roms";
|
||||
@@ -19,28 +19,40 @@ import { storeToRefs } from "pinia";
|
||||
import { inject, nextTick, onMounted, watch } from "vue";
|
||||
import { useDisplay } from "vuetify";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRouter } from "vue-router";
|
||||
import { debounce } from "lodash";
|
||||
|
||||
// Props
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
showPlayablesFilter?: boolean;
|
||||
showPlatformsFilter?: boolean;
|
||||
showFilterBar?: boolean;
|
||||
showSearchBar?: boolean;
|
||||
}>(),
|
||||
{
|
||||
showPlayablesFilter: true,
|
||||
showPlatformsFilter: false,
|
||||
showFilterBar: false,
|
||||
showSearchBar: false,
|
||||
},
|
||||
);
|
||||
|
||||
const { t } = useI18n();
|
||||
const { xs, smAndDown } = useDisplay();
|
||||
const router = useRouter();
|
||||
const galleryFilterStore = storeGalleryFilter();
|
||||
const romsStore = storeRoms();
|
||||
const platformsStore = storePlatforms();
|
||||
const {
|
||||
searchTerm,
|
||||
activeFilterDrawer,
|
||||
filterUnmatched,
|
||||
filterMatched,
|
||||
filterFavourites,
|
||||
filterDuplicates,
|
||||
filterPlayables,
|
||||
filterRA,
|
||||
filterMissing,
|
||||
filterVerified,
|
||||
selectedGenre,
|
||||
filterGenres,
|
||||
selectedFranchise,
|
||||
@@ -63,13 +75,52 @@ const {
|
||||
const { filteredRoms } = storeToRefs(romsStore);
|
||||
const { allPlatforms } = storeToRefs(platformsStore);
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
emitter?.on("filter", onFilterChange);
|
||||
|
||||
async function onFilterChange() {
|
||||
romsStore.resetPagination();
|
||||
romsStore.fetchRoms(galleryFilterStore, false);
|
||||
emitter?.emit("updateDataTablePages", null);
|
||||
}
|
||||
const onFilterChange = debounce(
|
||||
() => {
|
||||
romsStore.resetPagination();
|
||||
romsStore.fetchRoms(galleryFilterStore, false);
|
||||
|
||||
const url = new URL(window.location.href);
|
||||
|
||||
// Update URL with filters
|
||||
Object.entries({
|
||||
search: searchTerm.value,
|
||||
filterMatched: filterMatched.value ? "1" : null,
|
||||
filterUnmatched: filterUnmatched.value ? "1" : null,
|
||||
filterFavourites: filterFavourites.value ? "1" : null,
|
||||
filterDuplicates: filterDuplicates.value ? "1" : null,
|
||||
filterPlayables: filterPlayables.value ? "1" : null,
|
||||
filterMissing: filterMissing.value ? "1" : null,
|
||||
filterVerified: filterVerified.value ? "1" : null,
|
||||
filterRA: filterRA.value ? "1" : null,
|
||||
platform: selectedPlatform.value
|
||||
? String(selectedPlatform.value.id)
|
||||
: null,
|
||||
genre: selectedGenre.value,
|
||||
franchise: selectedFranchise.value,
|
||||
collection: selectedCollection.value,
|
||||
company: selectedCompany.value,
|
||||
ageRating: selectedAgeRating.value,
|
||||
region: selectedRegion.value,
|
||||
language: selectedLanguage.value,
|
||||
status: selectedStatus.value,
|
||||
}).forEach(([key, value]) => {
|
||||
if (value) {
|
||||
url.searchParams.set(key, value);
|
||||
} else {
|
||||
url.searchParams.delete(key);
|
||||
}
|
||||
});
|
||||
router.replace({ query: Object.fromEntries(url.searchParams.entries()) });
|
||||
// If leading and trailing options are true, this is invoked on the trailing edge of
|
||||
// the timeout only if the the function is invoked more than once during the wait
|
||||
},
|
||||
500,
|
||||
{ leading: true, trailing: true },
|
||||
);
|
||||
|
||||
emitter?.on("filterRoms", onFilterChange);
|
||||
|
||||
const filters = [
|
||||
{
|
||||
@@ -117,7 +168,7 @@ const filters = [
|
||||
// Functions
|
||||
function resetFilters() {
|
||||
galleryFilterStore.resetFilters();
|
||||
nextTick(() => emitter?.emit("filter", null));
|
||||
nextTick(() => emitter?.emit("filterRoms", null));
|
||||
}
|
||||
|
||||
function setFilters() {
|
||||
@@ -163,6 +214,87 @@ function setFilters() {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const {
|
||||
search: urlSearch,
|
||||
filterMatched: urlFilteredMatch,
|
||||
filterUnmatched: urlFilteredUnmatched,
|
||||
filterFavourites: urlFilteredFavourites,
|
||||
filterDuplicates: urlFilteredDuplicates,
|
||||
filterPlayables: urlFilteredPlayables,
|
||||
filterMissing: urlFilteredMissing,
|
||||
filterVerified: urlFilteredVerified,
|
||||
filterRA: urlFilteredRa,
|
||||
platform: urlPlatform,
|
||||
genre: urlGenre,
|
||||
franchise: urlFranchise,
|
||||
collection: urlCollection,
|
||||
company: urlCompany,
|
||||
ageRating: urlAgeRating,
|
||||
region: urlRegion,
|
||||
language: urlLanguage,
|
||||
status: urlStatus,
|
||||
} = router.currentRoute.value.query;
|
||||
|
||||
// Check if search term is set in the URL (empty string is ok)
|
||||
if (urlSearch !== undefined && urlSearch !== searchTerm.value) {
|
||||
searchTerm.value = urlSearch as string;
|
||||
romsStore.resetPagination();
|
||||
}
|
||||
|
||||
// Check for query params to set filters
|
||||
if (urlFilteredMatch !== undefined) {
|
||||
galleryFilterStore.setFilterMatched(true);
|
||||
}
|
||||
if (urlFilteredUnmatched !== undefined) {
|
||||
galleryFilterStore.setFilterUnmatched(true);
|
||||
}
|
||||
if (urlFilteredFavourites !== undefined) {
|
||||
galleryFilterStore.setFilterFavourites(true);
|
||||
}
|
||||
if (urlFilteredDuplicates !== undefined) {
|
||||
galleryFilterStore.setFilterDuplicates(true);
|
||||
}
|
||||
if (urlFilteredPlayables !== undefined) {
|
||||
galleryFilterStore.setFilterPlayables(true);
|
||||
}
|
||||
if (urlFilteredMissing !== undefined) {
|
||||
galleryFilterStore.setFilterMissing(true);
|
||||
}
|
||||
if (urlFilteredVerified !== undefined) {
|
||||
galleryFilterStore.setFilterVerified(true);
|
||||
}
|
||||
if (urlFilteredRa !== undefined) {
|
||||
galleryFilterStore.setFilterRA(true);
|
||||
}
|
||||
if (urlPlatform !== undefined) {
|
||||
const platform = platformsStore.get(Number(urlPlatform));
|
||||
if (platform) galleryFilterStore.setSelectedFilterPlatform(platform);
|
||||
}
|
||||
if (urlGenre !== undefined) {
|
||||
galleryFilterStore.setSelectedFilterGenre(urlGenre as string);
|
||||
}
|
||||
if (urlFranchise !== undefined) {
|
||||
galleryFilterStore.setSelectedFilterFranchise(urlFranchise as string);
|
||||
}
|
||||
if (urlCollection !== undefined) {
|
||||
galleryFilterStore.setSelectedFilterCollection(urlCollection as string);
|
||||
}
|
||||
if (urlCompany !== undefined) {
|
||||
galleryFilterStore.setSelectedFilterCompany(urlCompany as string);
|
||||
}
|
||||
if (urlAgeRating !== undefined) {
|
||||
galleryFilterStore.setSelectedFilterAgeRating(urlAgeRating as string);
|
||||
}
|
||||
if (urlRegion !== undefined) {
|
||||
galleryFilterStore.setSelectedFilterRegion(urlRegion as string);
|
||||
}
|
||||
if (urlLanguage !== undefined) {
|
||||
galleryFilterStore.setSelectedFilterLanguage(urlLanguage as string);
|
||||
}
|
||||
if (urlStatus !== undefined) {
|
||||
galleryFilterStore.setSelectedFilterStatus(urlStatus as string);
|
||||
}
|
||||
|
||||
watch(
|
||||
() => filteredRoms.value,
|
||||
async () => setFilters(),
|
||||
@@ -190,9 +322,9 @@ onMounted(async () => {
|
||||
class="bg-surface rounded mt-4 mb-2 pa-1 unset-height"
|
||||
>
|
||||
<v-list tabindex="-1">
|
||||
<template v-if="showFilterBar && xs">
|
||||
<template v-if="showSearchBar && xs">
|
||||
<v-list-item>
|
||||
<filter-text-field :tabindex="activeFilterDrawer ? 0 : -1" />
|
||||
<search-text-field :tabindex="activeFilterDrawer ? 0 : -1" />
|
||||
</v-list-item>
|
||||
</template>
|
||||
<v-list-item>
|
||||
@@ -238,7 +370,9 @@ onMounted(async () => {
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
:items="filterPlatforms"
|
||||
@update:model-value="nextTick(() => emitter?.emit('filter', null))"
|
||||
@update:model-value="
|
||||
nextTick(() => emitter?.emit('filterRoms', null))
|
||||
"
|
||||
>
|
||||
<template #item="{ props, item }">
|
||||
<v-list-item
|
||||
@@ -299,7 +433,9 @@ onMounted(async () => {
|
||||
variant="solo-filled"
|
||||
density="comfortable"
|
||||
:items="filter.items.value"
|
||||
@update:model-value="nextTick(() => emitter?.emit('filter', null))"
|
||||
@update:model-value="
|
||||
nextTick(() => emitter?.emit('filterRoms', null))
|
||||
"
|
||||
/>
|
||||
</v-list-item>
|
||||
<v-list-item
|
||||
|
||||
@@ -16,7 +16,7 @@ const { filterDuplicates } = storeToRefs(galleryFilterStore);
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
function setDuplicates() {
|
||||
galleryFilterStore.switchFilterDuplicates();
|
||||
emitter?.emit("filter", null);
|
||||
emitter?.emit("filterRoms", null);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ const { filterFavourites } = storeToRefs(galleryFilterStore);
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
function setFavourites() {
|
||||
galleryFilterStore.switchFilterFavourites();
|
||||
emitter?.emit("filter", null);
|
||||
emitter?.emit("filterRoms", null);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ const { filterMatched } = storeToRefs(galleryFilterStore);
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
function setUnmatched() {
|
||||
galleryFilterStore.switchFilterMatched();
|
||||
emitter?.emit("filter", null);
|
||||
emitter?.emit("filterRoms", null);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ const { filterMissing } = storeToRefs(galleryFilterStore);
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
function setMissing() {
|
||||
galleryFilterStore.switchFilterMissing();
|
||||
emitter?.emit("filter", null);
|
||||
emitter?.emit("filterRoms", null);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ const emitter = inject<Emitter<Events>>("emitter");
|
||||
// Functions
|
||||
function setPlayables() {
|
||||
galleryFilterStore.switchFilterPlayables();
|
||||
emitter?.emit("filter", null);
|
||||
emitter?.emit("filterRoms", null);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ const emitter = inject<Emitter<Events>>("emitter");
|
||||
// Functions
|
||||
function setRA() {
|
||||
galleryFilterStore.switchFilterRA();
|
||||
emitter?.emit("filter", null);
|
||||
emitter?.emit("filterRoms", null);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ const { filterUnmatched } = storeToRefs(galleryFilterStore);
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
function setUnmatched() {
|
||||
galleryFilterStore.switchFilterUnmatched();
|
||||
emitter?.emit("filter", null);
|
||||
emitter?.emit("filterRoms", null);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ const { filterVerified } = storeToRefs(galleryFilterStore);
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
function setVerified() {
|
||||
galleryFilterStore.switchFilterVerified();
|
||||
emitter?.emit("filter", null);
|
||||
emitter?.emit("filterRoms", null);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import storeGalleryFilter from "@/stores/galleryFilter";
|
||||
import storeRoms from "@/stores/roms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import { debounce } from "lodash";
|
||||
import type { Emitter } from "mitt";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { inject, nextTick, onMounted, watch } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useDisplay } from "vuetify";
|
||||
|
||||
// Props
|
||||
const { t } = useI18n();
|
||||
const { xs } = useDisplay();
|
||||
const router = useRouter();
|
||||
const galleryFilterStore = storeGalleryFilter();
|
||||
const romsStore = storeRoms();
|
||||
const { searchTerm } = storeToRefs(galleryFilterStore);
|
||||
const { fetchingRoms } = storeToRefs(romsStore);
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
|
||||
const filterRoms = debounce(() => {
|
||||
// Update URL with search term
|
||||
router.replace({ query: { search: searchTerm.value } });
|
||||
emitter?.emit("filter", null);
|
||||
}, 500);
|
||||
|
||||
function clearInput() {
|
||||
searchTerm.value = null;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const { search } = router.currentRoute.value.query;
|
||||
if (search !== undefined && search !== searchTerm.value) {
|
||||
searchTerm.value = search as string;
|
||||
filterRoms();
|
||||
}
|
||||
});
|
||||
|
||||
watch(
|
||||
() => router.currentRoute.value.query,
|
||||
(query) => {
|
||||
if (query.search !== undefined && query.search !== searchTerm.value) {
|
||||
searchTerm.value = query.search as string;
|
||||
filterRoms();
|
||||
}
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<v-text-field
|
||||
:density="xs ? 'comfortable' : 'default'"
|
||||
clearable
|
||||
hide-details
|
||||
rounded="0"
|
||||
:label="t('common.filter')"
|
||||
v-model="searchTerm"
|
||||
:disabled="fetchingRoms"
|
||||
@keyup.enter="filterRoms"
|
||||
prepend-inner-icon="mdi-filter-outline"
|
||||
@click:clear="clearInput"
|
||||
@update:model-value="nextTick(filterRoms)"
|
||||
/>
|
||||
</template>
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<v-empty-state
|
||||
headline="Whoops, 404"
|
||||
headline="Whoops!"
|
||||
title="No games to show"
|
||||
text="The game you were looking for does not exist"
|
||||
icon="mdi-disc-alert"
|
||||
|
||||
@@ -105,56 +105,58 @@ export default defineStore("galleryFilter", {
|
||||
setSelectedFilterStatus(status: string) {
|
||||
this.selectedStatus = status;
|
||||
},
|
||||
setFilterUnmatched(value: boolean) {
|
||||
this.filterUnmatched = value;
|
||||
this.filterMatched = false;
|
||||
},
|
||||
switchFilterUnmatched() {
|
||||
this.filterUnmatched = !this.filterUnmatched;
|
||||
this.filterMatched = false;
|
||||
},
|
||||
disableFilterUnmatched() {
|
||||
setFilterMatched(value: boolean) {
|
||||
this.filterMatched = value;
|
||||
this.filterUnmatched = false;
|
||||
},
|
||||
switchFilterMatched() {
|
||||
this.filterMatched = !this.filterMatched;
|
||||
this.filterUnmatched = false;
|
||||
},
|
||||
disableFilterMatched() {
|
||||
this.filterMatched = false;
|
||||
setFilterFavourites(value: boolean) {
|
||||
this.filterFavourites = value;
|
||||
},
|
||||
switchFilterFavourites() {
|
||||
this.filterFavourites = !this.filterFavourites;
|
||||
},
|
||||
disableFilterFavourites() {
|
||||
this.filterFavourites = false;
|
||||
setFilterDuplicates(value: boolean) {
|
||||
this.filterDuplicates = value;
|
||||
},
|
||||
switchFilterDuplicates() {
|
||||
this.filterDuplicates = !this.filterDuplicates;
|
||||
},
|
||||
disableFilterDuplicates() {
|
||||
this.filterDuplicates = false;
|
||||
setFilterPlayables(value: boolean) {
|
||||
this.filterPlayables = value;
|
||||
},
|
||||
switchFilterPlayables() {
|
||||
this.filterPlayables = !this.filterPlayables;
|
||||
},
|
||||
disableFilterPlayables() {
|
||||
this.filterPlayables = false;
|
||||
setFilterRA(value: boolean) {
|
||||
this.filterRA = value;
|
||||
},
|
||||
switchFilterRA() {
|
||||
this.filterRA = !this.filterRA;
|
||||
},
|
||||
disableFilterRA() {
|
||||
this.filterRA = false;
|
||||
setFilterMissing(value: boolean) {
|
||||
this.filterMissing = value;
|
||||
},
|
||||
switchFilterMissing() {
|
||||
this.filterMissing = !this.filterMissing;
|
||||
},
|
||||
disableFilterMissing() {
|
||||
this.filterMissing = false;
|
||||
setFilterVerified(value: boolean) {
|
||||
this.filterVerified = value;
|
||||
},
|
||||
switchFilterVerified() {
|
||||
this.filterVerified = !this.filterVerified;
|
||||
},
|
||||
disableFilterVerified() {
|
||||
this.filterVerified = false;
|
||||
},
|
||||
isFiltered() {
|
||||
return Boolean(
|
||||
this.filterUnmatched ||
|
||||
@@ -189,14 +191,14 @@ export default defineStore("galleryFilter", {
|
||||
this.selectedRegion = null;
|
||||
this.selectedLanguage = null;
|
||||
this.selectedStatus = null;
|
||||
this.disableFilterUnmatched();
|
||||
this.disableFilterMatched();
|
||||
this.disableFilterFavourites();
|
||||
this.disableFilterDuplicates();
|
||||
this.disableFilterPlayables();
|
||||
this.disableFilterRA();
|
||||
this.disableFilterMissing();
|
||||
this.disableFilterVerified();
|
||||
this.filterUnmatched = false;
|
||||
this.filterMatched = false;
|
||||
this.filterFavourites = false;
|
||||
this.filterDuplicates = false;
|
||||
this.filterPlayables = false;
|
||||
this.filterRA = false;
|
||||
this.filterMissing = false;
|
||||
this.filterVerified = false;
|
||||
},
|
||||
},
|
||||
});
|
||||
Vendored
+1
-2
@@ -72,9 +72,8 @@ export type Events = {
|
||||
scrim: boolean;
|
||||
};
|
||||
openFabMenu: boolean;
|
||||
filter: null;
|
||||
filterRoms: null;
|
||||
firmwareDrawerShow: null;
|
||||
updateDataTablePages: null;
|
||||
sortBarShow: null;
|
||||
showQRCodeDialog: SimpleRom;
|
||||
selectSaveDialog: DetailedRom;
|
||||
|
||||
@@ -196,10 +196,10 @@ onMounted(async () => {
|
||||
allRoms.value.length === 0) &&
|
||||
collection
|
||||
) {
|
||||
resetGallery();
|
||||
if (currentCollection.value) resetGallery();
|
||||
romsStore.setCurrentCollection(collection);
|
||||
document.title = `${collection.name}`;
|
||||
await fetchRoms();
|
||||
emitter?.emit("filterRoms", null);
|
||||
}
|
||||
|
||||
window.addEventListener("scroll", onScroll);
|
||||
@@ -225,10 +225,10 @@ onMounted(async () => {
|
||||
allRoms.value.length === 0) &&
|
||||
collection
|
||||
) {
|
||||
resetGallery();
|
||||
if (currentVirtualCollection.value) resetGallery();
|
||||
romsStore.setCurrentVirtualCollection(collection);
|
||||
document.title = `${collection.name}`;
|
||||
await fetchRoms();
|
||||
emitter?.emit("filterRoms", null);
|
||||
}
|
||||
|
||||
window.addEventListener("scroll", onScroll);
|
||||
@@ -363,7 +363,7 @@ onBeforeUnmount(() => {
|
||||
<fab-overlay />
|
||||
</template>
|
||||
<template v-else>
|
||||
<empty-game v-if="!fetchingRoms" />
|
||||
<empty-game v-if="allCollections.length > 0 && !fetchingRoms" />
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
@@ -192,10 +192,10 @@ onMounted(async () => {
|
||||
allRoms.value.length === 0) &&
|
||||
platform
|
||||
) {
|
||||
resetGallery();
|
||||
if (currentPlatform.value) resetGallery();
|
||||
romsStore.setCurrentPlatform(platform);
|
||||
document.title = `${platform.display_name}`;
|
||||
await fetchRoms();
|
||||
emitter?.emit("filterRoms", null);
|
||||
}
|
||||
|
||||
window.addEventListener("scroll", onScroll);
|
||||
@@ -232,7 +232,7 @@ onBeforeRouteUpdate(async (to, from) => {
|
||||
) {
|
||||
romsStore.setCurrentPlatform(platform);
|
||||
document.title = `${platform.display_name}`;
|
||||
await fetchRoms();
|
||||
emitter?.emit("filterRoms", null);
|
||||
} else {
|
||||
noPlatformError.value = true;
|
||||
}
|
||||
@@ -311,7 +311,7 @@ onBeforeUnmount(() => {
|
||||
<fab-overlay />
|
||||
</template>
|
||||
<template v-else>
|
||||
<empty-game v-if="!fetchingRoms" />
|
||||
<empty-game v-if="allPlatforms.length > 0 && !fetchingRoms" />
|
||||
</template>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
@@ -144,6 +144,7 @@ function onScroll() {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
emitter?.emit("filterRoms", null);
|
||||
scrolledToTop.value = true;
|
||||
window.addEventListener("scroll", onScroll);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user