Skip to content

Commit 8c97fa2

Browse files
committed
refactor: moved puttoclipboard function to utils.ts
1 parent 238b31d commit 8c97fa2

File tree

5 files changed

+56
-69
lines changed

5 files changed

+56
-69
lines changed

components/diffActionBar.vue

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
py-2
99
mb-4
1010
sticky
11-
top-[80px]
11+
top-[70px]
1212
dark:bg-gray-700
1313
bg-gray-300
1414
dark:bg-opacity-50
@@ -43,7 +43,7 @@
4343
<div id="nextDiffSection" class="inline-flex items-center gap-1">
4444
<button
4545
id="nextDiff"
46-
class="inline-flex items-center justify-center px-1 py-1 text-sm text-gray-600 transition-transform transform bg-gray-300 border border-gray-800 rounded-sm outline-none dark:border-gray-400 dark:text-white dark:bg-gray-800 align-center focus:ring-4 active:scale-y-75"
46+
class="inline-flex items-center justify-center px-1 py-1 text-sm text-gray-600 transition-transform transform bg-gray-300 border border-gray-800 rounded-sm outline-none dark:border-gray-400 dark:text-white dark:bg-gray-800 align-center focus:ring-4 active:scale-y-75 hover:scale-105 hover:shadow-lg"
4747
aria-label="Go to next diff"
4848
type="button"
4949
@click="goToNextDiff"
@@ -68,7 +68,7 @@
6868
<div id="prevDiffSection" class="inline-flex items-center gap-1">
6969
<button
7070
id="prevDiff"
71-
class="inline-flex items-center justify-center px-1 py-1 text-sm text-gray-600 transition-transform transform bg-gray-300 border border-gray-800 rounded-sm outline-none dark:border-gray-400 dark:text-white dark:bg-gray-800 align-center focus:ring-4 active:scale-y-75"
71+
class="inline-flex items-center justify-center px-1 py-1 text-sm text-gray-600 transition-transform transform bg-gray-300 border border-gray-800 rounded-sm outline-none dark:border-gray-400 dark:text-white dark:bg-gray-800 align-center focus:ring-4 active:scale-y-75 hover:scale-105 hover:shadow-lg"
7272
aria-label="Go to previous diff"
7373
type="button"
7474
@click="goToPreviousDiff"
@@ -94,7 +94,7 @@
9494
<div>
9595
<button
9696
type="button"
97-
class="inline-flex items-center justify-center gap-1 p-2 text-sm transition-transform transform rounded-md shadow outline-none justify-self-end focus:ring-4 active:scale-y-75"
97+
class="inline-flex items-center justify-center gap-1 p-2 text-sm transition-transform transform rounded-md shadow outline-none justify-self-end focus:ring-4 active:scale-y-75 hover:scale-105 hover:shadow-lg copy-uri-button"
9898
aria-label="Copy url to clipboard"
9999
:class="{
100100
'bg-blue-500 text-white': !copied,
@@ -142,6 +142,7 @@
142142
</template>
143143

