2018-05-11 21:44:34 +02:00
|
|
|
import React, { PureComponent } from 'react'
|
2018-04-08 22:49:58 +02:00
|
|
|
import PropTypes from 'prop-types'
|
2018-05-06 18:38:40 +02:00
|
|
|
import FileSaver from 'file-saver'
|
2018-05-07 10:48:34 +02:00
|
|
|
import vCard from '../../lib/vcf/vcard'
|
2018-04-21 13:39:18 +02:00
|
|
|
import Social from '../molecules/Social'
|
2018-04-06 17:24:35 +02:00
|
|
|
import './Footer.scss'
|
2018-04-02 23:22:48 +02:00
|
|
|
|
2018-05-11 21:44:34 +02:00
|
|
|
class Footer extends PureComponent {
|
2018-05-06 18:38:40 +02:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
2018-05-11 21:44:34 +02:00
|
|
|
|
|
|
|
this.state = { year: new Date().getFullYear() }
|
2018-05-06 18:38:40 +02:00
|
|
|
}
|
|
|
|
|
2018-05-07 11:10:50 +02:00
|
|
|
generateFileName() {
|
|
|
|
// results in 'matthias-kretschmann.vcf'
|
2018-05-07 15:39:42 +02:00
|
|
|
return `${this.props.meta.title
|
|
|
|
.toLowerCase()
|
|
|
|
.split(' ')
|
|
|
|
.join('-')}.vcf`
|
2018-05-07 11:10:50 +02:00
|
|
|
}
|
|
|
|
|
2018-05-06 18:38:40 +02:00
|
|
|
constructVcard() {
|
2018-05-07 10:48:34 +02:00
|
|
|
const meta = this.props.meta
|
|
|
|
const contact = new vCard()
|
|
|
|
const photo = meta.avatarBase64
|
2018-05-07 11:10:50 +02:00
|
|
|
|
2018-05-07 10:48:34 +02:00
|
|
|
contact.set('fn', meta.title)
|
|
|
|
contact.set('title', meta.tagline)
|
|
|
|
contact.set('email', meta.email)
|
|
|
|
contact.set('url', meta.url, { type: 'Portfolio' })
|
|
|
|
contact.add('url', meta.social.Blog, { type: 'Blog' })
|
|
|
|
contact.set('nickname', 'kremalicious')
|
|
|
|
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' })
|
2018-05-07 11:10:50 +02:00
|
|
|
|
2018-05-07 10:48:34 +02:00
|
|
|
const vcard = contact.toString('3.0')
|
2018-05-07 11:10:50 +02:00
|
|
|
this.downloadVcard(vcard)
|
2018-05-06 18:38:40 +02:00
|
|
|
}
|
|
|
|
|
2018-05-07 11:10:50 +02:00
|
|
|
downloadVcard(vcard) {
|
2018-05-06 18:38:40 +02:00
|
|
|
const blob = new Blob([vcard], { type: 'text/x-vcard' })
|
2018-05-07 11:10:50 +02:00
|
|
|
FileSaver.saveAs(blob, this.generateFileName())
|
2018-05-06 18:38:40 +02:00
|
|
|
}
|
|
|
|
|
2018-05-12 01:42:29 +02:00
|
|
|
handleAddressbookClick = e => {
|
2018-05-06 18:38:40 +02:00
|
|
|
e.preventDefault()
|
|
|
|
this.constructVcard()
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const meta = this.props.meta
|
|
|
|
|
|
|
|
return (
|
|
|
|
<footer className="footer">
|
|
|
|
<Social meta={meta} minimal />
|
|
|
|
<p className="footer__actions">
|
2018-05-07 15:39:42 +02:00
|
|
|
<a
|
|
|
|
href={`${meta.url}/${this.generateFileName()}`}
|
|
|
|
onClick={this.handleAddressbookClick}
|
|
|
|
>
|
2018-05-06 18:38:40 +02:00
|
|
|
Add to addressbook
|
2018-05-07 10:48:34 +02:00
|
|
|
</a>
|
2018-05-06 18:38:40 +02:00
|
|
|
<a href={meta.gpg}>PGP/GPG key</a>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<small>
|
2018-05-11 21:44:34 +02:00
|
|
|
© {this.state.year} {meta.title} — All Rights Reserved
|
2018-05-06 18:38:40 +02:00
|
|
|
</small>
|
|
|
|
</p>
|
|
|
|
</footer>
|
|
|
|
)
|
|
|
|
}
|
2018-04-02 23:22:48 +02:00
|
|
|
}
|
|
|
|
|
2018-04-08 22:49:58 +02:00
|
|
|
Footer.propTypes = {
|
|
|
|
meta: PropTypes.object,
|
|
|
|
}
|
|
|
|
|
2018-04-02 23:22:48 +02:00
|
|
|
export default Footer
|