Refactor tab synchronization logic to simplify URL change handling in GameDetails.vue

This commit is contained in:
zurdi
2025-11-19 22:48:51 +00:00
parent c1fe3895f8
commit 033eae8299

View File

@@ -127,27 +127,12 @@ watch(tab, (newTab) => {
}
});
// Watch for URL changes and update tab
// Type guard for valid tab names
function isValidTab(tab: unknown): tab is (
| "details"
| "manual"
| "gamedata"
| "personal"
| "timetobeat"
| "additionalcontent"
| "screenshots"
| "relatedgames"
) {
return typeof tab === "string" && validTabs.includes(tab);
}
watch(
() => route.query.tab,
(newTab) => {
if (isValidTab(newTab)) {
if (tab.value !== newTab) {
tab.value = newTab;
if (newTab && validTabs.includes(newTab as any)) {
if (tab.value !== newTab && typeof newTab === "string") {
tab.value = newTab as typeof tab.value;
}
}
},