Add connection QR code and link (#28)

* Add connection link clipboard copy

* Add connection link QR code
This commit is contained in:
Brian Ginsburg 2022-08-05 10:56:34 -07:00 committed by GitHub
parent 143ec66d1f
commit 2adcca9e55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 8 deletions

39
package-lock.json generated
View File

@ -8,6 +8,8 @@
"name": "svelte-elemetary-template", "name": "svelte-elemetary-template",
"version": "0.1.0", "version": "0.1.0",
"dependencies": { "dependencies": {
"clipboard-copy": "^4.0.1",
"qrcode-svg": "^1.1.0",
"webnative": "0.33.0-alpha-4" "webnative": "0.33.0-alpha-4"
}, },
"devDependencies": { "devDependencies": {
@ -1294,6 +1296,25 @@
"url": "https://github.com/chalk/strip-ansi?sponsor=1" "url": "https://github.com/chalk/strip-ansi?sponsor=1"
} }
}, },
"node_modules/clipboard-copy": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/clipboard-copy/-/clipboard-copy-4.0.1.tgz",
"integrity": "sha512-wOlqdqziE/NNTUJsfSgXmBMIrYmfd5V0HCGsR8uAKHcg+h9NENWINcfRjtWGU77wDHC8B8ijV4hMTGYbrKovng==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
]
},
"node_modules/cliui": { "node_modules/cliui": {
"version": "7.0.4", "version": "7.0.4",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz",
@ -3610,6 +3631,14 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/qrcode-svg": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/qrcode-svg/-/qrcode-svg-1.1.0.tgz",
"integrity": "sha512-XyQCIXux1zEIA3NPb0AeR8UMYvXZzWEhgdBgBjH9gO7M48H9uoHzviNz8pXw3UzrAcxRRRn9gxHewAVK7bn9qw==",
"bin": {
"qrcode-svg": "bin/qrcode-svg.js"
}
},
"node_modules/queue-microtask": { "node_modules/queue-microtask": {
"version": "1.2.3", "version": "1.2.3",
"integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==",
@ -5728,6 +5757,11 @@
} }
} }
}, },
"clipboard-copy": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/clipboard-copy/-/clipboard-copy-4.0.1.tgz",
"integrity": "sha512-wOlqdqziE/NNTUJsfSgXmBMIrYmfd5V0HCGsR8uAKHcg+h9NENWINcfRjtWGU77wDHC8B8ijV4hMTGYbrKovng=="
},
"cliui": { "cliui": {
"version": "7.0.4", "version": "7.0.4",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz",
@ -7366,6 +7400,11 @@
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==",
"dev": true "dev": true
}, },
"qrcode-svg": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/qrcode-svg/-/qrcode-svg-1.1.0.tgz",
"integrity": "sha512-XyQCIXux1zEIA3NPb0AeR8UMYvXZzWEhgdBgBjH9gO7M48H9uoHzviNz8pXw3UzrAcxRRRn9gxHewAVK7bn9qw=="
},
"queue-microtask": { "queue-microtask": {
"version": "1.2.3", "version": "1.2.3",
"integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==",

View File

@ -50,6 +50,8 @@
] ]
}, },
"dependencies": { "dependencies": {
"clipboard-copy": "^4.0.1",
"qrcode-svg": "^1.1.0",
"webnative": "0.33.0-alpha-4" "webnative": "0.33.0-alpha-4"
} }
} }

View File

@ -1,11 +1,26 @@
<script lang="ts"> <script lang="ts">
import clipboardCopy from 'clipboard-copy'
import QRCode from 'qrcode-svg'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
import { sessionStore, theme } from '../../../stores'
import type { BackupView } from '$lib/views' import type { BackupView } from '$lib/views'
import ClipboardIcon from '$components/icons/ClipboardIcon.svelte' import ClipboardIcon from '$components/icons/ClipboardIcon.svelte'
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const origin = window.location.origin
const connectionLink = `${origin}/link?username=${$sessionStore.username}`
const qrcode = new QRCode({
content: connectionLink,
color: $theme === 'light' ? '#334155' : '#E2E8F0',
background: '#ffffff00'
}).svg()
const copyLink = async () => {
await clipboardCopy(connectionLink)
}
const navigate = (view: BackupView) => { const navigate = (view: BackupView) => {
dispatch('navigate', { view }) dispatch('navigate', { view })
} }
@ -15,16 +30,12 @@
<div class="modal"> <div class="modal">
<div class="modal-box w-80 relative text-center"> <div class="modal-box w-80 relative text-center">
<div> <div>
<h3 class="mb-7 text-xl font-serif">Connect a backup device</h3> <h3 class="pb-1 text-xl font-serif">Connect a backup device</h3>
{@html qrcode}
<!-- GIANT QR CODE GOES HERE --> <p class="font-extralight pt-1 mb-8">
QR Codes
<p class="mt-8 mb-4">
Scan this code on the new device, or share the connection link. Scan this code on the new device, or share the connection link.
</p> </p>
<button class="btn btn-primary btn-outline" on:click={copyLink}>
<button class="btn btn-primary btn-outline" href="/backup">
<ClipboardIcon /> <ClipboardIcon />
<span class="ml-2">Copy connection link</span> <span class="ml-2">Copy connection link</span>
</button> </button>