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

67 lines
2.3 KiB

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 '../../../styles/default.scss'
  6. interface Props {
  7. communicator: Communicator
  8. }
  9. const App: FC<Props> = ({ communicator }) => {
  10. const maxCharacters = 256
  11. const [content, setContent] = useState('')
  12. const [cover, setCover] = useState('')
  13. const charactersLeft = maxCharacters - content.length
  14. const showCharactersLeft = charactersLeft < (maxCharacters / 2)
  15. const showCharactersStyle = charactersLeft > (maxCharacters * 0.1) ? 'has-text-danger' : ''
  16. const buttonStyle = 'button is-primary is-small' + (charactersLeft < 1 ? ' is-disabled' : '')
  17. useEffect(() => {
  18. const init = async () => {
  19. try {
  20. await communicator.setHeight(document.body.offsetHeight)
  21. } catch (err) {
  22. console.error('App Component: ', err)
  23. }
  24. }
  25. init()
  26. }, [])
  27. return (
  28. <div>
  29. <div className="field">
  30. <div className="control">
  31. <textarea className="textarea" placeholder="What it do?" value={content} onChange={(e) => setContent(e.target.value)} />
  32. </div>
  33. </div>
  34. <div className="field">
  35. <p className="control has-icons-left">
  36. <input className="input" type="text" placeholder="Cover Text" value={cover} onChange={(e) => setCover(e.target.value)} />
  37. <span className="icon is-small is-left">
  38. <FontAwesomeIcon icon={faEyeSlash} />
  39. </span>
  40. </p>
  41. </div>
  42. <nav className="level">
  43. <div className="level-left">
  44. <div className="level-item">
  45. {showCharactersLeft && <p className={showCharactersStyle}>{charactersLeft} Chars Left</p>}
  46. </div>
  47. </div>
  48. <div className="level-right">
  49. <div className="level-item">
  50. <button className={buttonStyle}>Post!</button>
  51. </div>
  52. </div>
  53. </nav>
  54. </div>
  55. )
  56. }
  57. export default App