Skip to content

Commit 47013e9

Browse files
committed
refactor: use useClipboard from vueuse
1 parent 950e585 commit 47013e9

5 files changed

Lines changed: 12 additions & 34 deletions

File tree

app/components/ConnectorModal.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { isConnected, isConnecting, npmUser, error, hasOperations, connect, disco
66
77
const tokenInput = shallowRef('')
88
const portInput = shallowRef('31415')
9-
const copied = shallowRef(false)
9+
const { copied, copy } = useClipboard({ copiedDuring: 2000 })
1010
1111
async function handleConnect() {
1212
const port = Number.parseInt(portInput.value, 10) || 31415
@@ -26,11 +26,7 @@ function copyCommand() {
2626
if (portInput.value !== '31415') {
2727
command += ` --port ${portInput.value}`
2828
}
29-
navigator.clipboard.writeText(command)
30-
copied.value = true
31-
setTimeout(() => {
32-
copied.value = false
33-
}, 2000)
29+
copy(command)
3430
}
3531
3632
const selectedPM = useSelectedPackageManager()

app/composables/useCopyToClipboard.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/composables/useInstallCommand.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,11 @@ export function useInstallCommand(
7676
})
7777

7878
// Copy state
79-
const copied = ref(false)
79+
const { copied, copy } = useClipboard({ copiedDuring: 2000 })
8080

8181
async function copyInstallCommand() {
8282
if (!fullInstallCommand.value) return
83-
await navigator.clipboard.writeText(fullInstallCommand.value)
84-
copied.value = true
85-
setTimeout(() => (copied.value = false), 2000)
83+
await copy(fullInstallCommand.value)
8684
}
8785

8886
return {

app/pages/[...package].vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ const executeCommand = computed(() => {
293293
})
294294
295295
// Copy execute command (for binary-only packages)
296-
const { copied: executeCopied, copy: copyExecute } = useCopyToClipboard()
296+
const { copied: executeCopied, copy: copyExecute } = useClipboard({ copiedDuring: 2000 })
297297
const copyExecuteCommand = () => copyExecute(executeCommand.value)
298298
299299
// Get associated create-* package info (e.g., vite -> create-vite)
@@ -334,7 +334,7 @@ const createCommand = computed(() => {
334334
})
335335
336336
// Copy create command
337-
const { copied: createCopied, copy: copyCreate } = useCopyToClipboard()
337+
const { copied: createCopied, copy: copyCreate } = useClipboard({ copiedDuring: 2000 })
338338
const copyCreateCommand = () => copyCreate(createCommand.value)
339339
340340
// Primary run command parts
@@ -355,7 +355,7 @@ function getFullRunCommand(command?: string) {
355355
}
356356
357357
// Copy run command
358-
const { copied: runCopied, copy: copyRun } = useCopyToClipboard()
358+
const { copied: runCopied, copy: copyRun } = useClipboard({ copiedDuring: 2000 })
359359
const copyRunCommand = (command?: string) => copyRun(getFullRunCommand(command))
360360
361361
// Expandable description

app/pages/code/[...path].vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,10 @@ function handleLineClick(lineNum: number, event: MouseEvent) {
228228
}
229229
230230
// Copy link to current line(s)
231-
async function copyPermalink() {
231+
const { copied: permalinkCopied, copy: copyPermalink } = useClipboard({ copiedDuring: 2000 })
232+
function copyPermalinkUrl() {
232233
const url = new URL(window.location.href)
233-
await navigator.clipboard.writeText(url.toString())
234+
copyPermalink(url.toString())
234235
}
235236
236237
// Canonical URL for this code page
@@ -373,9 +374,9 @@ useSeoMeta({
373374
v-if="selectedLines"
374375
type="button"
375376
class="px-2 py-1 font-mono text-xs text-fg-muted bg-bg-subtle border border-border rounded hover:text-fg hover:border-border-hover transition-colors"
376-
@click="copyPermalink"
377+
@click="copyPermalinkUrl"
377378
>
378-
{{ $t('code.copy_link') }}
379+
{{ permalinkCopied ? $t('common.copied') : $t('code.copy_link') }}
379380
</button>
380381
<a
381382
:href="`https://cdn.jsdelivr.net/npm/${packageName}@${version}/${filePath}`"

0 commit comments

Comments
 (0)