mirror of
https://github.com/modrinth/code.git
synced 2026-09-04 05:48:57 +00:00
fix: loading flashes
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { SpinnerIcon } from '@modrinth/assets'
|
import { SpinnerIcon } from '@modrinth/assets'
|
||||||
import { Avatar, injectNotificationManager } from '@modrinth/ui'
|
import { Avatar, injectNotificationManager } from '@modrinth/ui'
|
||||||
|
import { useQueryClient } from '@tanstack/vue-query'
|
||||||
import { convertFileSrc } from '@tauri-apps/api/core'
|
import { convertFileSrc } from '@tauri-apps/api/core'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { onUnmounted, ref } from 'vue'
|
import { onUnmounted, ref } from 'vue'
|
||||||
@@ -10,11 +11,16 @@ import { instance_listener } from '@/helpers/events.js'
|
|||||||
import { list } from '@/helpers/instance'
|
import { list } from '@/helpers/instance'
|
||||||
|
|
||||||
const { handleError } = injectNotificationManager()
|
const { handleError } = injectNotificationManager()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
const recentInstances = ref([])
|
const recentInstances = ref([])
|
||||||
const getInstances = async () => {
|
const getInstances = async () => {
|
||||||
const instances = await list().catch(handleError)
|
const instances = await list().catch(handleError)
|
||||||
|
|
||||||
|
for (const instance of instances) {
|
||||||
|
queryClient.setQueryData(['instances', 'summary', instance.id], instance)
|
||||||
|
}
|
||||||
|
|
||||||
recentInstances.value = instances
|
recentInstances.value = instances
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
const dateACreated = dayjs(a.created)
|
const dateACreated = dayjs(a.created)
|
||||||
|
|||||||
@@ -226,7 +226,10 @@ window.addEventListener('online', () => {
|
|||||||
offline.value = false
|
offline.value = false
|
||||||
})
|
})
|
||||||
|
|
||||||
const instance = ref<GameInstance>()
|
const initialInstanceId = String(displayedInstanceRoute.value.params.id ?? '')
|
||||||
|
const instance = ref<GameInstance | undefined>(
|
||||||
|
queryClient.getQueryData<GameInstance>(['instances', 'summary', initialInstanceId]),
|
||||||
|
)
|
||||||
const instanceBreadcrumb = useRootBreadcrumb({
|
const instanceBreadcrumb = useRootBreadcrumb({
|
||||||
slot: 'instance',
|
slot: 'instance',
|
||||||
id: () => `instance:${String(displayedInstanceRoute.value.params.id ?? '')}`,
|
id: () => `instance:${String(displayedInstanceRoute.value.params.id ?? '')}`,
|
||||||
@@ -387,6 +390,9 @@ async function fetchInstance() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
instance.value = nextInstance ?? undefined
|
instance.value = nextInstance ?? undefined
|
||||||
|
if (nextInstance) {
|
||||||
|
queryClient.setQueryData(['instances', 'summary', nextInstance.id], nextInstance)
|
||||||
|
}
|
||||||
displayedInstanceRoute.value = nextRoute
|
displayedInstanceRoute.value = nextRoute
|
||||||
sharedInstanceState.reset()
|
sharedInstanceState.reset()
|
||||||
sharedInstanceState.refreshAvailability()
|
sharedInstanceState.refreshAvailability()
|
||||||
|
|||||||
@@ -350,10 +350,8 @@ function getProjectBreadcrumbLabel(projectId) {
|
|||||||
return formatMessage(commonMessages.loadingLabel)
|
return formatMessage(commonMessages.loadingLabel)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
const summary = queryClient.getQueryData(['projects', 'summary', identifier])
|
||||||
queryClient.getQueryData(['projects', 'summary', identifier])?.name ??
|
return summary?.name ?? summary?.title ?? formatMessage(commonMessages.loadingLabel)
|
||||||
formatMessage(commonMessages.loadingLabel)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const projectBreadcrumbLabel = ref(getProjectBreadcrumbLabel(route.params.id))
|
const projectBreadcrumbLabel = ref(getProjectBreadcrumbLabel(route.params.id))
|
||||||
|
|||||||
@@ -642,6 +642,21 @@ const projects = computed<ResolvedProject[]>(() =>
|
|||||||
resolvedProjectType: resolveProjectType(project, tags?.loaders.value ?? []),
|
resolvedProjectType: resolveProjectType(project, tags?.loaders.value ?? []),
|
||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
|
watch(
|
||||||
|
() => projectsQuery.data.value,
|
||||||
|
(projects) => {
|
||||||
|
if (props.projectLinkMode !== 'app') return
|
||||||
|
|
||||||
|
for (const project of projects ?? []) {
|
||||||
|
for (const identifier of [project.id, project.slug]) {
|
||||||
|
if (identifier) {
|
||||||
|
queryClient.setQueryData(['projects', 'summary', identifier], project)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
)
|
||||||
const organizations = computed(() => organizationsQuery.data.value ?? [])
|
const organizations = computed(() => organizationsQuery.data.value ?? [])
|
||||||
const collections = computed(() => collectionsQuery.data.value ?? [])
|
const collections = computed(() => collectionsQuery.data.value ?? [])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user