144144
<script>
145+
import { putToClipboard } from '~/helpers/utils'
145146
export default {
146147
data() {
147148
return {
@@ -181,32 +182,12 @@ export default {
181182
}
182183
},
183184
methods: {
184-
putToClipboard(textToPut, toastContent) {
185-
navigator.clipboard.writeText(textToPut)
186-
this.$store.commit('toast/show', {
187-
show: true,
188-
content: toastContent,
189-
iconHTML: `
190-
<svg
191-
class="w-6 h-6"
192-
fill="none"
193-
stroke="currentColor"
194-
viewBox="0 0 24 24"
195-
xmlns="http://www.w3.org/2000/svg"
196-
>
197-
<path
198-
stroke-linecap="round"
199-
stroke-linejoin="round"
200-
stroke-width="2"
201-
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
202-
></path>
203-
</svg>
204-
`,
205-
theme: 'success',
206-
})
207-
},
208185
copyUrlToClipboard() {
209-
this.putToClipboard(window.location.href, 'Link copied to your clipboard')
186+
putToClipboard(
187+
window.location.href,
188+
'Link copied to your clipboard',
189+
this.$store
190+
)
210191
this.copied = true
211192
setTimeout(() => {
212193
this.copied = false
@@ -262,3 +243,8 @@ export default {
262243
},
263244
}
264245
</script>
246+
<style lang="scss">
247+
.copy-uri-button:hover svg {
248+
@apply rotate-12;
249+
}
250+
</style>

components/navbar.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
class="sticky top-0 left-0 right-0 z-10 text-gray-800 shadow-lg dark:shadow-dark bg-gray-50 dark:bg-gray-900 dark:text-gray-50"
44
>
55
<div class="container flex items-center py-4 m-auto">
6-
<div v-if="showBackButton" class="hidden mr-4 md:block">
6+
<div
7+
v-if="showBackButton"
8+
class="hidden mr-4 md:block hover:scale-110 filter hover:drop-shadow-md"
9+
>
710
<NuxtLink to="/">
811
<svg
912
class="w-6 h-6"
@@ -62,7 +65,7 @@
6265
<slot name="right" />
6366
<button
6467
type="button"
65-
class="inline-flex items-center justify-center ml-4 bg-transparent border-2 border-gray-700 rounded-full shadow-lg w-9 h-9 active:scale-y-75"
68+
class="inline-flex items-center justify-center ml-4 bg-transparent border-2 border-gray-700 rounded-full shadow-lg w-9 h-9 active:scale-y-75 hover:scale-105 hover:shadow-lg"
6669
aria-label="Toggle Dark Mode"
6770
@click="toggleDarkMode"
6871
>
@@ -104,7 +107,6 @@
104107
<ul class="flex items-center justify-end">
105108
<li class="relative inline-block ml-2 lg:ml-4">
106109
<a
107-
class=""
108110
href="https://github.com/technikhil314/offline-diff-viewer"
109111
title="go to github repository of this open source project"
110112
>

components/singleDiff.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
</template>
3030

3131
<script>
32+
import { putToClipboard } from '~/helpers/utils'
3233
export default {
3334
props: {
3435
diff: {
@@ -55,11 +56,12 @@ export default {
5556
},
5657
methods: {
5758
copyTextToClipboard(e) {
58-
this.putToClipboard(
59+
putToClipboard(
5960
e.currentTarget.parentNode.parentNode.innerText
6061
.split('\n\n')
6162
.join('\n'),
62-
'Text copied to your clipboard'
63+
'Text copied to your clipboard',
64+
this.$store
6365
)
6466
},
6567
},

helpers/utils.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { Store } from 'vuex'
2+
import { ToastState } from '~/store/toast'
3+
14
export function doUrlSafeBase64(decoded: string) {
25
return decoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
36
}
@@ -26,3 +29,32 @@ export function escapeHtml(unsafe: string) {
2629
.replace(/"/g, '&quot;')
2730
.replace(/'/g, '&#039;')
2831
}
32+
33+
export function putToClipboard(
34+
textToPut: string,
35+
toastContent: string,
36+
store: Store<ToastState>
37+
) {
38+
navigator.clipboard.writeText(textToPut)
39+
store.commit('toast/show', {
40+
show: true,
41+
content: toastContent,
42+
iconHTML: `
43+
<svg
44+
class="w-6 h-6"
45+
fill="none"
46+
stroke="currentColor"
47+
viewBox="0 0 24 24"
48+
xmlns="http://www.w3.org/2000/svg"
49+
>
50+
<path
51+
stroke-linecap="round"
52+
stroke-linejoin="round"
53+
stroke-width="2"
54+
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
55+
></path>
56+
</svg>
57+
`,
58+
theme: 'success',
59+
})
60+
}

pages/v1/diff.vue

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -132,40 +132,5 @@ export default {
132132
driver.start()
133133
}
134134
},
135-
methods: {
136-
putToClipboard(textToPut, toastContent) {
137-
navigator.clipboard.writeText(textToPut)
138-
this.$store.commit('toast/show', {
139-
show: true,
140-
content: toastContent,
141-
iconHTML: `
142-
<svg
143-
class="w-6 h-6"
144-
fill="none"
145-
stroke="currentColor"
146-
viewBox="0 0 24 24"
147-
xmlns="http://www.w3.org/2000/svg"
148-
>
149-
<path
150-
stroke-linecap="round"
151-
stroke-linejoin="round"
152-
stroke-width="2"
153-
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
154-
></path>
155-
</svg>
156-
`,
157-
theme: 'success',
158-
})
159-
},
160-
},
161135
}
162136
</script>
163-
164-
<style lang="scss">
165-
.copy-uri-button:hover {
166-
@apply shadow-lg;
167-
svg {
168-
@apply scale-110 rotate-12;
169-
}
170-
}
171-
</style>

0 commit comments

Comments
 (0)