11<script setup lang="ts">
2- import type { CheckNameResult } from ' ~/utils/package-name'
32import { checkPackageName } from ' ~/utils/package-name'
43
54const props = defineProps <{
@@ -16,25 +15,34 @@ const {
1615 refreshState,
1716} = useConnector ()
1817
19- // Fetch name availability when modal opens
20- const checkResult = shallowRef <CheckNameResult | null >(null )
21-
22- const isChecking = shallowRef (false )
2318const isPublishing = shallowRef (false )
24- const publishError = shallowRef <string | null >(null )
2519const publishSuccess = shallowRef (false )
20+ const publishError = shallowRef <string | null >(null )
2621
27- async function checkAvailability() {
28- isChecking .value = true
29- publishError .value = null
30- try {
31- checkResult .value = await checkPackageName (props .packageName )
32- } catch (err ) {
33- publishError .value = err instanceof Error ? err .message : $t (' claim.modal.failed_to_check' )
34- } finally {
35- isChecking .value = false
36- }
37- }
22+ const {
23+ data : checkResult,
24+ refresh : checkAvailability,
25+ status,
26+ error : checkError,
27+ } = useAsyncData (
28+ (_nuxtApp , { signal }) => {
29+ return checkPackageName (props .packageName , { signal })
30+ },
31+ { default : () => null , immediate: false },
32+ )
33+
34+ const isChecking = computed (() => {
35+ return status .value === ' pending'
36+ })
37+
38+ const mergedError = computed (() => {
39+ return (
40+ publishError .value ??
41+ (checkError .value instanceof Error
42+ ? checkError .value .message
43+ : $t (' claim.modal.failed_to_check' ))
44+ )
45+ })
3846
3947const connectorModal = useModal (' connector-modal' )
4048
@@ -92,7 +100,6 @@ const dialogRef = ref<HTMLDialogElement>()
92100
93101function open() {
94102 // Reset state and check availability each time modal is opened
95- checkResult .value = null
96103 publishError .value = null
97104 publishSuccess .value = false
98105 checkAvailability ()
@@ -287,11 +294,11 @@ const previewPackageJson = computed(() => {
287294
288295 <!-- Error message -->
289296 <div
290- v-if =" publishError "
297+ v-if =" mergedError "
291298 role =" alert"
292299 class =" p-3 text-sm text-red-400 bg-red-500/10 border border-red-500/20 rounded-md"
293300 >
294- {{ publishError }}
301+ {{ mergedError }}
295302 </div >
296303
297304 <!-- Actions -->
@@ -369,17 +376,17 @@ const previewPackageJson = computed(() => {
369376 </div >
370377
371378 <!-- Error state -->
372- <div v-else-if =" publishError " class =" space-y-4" >
379+ <div v-else-if =" mergedError " class =" space-y-4" >
373380 <div
374381 role =" alert"
375382 class =" p-3 text-sm text-red-400 bg-red-500/10 border border-red-500/20 rounded-md"
376383 >
377- {{ publishError }}
384+ {{ mergedError }}
378385 </div >
379386 <button
380387 type =" button"
381388 class =" w-full px-4 py-2 font-mono text-sm text-fg-muted bg-bg-subtle border border-border rounded-md transition-colors duration-200 hover:text-fg hover:border-border-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50"
382- @click =" checkAvailability"
389+ @click =" () => checkAvailability() "
383390 >
384391 {{ $t('common.retry') }}
385392 </button >
0 commit comments