portfolio/src/components/organisms/Footer.jsx

82 lines
2.0 KiB
React
Raw Normal View History

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'
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
class Footer extends PureComponent {
2018-05-06 18:38:40 +02:00
constructor(props) {
super(props)
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() {
const meta = this.props.meta
const contact = new vCard()
const photo = meta.avatarBase64
2018-05-07 11:10:50 +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
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
</a>
2018-05-06 18:38:40 +02:00
<a href={meta.gpg}>PGP/GPG key</a>
</p>
<p>
<small>
&copy; {this.state.year} {meta.title} &mdash; 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