tsx
65 lines
1.51 KB
| 1 | import React, { Component } from 'react'; |
| 2 | import { FormattedMessage } from 'react-intl'; |
| 3 | import Firebase from './Firebase'; |
| 4 | import app from 'firebase/app'; |
| 5 | import { InitialData, Path } from '../shared/routes'; |
| 6 | |
| 7 | type CvProps = { |
| 8 | firebase?: Firebase |
| 9 | initialData?: InitialData |
| 10 | } |
| 11 | |
| 12 | type CvState = { |
| 13 | content: string |
| 14 | } |
| 15 | |
| 16 | class Cv extends Component<CvProps, CvState> { |
| 17 | |
| 18 | cvRef: app.database.Reference | undefined; |
| 19 | |
| 20 | constructor(props: CvProps) { |
| 21 | super(props); |
| 22 | this.cvRef = this.props.firebase?.cvRef(); |
| 23 | if (props.initialData?.path === Path.CV) { |
| 24 | this.state = { |
| 25 | content: props.initialData?.data.content |
| 26 | } |
| 27 | } else { |
| 28 | this.state = { |
| 29 | content: "Loading ..." |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | componentDidMount() { |
| 35 | if (this.props.initialData?.path === Path.CV) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | this.cvRef?.on('value', (snapshot) => { |
| 40 | let items = snapshot?.val(); |
| 41 | this.setState({ |
| 42 | content: items.content |
| 43 | }); |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | componentWillUnmount() { |
| 48 | this.cvRef?.off(); |
| 49 | } |
| 50 | |
| 51 | render() { |
| 52 | return ( |
| 53 | <div> |
| 54 | <h1> |
| 55 | <FormattedMessage id="cv.title" |
| 56 | defaultMessage="CV" |
| 57 | description="CV page title"/> |
| 58 | </h1> |
| 59 | <p style={{lineHeight: "150%"}}>{this.state.content}</p> |
| 60 | </div> |
| 61 | ); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | export default Cv; |