Skip to content

Commit 8a40a2e

Browse files
committed
fix: using single function to show toast on copy button click
1 parent e0aadc6 commit 8a40a2e

File tree

2 files changed

+28
-37
lines changed

2 files changed

+28
-37
lines changed

components/Toast.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
<template>
2-
<div class="relative mt-24 xl:container">
2+
<div class="relative mt-24">
33
<div
4-
class="absolute top-0 right-0 flow-root p-4 transition-transform rounded-md shadow-md z-2"
4+
class="
5+
absolute
6+
top-0
7+
right-[20px]
8+
flow-root
9+
p-4
10+
transition-transform
11+
rounded-md
12+
shadow-md
13+
z-2
14+
"
515
v-bind:class="{
616
'-translate-y-screen': !toastState.show,
717
'-translate-y-0': !toastState.show,

pages/diff/_diff.vue

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
>
1414
<span class="inline-flex justify-center" v-show="copied">
1515
<svg
16-
class="w-6 h-6 mr-2"
16+
class="inline-block w-6 h-6 mr-2 ml-[-4px]"
1717
fill="none"
1818
stroke="currentColor"
1919
viewBox="0 0 24 24"
@@ -125,10 +125,10 @@ export default {
125125
}
126126
},
127127
methods: {
128-
copyUrlToClipboard() {
129-
navigator.clipboard.writeText(window.location.href)
128+
putToClipboard(textToPut, toastContent) {
129+
navigator.clipboard.writeText(textToPut)
130130
this.$store.commit('toast/setData', {
131-
content: 'Link copied to your clipboard',
131+
content: toastContent,
132132
iconHTML: `
133133
<svg
134134
class="w-6 h-6"
@@ -148,46 +148,27 @@ export default {
148148
theme: 'success',
149149
})
150150
this.$store.commit('toast/toggle')
151-
this.copied = true
152151
setTimeout(() => {
153152
this.$store.commit('toast/toggle')
154-
this.copied = false
155153
}, 5000)
156154
setTimeout(() => {
157155
this.$store.commit('toast/clean')
158156
}, 5500)
159157
},
160-
copyTextToClipboard(e) {
161-
navigator.clipboard.writeText(
162-
e.currentTarget.parentNode.parentNode.innerText.split('\n\n').join('\n')
163-
)
164-
this.$store.commit('toast/setData', {
165-
content: 'Text copied to your clipboard',
166-
iconHTML: `
167-
<svg
168-
class="w-6 h-6"
169-
fill="none"
170-
stroke="currentColor"
171-
viewBox="0 0 24 24"
172-
xmlns="http://www.w3.org/2000/svg"
173-
>
174-
<path
175-
stroke-linecap="round"
176-
stroke-linejoin="round"
177-
stroke-width="2"
178-
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
179-
></path>
180-
</svg>
181-
`,
182-
theme: 'success',
183-
})
184-
this.$store.commit('toast/toggle')
158+
copyUrlToClipboard() {
159+
this.putToClipboard(window.location.href, 'Link copied to your clipboard')
160+
this.copied = true
185161
setTimeout(() => {
186-
this.$store.commit('toast/toggle')
162+
this.copied = false
187163
}, 5000)
188-
setTimeout(() => {
189-
this.$store.commit('toast/clean')
190-
}, 5500)
164+
},
165+
copyTextToClipboard(e) {
166+
this.putToClipboard(
167+
e.currentTarget.parentNode.parentNode.innerText
168+
.split('\n\n')
169+
.join('\n'),
170+
'Text copied to your clipboard'
171+
)
191172
},
192173
},
193174
}

0 commit comments

Comments
 (0)