[ABANDONDED] Set of "apps" 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.

117 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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. import React, { FC, useState, useEffect } from 'react'
  2. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
  3. import { faShieldAlt, faSpinner } from '@fortawesome/free-solid-svg-icons'
  4. import { Communicator, Post, Theme } from '../../../communicator'
  5. import '../../../styles/default.css'
  6. const prompts = [
  7. "What's going on?",
  8. 'What it do?',
  9. "What's happening?",
  10. "How's your day going?"
  11. ]
  12. interface Props {
  13. communicator: Communicator
  14. }
  15. const App: FC<Props> = ({ communicator }) => {
  16. const maxCharacters = 256
  17. const [content, setContent] = useState('')
  18. const [cover, setCover] = useState('')
  19. const [posting, setPosting] = useState(false)
  20. const [parent, setParent] = useState<Post | null>(null)
  21. const [theme, setTheme] = useState<Theme>({
  22. primary: '#333',
  23. primaryAlternate: '#fff',
  24. secondary: '#777',
  25. backgroundPrimary: '#fff',
  26. backgroundSecondary: '#ccc',
  27. text: '#555',
  28. red: '#ff1a1a',
  29. green: '#00802b',
  30. blue: '#005ce6',
  31. })
  32. const charactersLeft = maxCharacters - content.length
  33. const showCharactersLeft = charactersLeft < (maxCharacters / 2)
  34. const buttonDisabled = charactersLeft < 1 || content.length === 0 || posting
  35. const showCharactersDanger = charactersLeft < (maxCharacters * 0.1)
  36. const buttonText = parent ? 'Reply!' : 'Post!'
  37. useEffect(() => {
  38. const init = async () => {
  39. try {
  40. const response = await communicator.init()
  41. if (response!.parent) setParent(response!.parent)
  42. if (response!.theme) setTheme(response!.theme)
  43. await communicator.setHeight(document.body.offsetHeight)
  44. } catch (err) {}
  45. }
  46. init()
  47. }, [])
  48. const post = async () => {
  49. if (!content.length) return
  50. try {
  51. setPosting(true)
  52. await communicator.post({
  53. text: content,
  54. cover,
  55. visible: true,
  56. })
  57. setContent('')
  58. setCover('')
  59. } catch (err) {}
  60. setPosting(false)
  61. }
  62. return (
  63. <div style={{ backgroundColor: theme.backgroundPrimary }}>
  64. <div className="control">
  65. <textarea
  66. style={{ backgroundColor: theme.backgroundSecondary, borderColor: theme.secondary, color: theme.text }}
  67. placeholder={prompts[Math.floor(Math.random() * prompts.length)]}
  68. value={content}
  69. onChange={(e) => setContent(e.target.value)} />
  70. </div>
  71. <div className="field">
  72. <div className="control-container">
  73. <div className="icon" style={{ backgroundColor: theme.primary, color: theme.primaryAlternate }}>
  74. <FontAwesomeIcon icon={faShieldAlt} />
  75. </div>
  76. <div className="control">
  77. <input
  78. style={{ backgroundColor: theme.backgroundSecondary, borderColor: theme.secondary, color: theme.text }}
  79. type="text"
  80. placeholder="Cover Text"
  81. value={cover}
  82. onChange={(e) => setCover(e.target.value)} />
  83. </div>
  84. </div>
  85. </div>
  86. <nav className="level">
  87. <div>
  88. {showCharactersLeft ? <p style={{ color: showCharactersDanger ? theme.red : theme.text }}>{charactersLeft} Chars Left</p> : <p>&nbsp;</p>}
  89. </div>
  90. <div>
  91. <button style={{ backgroundColor: theme.primary, color: theme.primaryAlternate }} onClick={() => post()} disabled={buttonDisabled}>
  92. {posting ? <FontAwesomeIcon icon={faSpinner} spin /> : <span>{buttonText}</span>}
  93. </button>
  94. </div>
  95. </nav>
  96. </div>
  97. )
  98. }
  99. export default App