From e52846dac38632c5fd0482f75a6e5bb1061e8a0b Mon Sep 17 00:00:00 2001 From: "Calum H. (IMB11)" Date: Tue, 16 Jun 2026 19:11:28 +0100 Subject: [PATCH] fix: vers page --- apps/app-frontend/src/pages/Browse.vue | 76 ++++++++++++++----- apps/app-frontend/src/pages/project/Index.vue | 21 ++++- 2 files changed, 75 insertions(+), 22 deletions(-) diff --git a/apps/app-frontend/src/pages/Browse.vue b/apps/app-frontend/src/pages/Browse.vue index 57ad402831..8ce11f96be 100644 --- a/apps/app-frontend/src/pages/Browse.vue +++ b/apps/app-frontend/src/pages/Browse.vue @@ -29,7 +29,7 @@ import { import { useQueryClient } from '@tanstack/vue-query' import { convertFileSrc } from '@tauri-apps/api/core' import type { Ref } from 'vue' -import { computed, ref, watch } from 'vue' +import { computed, onMounted, onUnmounted, ref, watch } from 'vue' import type { LocationQuery } from 'vue-router' import { onBeforeRouteLeave, useRoute, useRouter } from 'vue-router' @@ -41,6 +41,7 @@ import { get_search_results_v3, get_version_many, } from '@/helpers/cache.js' +import { profile_listener } from '@/helpers/events.js' import { get_loader_versions as getLoaderManifest } from '@/helpers/metadata' import { get as getInstance, @@ -181,6 +182,28 @@ watchServerContextChanges() await initInstanceContext() +async function refreshInstalledProjectIds() { + if (!route.query.i) return + + if (route.query.from === 'worlds') { + const worlds = await get_profile_worlds(route.query.i as string).catch(handleError) + if (!worlds) return + + const serverProjectIds = worlds + .filter((w) => w.type === 'server' && 'project_id' in w && w.project_id) + .map((w) => (w as { project_id: string }).project_id) + debugLog('installedServerProjectIds loaded', { count: serverProjectIds.length }) + installedProjectIds.value = serverProjectIds + return + } + + const ids = await getInstalledProjectIds(route.query.i as string).catch(handleError) + if (!ids) return + + debugLog('installedProjectIds loaded', { count: ids.length }) + installedProjectIds.value = ids +} + async function initInstanceContext() { debugLog('initInstanceContext', { queryI: route.query.i, @@ -199,24 +222,7 @@ async function initInstanceContext() { gameVersion: instance.value?.game_version, }) - if (route.query.from === 'worlds') { - get_profile_worlds(route.query.i as string) - .then((worlds) => { - const serverProjectIds = worlds - .filter((w) => w.type === 'server' && 'project_id' in w && w.project_id) - .map((w) => (w as { project_id: string }).project_id) - debugLog('installedServerProjectIds loaded', { count: serverProjectIds.length }) - installedProjectIds.value = serverProjectIds - }) - .catch(handleError) - } else { - getInstalledProjectIds(route.query.i as string) - .then((ids) => { - debugLog('installedProjectIds loaded', { count: ids?.length }) - installedProjectIds.value = ids - }) - .catch(handleError) - } + await refreshInstalledProjectIds() if (instance.value?.linked_data?.project_id) { debugLog('checking linked project for server status', instance.value.linked_data.project_id) @@ -978,6 +984,38 @@ if (instance.value?.game_version) { await searchState.refreshSearch() +type UnlistenFn = () => void + +let isUnmounted = false +let unlistenProfiles: UnlistenFn | null = null + +onMounted(() => { + profile_listener(async (event: { event: string; profile_path_id: string }) => { + if ( + instance.value && + event.profile_path_id === instance.value.path && + event.event === 'synced' + ) { + await refreshInstalledProjectIds() + await searchState.refreshSearch() + } + }) + .then((unlisten) => { + if (isUnmounted) { + unlisten() + return + } + + unlistenProfiles = unlisten + }) + .catch(handleError) +}) + +onUnmounted(() => { + isUnmounted = true + unlistenProfiles?.() +}) + function getProjectBrowseQuery() { if (!installContext.value) return undefined return { diff --git a/apps/app-frontend/src/pages/project/Index.vue b/apps/app-frontend/src/pages/project/Index.vue index 035d12899f..7d5b24dd36 100644 --- a/apps/app-frontend/src/pages/project/Index.vue +++ b/apps/app-frontend/src/pages/project/Index.vue @@ -406,6 +406,20 @@ function buildProjectHref(path, extraQuery = {}) { return qs ? `${path}?${qs}` : path } +function buildBrowseHref(path) { + const params = new URLSearchParams() + for (const [key, val] of Object.entries(route.query)) { + if (key === 'b') continue + if (Array.isArray(val)) { + for (const v of val) params.append(key, v) + } else if (val) { + params.append(key, String(val)) + } + } + const qs = params.toString() + return qs ? `${path}?${qs}` : path +} + const projectDescriptionHref = computed(() => buildProjectHref(`/project/${route.params.id}`)) const versionsHref = computed(() => buildProjectHref(`/project/${route.params.id}/versions`, instanceFilters.value), @@ -416,7 +430,7 @@ const projectBrowseBackUrl = computed(() => { const browsePath = route.query.b if (typeof browsePath === 'string' && browsePath.startsWith('/browse/')) return browsePath const type = data.value?.project_type ? `${data.value.project_type}` : 'mod' - return `/browse/${type}` + return buildBrowseHref(`/browse/${type}`) }) const projectInstallContext = computed(() => { @@ -725,10 +739,11 @@ async function install(version) { version, instance.value ? instance.value.path : null, 'ProjectPage', - (version) => { + (version, installedProjectIds) => { installing.value = false - if (instance.value && version) { + const installedIds = installedProjectIds ?? [data.value.id] + if (instance.value && version && installedIds.includes(data.value.id)) { installed.value = true installedVersion.value = version }