[ABANDONED] React/Redux front end for the Flexor social network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
4.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. // post.tsx
  2. // Copyright (C) 2020 Dwayne Harris
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. import React, { FC } from 'react'
  14. import { useDispatch } from 'react-redux'
  15. import { Link } from 'react-router-dom'
  16. import moment from 'moment'
  17. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
  18. import { faClock, faReplyAll, faExclamationCircle } from '@fortawesome/free-solid-svg-icons'
  19. import { useTheme } from '../hooks'
  20. import { setEntities } from '../actions/entities'
  21. import { normalize } from '../utils/normalization'
  22. import { Post, EntityType } from '../types'
  23. import User from '../components/user'
  24. interface Props {
  25. post: Post
  26. }
  27. const PostComponent: FC<Props> = ({ post }) => {
  28. const theme = useTheme()
  29. const dispatch = useDispatch()
  30. const showCover = !!post.cover && !post.revealed
  31. const handleShowPost = () => {
  32. const posts = normalize([{
  33. ...post,
  34. revealed: true,
  35. }], EntityType.Post)
  36. dispatch(setEntities(posts.entities))
  37. }
  38. return (
  39. <div className="post" style={{ backgroundColor: theme.backgroundPrimary, borderColor: theme.backgroundSecondary, color: theme.text }}>
  40. {showCover &&
  41. <div className="cover" style={{ backgroundColor: theme.primary, color: theme.primaryAlternate }} onClick={() => handleShowPost()}>{post.cover}</div>
  42. }
  43. {!showCover &&
  44. <div className="post-content">
  45. {post.text && <p>{post.text}</p>}
  46. {post.attachments && post.attachments.length > 0 &&
  47. <div className="attachments">
  48. {post.attachments.map(attachment => (
  49. <div key={attachment.url} className="attachment">
  50. <img src={attachment.url} />
  51. {attachment.text && <p className="caption">{attachment.text}</p>}
  52. </div>
  53. ))}
  54. </div>
  55. }
  56. </div>
  57. }
  58. <div className="post-info" style={{ borderColor: theme.backgroundSecondary }}>
  59. <div>
  60. <User user={post.user} />
  61. </div>
  62. {!!post.cover && post.cover.length > 0 &&
  63. <div>
  64. <span className="icon" style={{ color: theme.red }}>
  65. <FontAwesomeIcon icon={faExclamationCircle} />
  66. </span>
  67. </div>
  68. }
  69. <div>
  70. <Link to={`/p/${post.id}`} style={{ color: theme.primary }}>
  71. <span className="icon" style={{ color: theme.secondary }}>
  72. <FontAwesomeIcon icon={faReplyAll} />
  73. </span>
  74. {post.replies}
  75. </Link>
  76. </div>
  77. <div>
  78. <span className="icon" style={{ color: theme.secondary }}>
  79. <FontAwesomeIcon icon={faClock} />
  80. </span>
  81. <Link to={`/p/${post.id}`} style={{ color: theme.primary }}>
  82. {moment(post.created).format('MMMM Do, h:mm A')}
  83. </Link>
  84. </div>
  85. </div>
  86. </div>
  87. )
  88. }
  89. export default PostComponent