tsx
53 lines
1.24 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 | |
| 6 | type ContactProps = { |
| 7 | firebase: Firebase | null |
| 8 | } |
| 9 | |
| 10 | type ContactState = { |
| 11 | content: string |
| 12 | } |
| 13 | |
| 14 | class Contact extends Component<ContactProps, ContactState> { |
| 15 | |
| 16 | contactRef: app.database.Reference | undefined; |
| 17 | |
| 18 | constructor(props: ContactProps) { |
| 19 | super(props); |
| 20 | this.contactRef = this.props.firebase?.contactRef(); |
| 21 | this.state = { |
| 22 | content: "Loading ..." |
| 23 | } |
| 24 | } |
| 25 | componentWillMount() { |
| 26 | this.contactRef?.on('value', (snapshot) => { |
| 27 | let items = snapshot?.val(); |
| 28 | this.setState({ |
| 29 | content: items.content |
| 30 | }); |
| 31 | }); |
| 32 | } |
| 33 | |
| 34 | componentWillUnmount() { |
| 35 | this.contactRef?.off(); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | render() { |
| 40 | return ( |
| 41 | <div> |
| 42 | <h1> |
| 43 | <FormattedMessage id="contact.title" |
| 44 | defaultMessage="Contact" |
| 45 | description="Contact page title"/> |
| 46 | </h1> |
| 47 | <p style={{lineHeight: "150%"}}>{this.state.content}</p> |
| 48 | </div> |
| 49 | ); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | export default Contact; |