From 180344fc052c5aac87efbff35b7b07d53515a5e1 Mon Sep 17 00:00:00 2001 From: Tomasz Knapik <hi@tmkn.org> Date: Wed, 23 Jan 2019 15:28:59 +0000 Subject: [PATCH] Refactor note container --- .../src/app/src/components/NoteListingItem.js | 21 +++++++++++++++++++ .../static_src/src/app/src/containers/Note.js | 12 +++++------ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 opentech/static_src/src/app/src/components/NoteListingItem.js diff --git a/opentech/static_src/src/app/src/components/NoteListingItem.js b/opentech/static_src/src/app/src/components/NoteListingItem.js new file mode 100644 index 000000000..c7f88178d --- /dev/null +++ b/opentech/static_src/src/app/src/components/NoteListingItem.js @@ -0,0 +1,21 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import moment from 'moment'; + +export default class NoteListingItem extends React.Component { + static propTypes = { + user: PropTypes.string.isRequired, + message: PropTypes.string.isRequired, + timestamp: PropTypes.instanceOf(moment).isRequired, + }; + + render() { + const { user, timestamp, message } = this.props; + return ( + <div> + <div style={{fontWeight: 'bold'}}>{user} - {timestamp.format('ll')}</div> + <div>{message}</div> + </div> + ); + } +} diff --git a/opentech/static_src/src/app/src/containers/Note.js b/opentech/static_src/src/app/src/containers/Note.js index 17152778c..9f297145b 100644 --- a/opentech/static_src/src/app/src/containers/Note.js +++ b/opentech/static_src/src/app/src/containers/Note.js @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'; import moment from 'moment'; import { getNoteOfID } from '@selectors/notes'; +import NoteListingItem from '@components/NoteListingItem'; class Note extends React.Component { static propTypes = { @@ -17,12 +18,11 @@ class Note extends React.Component { render() { const { note } = this.props; - return ( - <div> - <div style={{fontWeight: 'bold'}}>{note.user} - {moment(note.timestamp).format('ll')}</div> - <div>{note.message}</div> - </div> - ); + return <NoteListingItem + user={note.user} + message={note.message} + timestamp={moment(note.timestamp)} + />; } } -- GitLab