[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.

90 lines
3.3 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. import React, { FC } from 'react'
  2. import { useDispatch } from 'react-redux'
  3. import { Link } from 'react-router-dom'
  4. import moment from 'moment'
  5. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
  6. import { faClock, faReplyAll, faExclamationCircle } from '@fortawesome/free-solid-svg-icons'
  7. import { useTheme } from '../hooks'
  8. import { setEntities } from '../actions/entities'
  9. import { normalize } from '../utils/normalization'
  10. import { Post, EntityType } from '../types'
  11. import User from '../components/user'
  12. interface Props {
  13. post: Post
  14. }
  15. const PostComponent: FC<Props> = ({ post }) => {
  16. const theme = useTheme()
  17. const dispatch = useDispatch()
  18. const showCover = !!post.cover && !post.revealed
  19. const handleShowPost = () => {
  20. const posts = normalize([{
  21. ...post,
  22. revealed: true,
  23. }], EntityType.Post)
  24. dispatch(setEntities(posts.entities))
  25. }
  26. return (
  27. <div className="post" style={{ backgroundColor: theme.backgroundPrimary, borderColor: theme.backgroundSecondary, color: theme.text }}>
  28. {showCover &&
  29. <div className="cover" style={{ backgroundColor: theme.primary, color: theme.primaryAlternate }} onClick={() => handleShowPost()}>{post.cover}</div>
  30. }
  31. {!showCover &&
  32. <div className="post-content">
  33. {post.text && <p>{post.text}</p>}
  34. {post.attachments && post.attachments.length > 0 &&
  35. <div className="attachments">
  36. {post.attachments.map(attachment => (
  37. <div key={attachment.url} className="attachment">
  38. <img src={attachment.url} />
  39. {attachment.text && <p className="caption">{attachment.text}</p>}
  40. </div>
  41. ))}
  42. </div>
  43. }
  44. </div>
  45. }
  46. <div className="post-info" style={{ borderColor: theme.backgroundSecondary }}>
  47. <div>
  48. <User user={post.user} />
  49. </div>
  50. {!!post.cover && post.cover.length > 0 &&
  51. <div>
  52. <span className="icon" style={{ color: theme.red }}>
  53. <FontAwesomeIcon icon={faExclamationCircle} />
  54. </span>
  55. </div>
  56. }
  57. <div>
  58. <Link to={`/p/${post.id}`} style={{ color: theme.primary }}>
  59. <span className="icon" style={{ color: theme.secondary }}>
  60. <FontAwesomeIcon icon={faReplyAll} />
  61. </span>
  62. {post.replies}
  63. </Link>
  64. </div>
  65. <div>
  66. <span className="icon" style={{ color: theme.secondary }}>
  67. <FontAwesomeIcon icon={faClock} />
  68. </span>
  69. <Link to={`/p/${post.id}`} style={{ color: theme.primary }}>
  70. {moment(post.created).format('MMMM Do, h:mm A')}
  71. </Link>
  72. </div>
  73. </div>
  74. </div>
  75. )
  76. }
  77. export default PostComponent