Skip to content

Commit

Permalink
feat(electron): copy button of connection page (#154)
Browse files Browse the repository at this point in the history

Co-authored-by: arlo <[email protected]>
  • Loading branch information
alexzhang1030 and webfansplz authored Jan 6, 2024
1 parent 8cd47f8 commit 96b6f2f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 14 deletions.
14 changes: 9 additions & 5 deletions packages/client/src/components/WaitForConnection.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { VueInput } from '@vue/devtools-ui'
import { VueIcon, VueInput } from '@vue/devtools-ui'
import AppConnecting from '~/components/AppConnecting.vue'
const props = defineProps<{
Expand All @@ -16,6 +16,8 @@ const _network = scriptWrapper(props.network!)
const local = ref(_local)
const network = ref(_network)
const { copy } = useCopy()
</script>

<template>
Expand All @@ -28,11 +30,13 @@ const network = ref(_network)
<p class="text-center text-sm op80 text-base">
Add one of the following to the top of your page 👇:
</p>
<div class="mt-3 $ui-fcc flex-row">
<VueInput v-model="local" left-icon="i-carbon-copy" class="w-400px!" />
<div class="mt-3 $ui-fcc flex-row gap3">
<VueInput v-model="local" class="w-380px!" />
<VueIcon icon="i-carbon-copy" class="cursor-pointer text-primary-300 hover:text-primary-500" @click="copy(local)" />
</div>
<div class="mt-3 $ui-fcc flex-row">
<VueInput v-model="network" left-icon="i-carbon-copy" class="w-400px!" />
<div class="mt-3 $ui-fcc flex-row gap3">
<VueInput v-model="network" class="w-380px!" />
<VueIcon icon="i-carbon-copy" class="cursor-pointer text-primary-300 hover:text-primary-500" @click="copy(network)" />
</div>
</div>
</AppConnecting>
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/components/assets/AssetDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const codeSnippets = computed(() => {
return items
})
const copy = useCopy()
const { copy } = useCopy()
const timeAgo = useTimeAgo(() => asset.value.mtime)
const fileSize = computed(() => {
const size = asset.value.size
Expand Down Expand Up @@ -159,7 +159,7 @@ const supportsPreview = computed(() => {
icon="i-carbon-copy"
action mr1 mt--2px flex-none
:border="false"
@click="copy(asset.publicPath, 'assets-public-path')"
@click="copy(asset.publicPath, { silent: false, type: 'assets-public-path' })"
/>
<RouterLink
:to="asset.publicPath"
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/components/code/CodeSnippets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const props = defineProps<{
}>()
const selected = shallowRef<CodeSnippet | undefined>(props.codeSnippets[0])
const copy = useCopy()
const { copy } = useCopy()
const selectedLang = computed(() => (selected.value?.lang || 'text') as BuiltinLanguage)
Expand Down Expand Up @@ -45,7 +45,7 @@ watchEffect(() => {
w-full of-auto p3
/>
<div flex="~ gap-2" px3 pb3>
<VueButton @click="copy(selected!.code, eventType || `code-snippet-${selected.name}`)">
<VueButton @click="copy(selected!.code, { silent: false, type: eventType || `code-snippet-${selected.name}` })">
Copy
<template #icon>
<slot name="i-carbon-copy" />
Expand Down
38 changes: 35 additions & 3 deletions packages/client/src/composables/editor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
import { showVueNotification } from '@vue/devtools-ui'

interface CopyOptions {
silent?: boolean
type?: string
}

export function useCopy() {
const clipboard = useClipboard()
const { copy: _copy, copied } = useClipboard()

const copy = (text: string, options: CopyOptions = {}) => {
const {
silent = false,
type = '',
} = options
_copy(text).then(() => {
if (!silent) {
showVueNotification({
message: 'Copied to clipboard',
type: 'success',
duration: 3000,
})
}
}).catch(() => {
if (!silent) {
showVueNotification({
message: 'Failed to copy to clipboard',
type: 'error',
duration: 3000,
})
}
})
}

return (text: string, type?: string) => {
clipboard.copy(text)
return {
copy,
copied,
}
}
6 changes: 4 additions & 2 deletions packages/ui/src/components/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const props = withDefaults(defineProps<{
loading?: boolean
autoFocus?: boolean
loadingDebounceTime?: number
readonly?: boolean
}>(), {
placeholder: '',
variant: 'normal',
Expand All @@ -26,6 +27,7 @@ const props = withDefaults(defineProps<{
loading: false,
autoFocus: false,
loadingDebounceTime: 0,
readonly: false,
})
const emit = defineEmits<{
Expand All @@ -42,7 +44,7 @@ const focused = refWithControl(false, {
emit('updateFocused', value)
},
})
const noFocusAnimation = computed(() => props.variant === 'flat' || props.variant === 'warning')
const noFocusAnimation = computed(() => props.variant === 'flat' || props.variant === 'warning' || props.disabled || props.readonly)
const disabled = computed(() => props.disabled || loading.value)
Expand Down Expand Up @@ -100,7 +102,7 @@ watchEffect(() => {
<input
ref="inputRef" v-model="value"
class="$ui-base w-full bg-transparent color-inherit outline-none placeholder-color-gray-500 dark:placeholder-gray-300" :type="props.password ? 'password' : 'text'"
:placeholder="placeholder" :disabled="disabled"
:placeholder="placeholder" :disabled="disabled || readonly"
@blur="focused = false"
>
<div v-if="loading" :class="iconClasses">
Expand Down

0 comments on commit 96b6f2f

Please sign in to comment.