Skip to content

Commit 5e67d2d

Browse files
committed
fix: small fixes
1 parent 62515f5 commit 5e67d2d

4 files changed

Lines changed: 51 additions & 34 deletions

File tree

app/components/ClaimPackageModal.vue

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const props = defineProps<{
66
packageName: string
77
}>()
88
9-
const claimPackageModal = useModal('claim-package-modal')
109
const {
1110
isConnected,
1211
state,
@@ -72,14 +71,14 @@ async function handleClaim() {
7271
} else if (completedOp?.status === 'failed') {
7372
if (completedOp.result?.requiresOtp) {
7473
// OTP is needed - open connector panel to handle it
75-
claimPackageModal.close()
74+
close()
7675
connectorModal.open()
7776
} else {
7877
publishError.value = completedOp.result?.stderr || 'Failed to publish package'
7978
}
8079
} else {
8180
// Still pending/approved/running - open connector panel to show progress
82-
claimPackageModal.close()
81+
close()
8382
connectorModal.open()
8483
}
8584
} catch (err) {
@@ -89,14 +88,23 @@ async function handleClaim() {
8988
}
9089
}
9190
92-
// Reset state when modal opens
93-
function handleModalOpen() {
91+
const dialogRef = ref<HTMLDialogElement>()
92+
93+
function open() {
94+
// Reset state and check availability each time modal is opened
9495
checkResult.value = null
9596
publishError.value = null
9697
publishSuccess.value = false
9798
checkAvailability()
99+
dialogRef.value?.showModal()
100+
}
101+
102+
function close() {
103+
dialogRef.value?.close()
98104
}
99105
106+
defineExpose({ open, close })
107+
100108
// Computed for similar packages with warnings
101109
const hasDangerousSimilarPackages = computed(() => {
102110
if (!checkResult.value?.similarPackages) return false
@@ -127,7 +135,12 @@ const previewPackageJson = computed(() => {
127135

128136
<template>
129137
<!-- Modal -->
130-
<Modal :modalTitle="$t('claim.modal.title')" id="claim-package-modal" @open="handleModalOpen">
138+
<Modal
139+
ref="dialogRef"
140+
:modalTitle="$t('claim.modal.title')"
141+
id="claim-package-modal"
142+
class="max-w-md"
143+
>
131144
<!-- Loading state -->
132145
<div v-if="isChecking" class="py-8 text-center">
133146
<LoadingSpinner :text="$t('claim.modal.checking')" />
@@ -155,14 +168,14 @@ const previewPackageJson = computed(() => {
155168
<NuxtLink
156169
:to="`/package/${packageName}`"
157170
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"
158-
@click="claimPackageModal.close"
171+
@click="close"
159172
>
160173
{{ $t('claim.modal.view_package') }}
161174
</NuxtLink>
162175
<button
163176
type="button"
164177
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"
165-
@click="claimPackageModal.close"
178+
@click="close"
166179
>
167180
{{ $t('common.close') }}
168181
</button>
@@ -349,7 +362,7 @@ const previewPackageJson = computed(() => {
349362
v-if="!checkResult.available || !checkResult.valid"
350363
type="button"
351364
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"
352-
@click="claimPackageModal.close"
365+
@click="close"
353366
>
354367
{{ $t('common.close') }}
355368
</button>

app/components/ConnectorModal.vue

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<script setup lang="ts">
2-
const open = defineModel<boolean>('open', { default: false })
3-
42
const { isConnected, isConnecting, npmUser, error, hasOperations, connect, disconnect } =
53
useConnector()
64
@@ -10,14 +8,17 @@ const { copied, copy } = useClipboard({ copiedDuring: 2000 })
108
119
const hasAttemptedConnect = shallowRef(false)
1210
11+
watch(isConnected, connected => {
12+
if (!connected) {
13+
tokenInput.value = ''
14+
hasAttemptedConnect.value = false
15+
}
16+
})
17+
1318
async function handleConnect() {
1419
hasAttemptedConnect.value = true
1520
const port = Number.parseInt(portInput.value, 10) || 31415
16-
const success = await connect(tokenInput.value.trim(), port)
17-
if (success) {
18-
tokenInput.value = ''
19-
open.value = false
20-
}
21+
await connect(tokenInput.value.trim(), port)
2122
}
2223
2324
function handleDisconnect() {
@@ -40,13 +41,6 @@ const executeNpmxConnectorCommand = computed(() => {
4041
packageManager: selectedPM.value,
4142
})
4243
})
43-
44-
watch(open, isOpen => {
45-
if (isOpen) {
46-
tokenInput.value = ''
47-
hasAttemptedConnect.value = false
48-
}
49-
})
5044
</script>
5145

5246
<template>

app/components/Modal.client.vue

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
<script setup lang="ts">
2-
defineProps<{
2+
const props = defineProps<{
33
modalTitle: string
44
}>()
55
6+
const dialogRef = ref<HTMLDialogElement>()
7+
8+
const modalTitleId = computed(() => {
9+
const id = getCurrentInstance()?.attrs.id
10+
return id ? `${id}-title` : undefined
11+
})
12+
613
function handleModalClose() {
7-
const modal = document.querySelector<HTMLDialogElement>('dialog:modal')
8-
if (modal) {
9-
modal.close()
10-
}
14+
dialogRef.value?.close()
1115
}
16+
17+
defineExpose({
18+
showModal: () => dialogRef.value?.showModal(),
19+
close: () => dialogRef.value?.close(),
20+
})
1221
</script>
1322

1423
<template>
1524
<Teleport to="body">
1625
<dialog
26+
ref="dialogRef"
1727
closedby="any"
1828
class="w-full bg-bg border border-border rounded-lg shadow-xl max-h-[90vh] overflow-y-auto overscroll-contain m-0 m-auto p-6 text-white"
29+
:aria-labelledby="modalTitleId"
1930
v-bind="$attrs"
2031
>
2132
<!-- Modal top header section -->
2233
<div class="flex items-center justify-between mb-6">
23-
<h2 class="font-mono text-lg font-medium">
34+
<h2 :id="modalTitleId" class="font-mono text-lg font-medium">
2435
{{ modalTitle }}
2536
</h2>
2637
<button

app/pages/search.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,7 @@ const showClaimPrompt = computed(() => {
323323
)
324324
})
325325
326-
// Modal state for claiming a package
327-
const claimModalOpen = shallowRef(false)
326+
const claimPackageModalRef = useTemplateRef('claimPackageModalRef')
328327
329328
/**
330329
* Check if a string is a valid npm username/org name
@@ -742,7 +741,7 @@ defineOgImageComponent('Default', {
742741
<button
743742
type="button"
744743
class="shrink-0 px-4 py-2 font-mono text-sm text-bg bg-fg rounded-md motion-safe:transition-colors motion-safe:duration-200 hover:bg-fg/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50"
745-
@click="claimModalOpen = true"
744+
@click="claimPackageModalRef?.open()"
746745
>
747746
{{ $t('search.claim_button', { name: query }) }}
748747
</button>
@@ -835,7 +834,7 @@ defineOgImageComponent('Default', {
835834
<button
836835
type="button"
837836
class="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"
838-
@click="claimModalOpen = true"
837+
@click="claimPackageModalRef?.open()"
839838
>
840839
{{ $t('search.claim_button', { name: query }) }}
841840
</button>
@@ -884,6 +883,6 @@ defineOgImageComponent('Default', {
884883
</div>
885884

886885
<!-- Claim package modal -->
887-
<ClaimPackageModal v-model:open="claimModalOpen" :package-name="query" />
886+
<ClaimPackageModal ref="claimPackageModalRef" :package-name="query" />
888887
</main>
889888
</template>

0 commit comments

Comments
 (0)