refactor: Remove unused variables and functions in LibraryManagement component

This commit is contained in:
zurdi
2025-12-30 01:15:19 +00:00
parent 6b0e2aff2c
commit 65645e2f1b
2 changed files with 4 additions and 158 deletions

View File

@@ -137,16 +137,15 @@ function resetMissingRoms() {
galleryFilterStore.resetFilters();
}
const { y: documentY } = useScroll(document.body, { throttle: 500 });
const { y: windowY } = useScroll(window, { throttle: 500 });
watch(documentY, () => {
watch(windowY, () => {
clearTimeout(timeout);
window.setTimeout(async () => {
scrolledToTop.value = documentY.value === 0;
scrolledToTop.value = windowY.value === 0;
if (
documentY.value + window.innerHeight >=
document.body.scrollHeight - 300 &&
windowY.value + window.innerHeight >= document.body.scrollHeight - 300 &&
fetchTotalRoms.value > filteredRoms.value.length
) {
await fetchRoms();

View File

@@ -23,133 +23,6 @@ const tab = ref<"mapping" | "excluded" | "missing">(
);
const configStore = storeConfig();
const { config } = storeToRefs(configStore);
const romsStore = storeRoms();
const { fetchingRoms, fetchTotalRoms, filteredRoms } = storeToRefs(romsStore);
const galleryViewStore = storeGalleryView();
const { scrolledToTop } = storeToRefs(galleryViewStore);
const galleryFilterStore = storeGalleryFilter();
const { selectedPlatform } = storeToRefs(galleryFilterStore);
const platformsStore = storePlatforms();
const missingGamesLoading = ref(false);
const emitter = inject<Emitter<Events>>("emitter");
let timeout: ReturnType<typeof setTimeout> = setTimeout(() => {}, 400);
const allPlatforms = computed(() =>
[
...new Map(
filteredRoms.value
.map((rom) => platformsStore.get(rom.platform_id))
.filter((platform) => !!platform)
.map((platform) => [platform!.id, platform]),
).values(),
].sort((a, b) => a!.name.localeCompare(b!.name)),
);
const onFilterChange = debounce(
() => {
romsStore.resetPagination();
galleryFilterStore.setFilterMissing(true);
romsStore.fetchRoms({
galleryFilter: galleryFilterStore,
concat: false,
});
const url = new URL(window.location.href);
// Update URL with filters
Object.entries({
platform: selectedPlatform.value
? String(selectedPlatform.value.id)
: null,
}).forEach(([key, value]) => {
if (value) {
url.searchParams.set(key, value);
} else {
url.searchParams.delete(key);
}
});
galleryFilterStore.setFilterMissing(false);
},
500,
// 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
{ leading: false, trailing: true },
);
async function fetchRoms() {
if (fetchingRoms.value) return;
emitter?.emit("showLoadingDialog", {
loading: true,
scrim: false,
});
galleryFilterStore.setFilterMissing(true);
romsStore
.fetchRoms({ galleryFilter: galleryFilterStore })
.then(() => {
emitter?.emit("showLoadingDialog", {
loading: false,
scrim: false,
});
})
.catch((error) => {
console.error("Error fetching missing games:", error);
emitter?.emit("snackbarShow", {
msg: `Couldn't fetch missing ROMs: ${error}`,
icon: "mdi-close-circle",
color: "red",
timeout: 4000,
});
})
.finally(() => {
galleryFilterStore.setFilterMissing(false);
if (romsStore.fetchOffset === romsStore.fetchLimit) {
missingGamesLoading.value = false;
}
});
}
function cleanupAll() {
romsStore.setLimit(MAX_FETCH_LIMIT);
galleryFilterStore.setFilterMissing(true);
romsStore
.fetchRoms({ galleryFilter: galleryFilterStore })
.then(() => {
emitter?.emit("showLoadingDialog", {
loading: false,
scrim: false,
});
if (filteredRoms.value.length > 0) {
emitter?.emit("showDeleteRomDialog", filteredRoms.value);
} else {
emitter?.emit("snackbarShow", {
msg: "No missing ROMs to delete",
icon: "mdi-close-circle",
color: "red",
timeout: 4000,
});
}
})
.catch((error) => {
console.error("Error fetching missing games:", error);
emitter?.emit("snackbarShow", {
msg: `Couldn't fetch missing ROMs: ${error}`,
icon: "mdi-close-circle",
color: "red",
timeout: 4000,
});
})
.finally(() => {
galleryFilterStore.setFilterMissing(false);
});
}
function resetMissingRoms() {
romsStore.reset();
galleryFilterStore.resetFilters();
}
const { y: windowY } = useScroll(window, { throttle: 500 });
// Watch for tab changes and update URL
watch(tab, (newTab) => {
router.replace({
@@ -171,32 +44,6 @@ watch(
},
{ immediate: true },
);
watch(windowY, () => {
clearTimeout(timeout);
window.setTimeout(async () => {
scrolledToTop.value = windowY.value === 0;
if (
windowY.value + window.innerHeight >= document.body.scrollHeight - 300 &&
fetchTotalRoms.value > filteredRoms.value.length
) {
await fetchRoms();
}
}, 100);
});
onMounted(() => {
resetMissingRoms();
// Only fetch ROMs if we're on the missing tab
if (tab.value === "missing") {
fetchRoms();
}
});
onUnmounted(() => {
resetMissingRoms();
});
</script>
<template>