Skip to content

Commit 62515f5

Browse files
committed
fix: small fixes
1 parent 565c6da commit 62515f5

4 files changed

Lines changed: 25 additions & 48 deletions

File tree

app/app.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ function handleGlobalKeyup() {
7676
// https://codepen.io/paramagicdev/pen/gbYompq
7777
// see: https://github.com/npmx-dev/npmx.dev/pull/522#discussion_r2749978022
7878
function handleModalLightDismiss(e: MouseEvent) {
79-
const modal = document.querySelector<HTMLDialogElement>('dialog:modal')
80-
if (modal && modal.open && !e.composedPath().includes(modal)) {
81-
modal.close()
79+
const target = e.target as HTMLElement
80+
if (target.tagName === 'DIALOG' && target.hasAttribute('open')) {
81+
;(target as HTMLDialogElement).close()
8282
}
8383
}
8484

app/components/ChartModal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Modal
55
:modalTitle="$t('package.downloads.modal_title')"
66
id="chart-modal"
7-
class="h-full sm:h-min sm:border sm:border-border sm:rounded-lg shadow-xl sm:max-h-[90-vh] sm:max-w-3xl"
7+
class="h-full sm:h-min sm:border sm:border-border sm:rounded-lg shadow-xl sm:max-h-[90vh] sm:max-w-3xl"
88
>
99
<div class="font-mono text-sm">
1010
<slot />

app/components/ClaimPackageModal.vue

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,7 @@ const props = defineProps<{
66
packageName: string
77
}>()
88
9-
const open = defineModel<boolean>('open', { default: false })
10-
11-
// This flow doesn't seem like it's finished yet, whenever you're ready to open this modal call this function
12-
function showClaimPackageModal() {
13-
const claimPackageModal = document.querySelector<HTMLDialogElement>('#claim-package-modal')
14-
if (claimPackageModal) {
15-
claimPackageModal.showModal()
16-
}
17-
}
18-
19-
function closeClaimPackageModal() {
20-
const claimPackageModal = document.querySelector<HTMLDialogElement>('#claim-package-modal')
21-
if (claimPackageModal) {
22-
claimPackageModal.close()
23-
}
24-
}
25-
9+
const claimPackageModal = useModal('claim-package-modal')
2610
const {
2711
isConnected,
2812
state,
@@ -53,12 +37,7 @@ async function checkAvailability() {
5337
}
5438
}
5539
56-
function openConnectorModal() {
57-
const connectorModal = document.querySelector<HTMLDialogElement>('#connector-modal')
58-
if (connectorModal) {
59-
connectorModal.showModal()
60-
}
61-
}
40+
const connectorModal = useModal('connector-modal')
6241
6342
async function handleClaim() {
6443
if (!checkResult.value?.available || !isConnected.value) return
@@ -93,17 +72,15 @@ async function handleClaim() {
9372
} else if (completedOp?.status === 'failed') {
9473
if (completedOp.result?.requiresOtp) {
9574
// OTP is needed - open connector panel to handle it
96-
open.value = false
97-
closeClaimPackageModal()
98-
openConnectorModal()
75+
claimPackageModal.close()
76+
connectorModal.open()
9977
} else {
10078
publishError.value = completedOp.result?.stderr || 'Failed to publish package'
10179
}
10280
} else {
10381
// Still pending/approved/running - open connector panel to show progress
104-
open.value = false
105-
closeClaimPackageModal()
106-
openConnectorModal()
82+
claimPackageModal.close()
83+
connectorModal.open()
10784
}
10885
} catch (err) {
10986
publishError.value = err instanceof Error ? err.message : $t('claim.modal.failed_to_claim')
@@ -112,15 +89,13 @@ async function handleClaim() {
11289
}
11390
}
11491
115-
// Check availability when modal opens
116-
watch(open, isOpen => {
117-
if (isOpen) {
118-
checkResult.value = null
119-
publishError.value = null
120-
publishSuccess.value = false
121-
checkAvailability()
122-
}
123-
})
92+
// Reset state when modal opens
93+
function handleModalOpen() {
94+
checkResult.value = null
95+
publishError.value = null
96+
publishSuccess.value = false
97+
checkAvailability()
98+
}
12499
125100
// Computed for similar packages with warnings
126101
const hasDangerousSimilarPackages = computed(() => {
@@ -152,7 +127,7 @@ const previewPackageJson = computed(() => {
152127

153128
<template>
154129
<!-- Modal -->
155-
<Modal :modalTitle="$t('claim.modal.title')" id="claim-package-modal">
130+
<Modal :modalTitle="$t('claim.modal.title')" id="claim-package-modal" @open="handleModalOpen">
156131
<!-- Loading state -->
157132
<div v-if="isChecking" class="py-8 text-center">
158133
<LoadingSpinner :text="$t('claim.modal.checking')" />
@@ -180,14 +155,14 @@ const previewPackageJson = computed(() => {
180155
<NuxtLink
181156
:to="`/package/${packageName}`"
182157
class="flex-1 px-4 py-2 font-mono text-sm text-center text-bg bg-fg rounded-md transition-colors duration-200 hover:bg-fg/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50"
183-
@click="closeClaimPackageModal"
158+
@click="claimPackageModal.close"
184159
>
185160
{{ $t('claim.modal.view_package') }}
186161
</NuxtLink>
187162
<button
188163
type="button"
189164
class="flex-1 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"
190-
@click="closeClaimPackageModal"
165+
@click="claimPackageModal.close"
191166
>
192167
{{ $t('common.close') }}
193168
</button>
@@ -334,7 +309,7 @@ const previewPackageJson = computed(() => {
334309
<button
335310
type="button"
336311
class="w-full px-4 py-2 font-mono text-sm text-bg bg-fg rounded-md transition-colors duration-200 hover:bg-fg/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50"
337-
@click="openConnectorModal"
312+
@click="connectorModal.open"
338313
>
339314
{{ $t('claim.modal.connect_button') }}
340315
</button>
@@ -374,7 +349,7 @@ const previewPackageJson = computed(() => {
374349
v-if="!checkResult.available || !checkResult.valid"
375350
type="button"
376351
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"
377-
@click="closeClaimPackageModal"
352+
@click="claimPackageModal.close"
378353
>
379354
{{ $t('common.close') }}
380355
</button>

app/composables/useModal.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
export function useModal(modalId: string) {
2-
const modal = document.querySelector<HTMLDialogElement>(`#${modalId}`)
2+
const getModal = () => document.querySelector<HTMLDialogElement>(`#${modalId}`)
33

44
function open() {
5+
const modal = getModal()
56
if (modal) {
67
setTimeout(() => {
78
modal.showModal()
@@ -10,6 +11,7 @@ export function useModal(modalId: string) {
1011
}
1112

1213
function close() {
14+
const modal = getModal()
1315
if (modal) {
1416
modal.close()
1517
}

0 commit comments

Comments
 (0)