mirror of
https://github.com/modrinth/code.git
synced 2026-08-31 03:55:59 +00:00
fix: vers page
This commit is contained in:
@@ -29,7 +29,7 @@ import {
|
|||||||
import { useQueryClient } from '@tanstack/vue-query'
|
import { useQueryClient } from '@tanstack/vue-query'
|
||||||
import { convertFileSrc } from '@tauri-apps/api/core'
|
import { convertFileSrc } from '@tauri-apps/api/core'
|
||||||
import type { Ref } from 'vue'
|
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 type { LocationQuery } from 'vue-router'
|
||||||
import { onBeforeRouteLeave, useRoute, useRouter } from 'vue-router'
|
import { onBeforeRouteLeave, useRoute, useRouter } from 'vue-router'
|
||||||
|
|
||||||
@@ -41,6 +41,7 @@ import {
|
|||||||
get_search_results_v3,
|
get_search_results_v3,
|
||||||
get_version_many,
|
get_version_many,
|
||||||
} from '@/helpers/cache.js'
|
} from '@/helpers/cache.js'
|
||||||
|
import { profile_listener } from '@/helpers/events.js'
|
||||||
import { get_loader_versions as getLoaderManifest } from '@/helpers/metadata'
|
import { get_loader_versions as getLoaderManifest } from '@/helpers/metadata'
|
||||||
import {
|
import {
|
||||||
get as getInstance,
|
get as getInstance,
|
||||||
@@ -181,6 +182,28 @@ watchServerContextChanges()
|
|||||||
|
|
||||||
await initInstanceContext()
|
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() {
|
async function initInstanceContext() {
|
||||||
debugLog('initInstanceContext', {
|
debugLog('initInstanceContext', {
|
||||||
queryI: route.query.i,
|
queryI: route.query.i,
|
||||||
@@ -199,24 +222,7 @@ async function initInstanceContext() {
|
|||||||
gameVersion: instance.value?.game_version,
|
gameVersion: instance.value?.game_version,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (route.query.from === 'worlds') {
|
await refreshInstalledProjectIds()
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (instance.value?.linked_data?.project_id) {
|
if (instance.value?.linked_data?.project_id) {
|
||||||
debugLog('checking linked project for server status', 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()
|
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() {
|
function getProjectBrowseQuery() {
|
||||||
if (!installContext.value) return undefined
|
if (!installContext.value) return undefined
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -406,6 +406,20 @@ function buildProjectHref(path, extraQuery = {}) {
|
|||||||
return qs ? `${path}?${qs}` : path
|
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 projectDescriptionHref = computed(() => buildProjectHref(`/project/${route.params.id}`))
|
||||||
const versionsHref = computed(() =>
|
const versionsHref = computed(() =>
|
||||||
buildProjectHref(`/project/${route.params.id}/versions`, instanceFilters.value),
|
buildProjectHref(`/project/${route.params.id}/versions`, instanceFilters.value),
|
||||||
@@ -416,7 +430,7 @@ const projectBrowseBackUrl = computed(() => {
|
|||||||
const browsePath = route.query.b
|
const browsePath = route.query.b
|
||||||
if (typeof browsePath === 'string' && browsePath.startsWith('/browse/')) return browsePath
|
if (typeof browsePath === 'string' && browsePath.startsWith('/browse/')) return browsePath
|
||||||
const type = data.value?.project_type ? `${data.value.project_type}` : 'mod'
|
const type = data.value?.project_type ? `${data.value.project_type}` : 'mod'
|
||||||
return `/browse/${type}`
|
return buildBrowseHref(`/browse/${type}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
const projectInstallContext = computed(() => {
|
const projectInstallContext = computed(() => {
|
||||||
@@ -725,10 +739,11 @@ async function install(version) {
|
|||||||
version,
|
version,
|
||||||
instance.value ? instance.value.path : null,
|
instance.value ? instance.value.path : null,
|
||||||
'ProjectPage',
|
'ProjectPage',
|
||||||
(version) => {
|
(version, installedProjectIds) => {
|
||||||
installing.value = false
|
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
|
installed.value = true
|
||||||
installedVersion.value = version
|
installedVersion.value = version
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user