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

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