Skip to content

Commit

Permalink
Extract QR-Button as component, fix button display
Browse files Browse the repository at this point in the history
Signed-off-by: Knut Ahlers <knut@ahlers.me>
  • Loading branch information
Luzifer committed Sep 30, 2023
1 parent dc9d6ed commit b0ed41a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 108 deletions.
51 changes: 3 additions & 48 deletions src/components/display-url.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@
>
<i class="fas fa-clipboard" />
</button>
<button
v-if="!$root.customize.disableQRSupport"
id="secret-url-qrcode"
ref="qrButton"
class="btn btn-secondary"
:disabled="!secretQRDataURL"
>
<i class="fas fa-qrcode" />
</button>
<app-qr-button :qr-content="secretUrl" />
</div>
<p v-html="$t('text-burn-hint')" />
<p v-if="expiresAt">
Expand All @@ -43,10 +35,10 @@
</div>
</template>
<script>
import { Popover } from 'bootstrap'
import qrcode from 'qrcode'
import appQrButton from './qr-button.vue'
export default {
components: { appQrButton },
computed: {
hasClipboard() {
return Boolean(navigator.clipboard && navigator.clipboard.writeText)
Expand All @@ -67,7 +59,6 @@ export default {
return {
copyToClipboardSuccess: false,
popover: null,
secretQRDataURL: '',
}
},
Expand All @@ -81,23 +72,11 @@ export default {
}, 500)
})
},
generateQR() {
if (this.$root.customize.disableQRSupport) {
return
}
qrcode.toDataURL(this.secretUrl, { width: 200 })
.then(url => {
this.secretQRDataURL = url
})
},
},
mounted() {
// Give the interface a moment to transistion and focus
window.setTimeout(() => this.$refs.secretUrl.focus(), 100)
this.generateQR()
},
name: 'AppDisplayURL',
Expand All @@ -118,29 +97,5 @@ export default {
type: String,
},
},
watch: {
secretQRDataURL(to) {
if (this.popover) {
this.popover.dispose()
}
this.popover = new Popover(this.$refs.qrButton, {
content: () => {
const img = document.createElement('img')
img.src = to
return img
},
html: true,
placement: 'left',
trigger: 'focus',
})
},
secretUrl() {
this.generateQR()
},
},
}
</script>
83 changes: 23 additions & 60 deletions src/components/secret-display.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,28 @@
:value="secret"
rows="4"
/>
<div
class="btn-group-vertical"
role="group"
>
<button
v-if="hasClipboard"
:class="{'btn': true, 'btn-primary': !copyToClipboardSuccess, 'btn-success': copyToClipboardSuccess}"
:disabled="!secret"
@click="copySecret"
<div class="d-flex align-items-start p-0">
<div
class="btn-group-vertical"
role="group"
>
<i class="fas fa-fw fa-clipboard" />
</button>
<a
class="btn btn-secondary"
:href="secretContentBlobURL"
download
>
<i class="fas fa-fw fa-download" />
</a>
<button
v-if="!$root.customize.disableQRSupport"
id="secret-data-qrcode"
ref="qrButton"
class="btn btn-secondary"
:disabled="!secretContentQRDataURL"
>
<i class="fas fa-fw fa-qrcode" />
</button>
<button
v-if="hasClipboard"
:class="{'btn': true, 'btn-primary': !copyToClipboardSuccess, 'btn-success': copyToClipboardSuccess}"
:disabled="!secret"
@click="copySecret"
>
<i class="fas fa-fw fa-clipboard" />
</button>
<a
class="btn btn-secondary"
:href="secretContentBlobURL"
download
>
<i class="fas fa-fw fa-download" />
</a>
<app-qr-button :qr-content="secret" />
</div>
</div>
</div>
<p v-html="$t('text-hint-burned')" />
Expand All @@ -60,10 +54,10 @@
</template>
<script>
import appCrypto from '../crypto.js'
import { Popover } from 'bootstrap'
import qrcode from 'qrcode'
import appQrButton from './qr-button.vue'
export default {
components: { appQrButton },
computed: {
hasClipboard() {
return Boolean(navigator.clipboard && navigator.clipboard.writeText)
Expand All @@ -76,7 +70,6 @@ export default {
popover: null,
secret: null,
secretContentBlobURL: null,
secretContentQRDataURL: null,
}
},
Expand Down Expand Up @@ -152,36 +145,6 @@ export default {
window.URL.revokeObjectURL(this.secretContentBlobURL)
}
this.secretContentBlobURL = window.URL.createObjectURL(new Blob([to], { type: 'text/plain' }))
if (this.$root.customize.disableQRSupport || !to) {
return
}
qrcode.toDataURL(to, { width: 200 })
.then(url => {
this.secretContentQRDataURL = url
})
.catch(() => {
this.secretContentQRDataURL = null
})
},
secretContentQRDataURL(to) {
if (this.popover) {
this.popover.dispose()
}
this.popover = new Popover(this.$refs.qrButton, {
content: () => {
const img = document.createElement('img')
img.src = to
return img
},
html: true,
placement: 'left',
trigger: 'focus',
})
},
},
}
Expand Down

0 comments on commit b0ed41a

Please sign in to comment.