未登录时不请求接口,直接展示「登录后浏览资源下载」,避免 401 错误弹窗。
This commit is contained in:
1 parent
fdfc2d36f5
commit
52b3606062
3 files changed
+17
-1
No files matched your search
@@ -3,6 +3,7 @@ import { DownloadIcon, SpinnerIcon } from '@modrinth/assets'
|
||||
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
|
||||
import { skinSiteStatus, skinSiteUser } from '@/composables/skin-site-session'
|
||||
import {
|
||||
skinSitePublicDownloadCategories,
|
||||
type SkinSitePublicDownloadCategory,
|
||||
@@ -32,6 +33,10 @@ const messages = defineMessages({
|
||||
statusLegacy: { id: 'app.skin-site.downloads.status.legacy', defaultMessage: 'Legacy' },
|
||||
statusOutdated: { id: 'app.skin-site.downloads.status.outdated', defaultMessage: 'Outdated' },
|
||||
statusRemoval: { id: 'app.skin-site.downloads.status.removal', defaultMessage: 'Removal' },
|
||||
signedOut: {
|
||||
id: 'app.skin-site.downloads.signed-out',
|
||||
defaultMessage: 'Sign in to browse downloads.',
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits<{ (e: 'back'): void }>()
|
||||
@@ -42,6 +47,8 @@ const selectedCategory = ref<string | null>(null)
|
||||
const loading = ref(true)
|
||||
const failed = ref(false)
|
||||
|
||||
const signedIn = computed(() => skinSiteStatus.value === 'signed-in' && !!skinSiteUser.value)
|
||||
|
||||
const filtered = computed(() =>
|
||||
selectedCategory.value
|
||||
? items.value.filter((item) => item.category.includes(selectedCategory.value!))
|
||||
@@ -76,6 +83,10 @@ function download(item: SkinSitePublicDownloadItem) {
|
||||
async function load() {
|
||||
loading.value = true
|
||||
failed.value = false
|
||||
if (!signedIn.value) {
|
||||
loading.value = false
|
||||
return
|
||||
}
|
||||
try {
|
||||
const [listResult, categoryResult] = await Promise.all([
|
||||
skinSitePublicDownloadList(),
|
||||
@@ -138,7 +149,10 @@ onMounted(load)
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||
<p v-if="!signedIn" class="m-0 text-sm text-secondary">
|
||||
{{ formatMessage(messages.signedOut) }}
|
||||
</p>
|
||||
<div v-else-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||
<SpinnerIcon class="size-4 animate-spin" />
|
||||
{{ formatMessage(messages.loading) }}
|
||||
</div>
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
},
|
||||
"app.skin-site.downloads.title": { "message": "Downloads" },
|
||||
"app.skin-site.downloads.uploader": { "message": "by {name}" },
|
||||
"app.skin-site.downloads.signed-out": { "message": "Sign in to browse downloads." },
|
||||
"app.skin-site.home.announcements.empty": {
|
||||
"message": "No announcements right now."
|
||||
},
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
},
|
||||
"app.skin-site.downloads.title": { "message": "资源下载" },
|
||||
"app.skin-site.downloads.uploader": { "message": "上传者:{name}" },
|
||||
"app.skin-site.downloads.signed-out": { "message": "登录后浏览资源下载。" },
|
||||
"app.skin-site.home.announcements.empty": { "message": "暂无公告。" },
|
||||
"app.skin-site.home.announcements.failed": { "message": "加载公告失败。" },
|
||||
"app.skin-site.home.announcements.loading": { "message": "正在加载…" },
|
||||
|
||||
Reference in new issue
Block a user