1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-12-22 17:23:22 +01:00

better UX for vcard download

This commit is contained in:
Matthias Kretschmann 2018-05-07 11:10:50 +02:00
parent e1787e39e6
commit 49178e6834
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 12 additions and 4 deletions

View File

@ -1,2 +1,3 @@
node_modules/
.cache/
src/lib/vcf

View File

@ -11,10 +11,16 @@ class Footer extends Component {
this.handleAddressbookClick = this.handleAddressbookClick.bind(this)
}
generateFileName() {
// results in 'matthias-kretschmann.vcf'
return `${this.props.meta.title.toLowerCase().split(' ').join('-')}.vcf`
}
constructVcard() {
const meta = this.props.meta
const contact = new vCard()
const photo = meta.avatarBase64
contact.set('fn', meta.title)
contact.set('title', meta.tagline)
contact.set('email', meta.email)
@ -24,13 +30,14 @@ class Footer extends Component {
contact.add('x-socialprofile', meta.social.Twitter, { type: 'twitter' })
contact.add('x-socialprofile', meta.social.GitHub, { type: 'GitHub' })
contact.set('photo', photo, { encoding: 'b', type: 'JPEG' })
const vcard = contact.toString('3.0')
this.downloadVcard(vcard, meta)
this.downloadVcard(vcard)
}
downloadVcard(vcard, meta) {
downloadVcard(vcard) {
const blob = new Blob([vcard], { type: 'text/x-vcard' })
FileSaver.saveAs(blob, `${meta.title.toLowerCase()}.vcf`)
FileSaver.saveAs(blob, this.generateFileName())
}
handleAddressbookClick(e) {
@ -46,7 +53,7 @@ class Footer extends Component {
<footer className="footer">
<Social meta={meta} minimal />
<p className="footer__actions">
<a href="#" onClick={this.handleAddressbookClick}>
<a href={`${meta.url}/${this.generateFileName()}`} onClick={this.handleAddressbookClick}>
Add to addressbook
</a>
<a href={meta.gpg}>PGP/GPG key</a>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB