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

96 lines
3.1 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
  1. import React, { FC, useState, useEffect } from 'react'
  2. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
  3. import { faEyeSlash } from '@fortawesome/free-solid-svg-icons'
  4. import { Communicator } from '../../../communicator'
  5. import classNames from 'classnames'
  6. import { ClassDictionary } from '../../../types'
  7. import '../../../styles/default.scss'
  8. interface Props {
  9. communicator: Communicator
  10. }
  11. const App: FC<Props> = ({ communicator }) => {
  12. const maxCharacters = 256
  13. const [content, setContent] = useState('')
  14. const [cover, setCover] = useState('')
  15. const [posting, setPosting] = useState(false)
  16. const charactersLeft = maxCharacters - content.length
  17. const showCharactersLeft = charactersLeft < (maxCharacters / 2)
  18. const buttonDisabled = charactersLeft < 1 || content.length === 0 || posting
  19. const showCharactersStyle: ClassDictionary = {
  20. 'has-text-danger': charactersLeft < (maxCharacters * 0.1),
  21. }
  22. const buttonStyle: ClassDictionary = {
  23. 'button': true,
  24. 'is-primary': true,
  25. 'is-loading': posting,
  26. }
  27. useEffect(() => {
  28. const init = async () => {
  29. try {
  30. await communicator.init()
  31. await communicator.setHeight(document.body.offsetHeight)
  32. } catch (err) {
  33. console.error('App Component: ', err)
  34. }
  35. }
  36. init()
  37. }, [])
  38. const post = async () => {
  39. if (!content.length) return
  40. try {
  41. setPosting(true)
  42. await communicator.post(true, content, cover)
  43. setContent('')
  44. setCover('')
  45. } catch (err) {
  46. console.error('App Component: ', err)
  47. }
  48. setPosting(false)
  49. }
  50. return (
  51. <div>
  52. <div className="field">
  53. <div className="control">
  54. <textarea className="textarea" placeholder="What it do?" value={content} onChange={(e) => setContent(e.target.value)} />
  55. </div>
  56. </div>
  57. <div className="field">
  58. <p className="control has-icons-left">
  59. <input className="input" type="text" placeholder="Cover Text" value={cover} onChange={(e) => setCover(e.target.value)} />
  60. <span className="icon is-small is-left">
  61. <FontAwesomeIcon icon={faEyeSlash} />
  62. </span>
  63. </p>
  64. </div>
  65. <nav className="level">
  66. <div className="level-left">
  67. <div className="level-item">
  68. {showCharactersLeft && <p className={classNames(showCharactersStyle)}>{charactersLeft} Chars Left</p>}
  69. </div>
  70. </div>
  71. <div className="level-right">
  72. <div className="level-item">
  73. <button className={classNames(buttonStyle)} onClick={() => post()} disabled={buttonDisabled}>Post!</button>
  74. </div>
  75. </div>
  76. </nav>
  77. </div>
  78. )
  79. }
  80. export default App