HeaderButtons.jsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import user from '../../materials/user.png'
  2. import { actionFullProfilePageUserTypeSaga } from '../../actions/typeSaga/userTypesSaga'
  3. import { Avatar } from 'antd'
  4. import { Link } from 'react-router-dom'
  5. import { connect } from 'react-redux'
  6. import backendURL from '../../helpers/backendUrl'
  7. import {
  8. HomeOutlined,
  9. CompassOutlined,
  10. PlusSquareOutlined,
  11. ImportOutlined,
  12. SearchOutlined
  13. } from '@ant-design/icons'
  14. import React, { useEffect, useState } from 'react'
  15. const DefaultLink = ({ link, tag }) => {
  16. return (
  17. <Link to={`${link}`} className="Links">
  18. {tag}
  19. </Link>
  20. )
  21. }
  22. export const Feed = () =>
  23. <DefaultLink link={'/feed'} tag={<HomeOutlined />} />
  24. export const Explore = () => (
  25. <DefaultLink link={'/explore'} tag={<CompassOutlined />} />
  26. )
  27. export const SearchMobile = () => (
  28. <DefaultLink link={'/search'} tag={<SearchOutlined />} />
  29. )
  30. export const AddPost = ({ children }) => {
  31. const [state, setState] = useState(false)
  32. return (
  33. <>
  34. <Link to={`/edit/post/new`} className="Links">
  35. <PlusSquareOutlined onClick={() => setState(!state)} />
  36. {!state && children}
  37. </Link>
  38. </>
  39. )
  40. }
  41. export const LogOut = ({ onClick }) => (
  42. <ImportOutlined className="Links" onClick={onClick} />
  43. )
  44. const User = ({ my_Id, aboutMe: { _id, avatar } = {}, onMyPage }) => {
  45. useEffect(() => {
  46. if (my_Id) onMyPage(my_Id)
  47. }, [my_Id])
  48. return (
  49. <Link to={`/profile/${my_Id}`} className="Links" >
  50. {avatar?.url ? (
  51. <Avatar src={backendURL + '/' + avatar?.url} size={50} className="Avatar" />
  52. ) : (
  53. <Avatar src={user} size={50} className="Avatar" />
  54. )}
  55. </Link>
  56. )
  57. }
  58. export const CUser = connect(
  59. (state) => ({
  60. my_Id: state.auth?.payload?.sub?.id,
  61. aboutMe: state.myData.aboutMe,
  62. }),
  63. { onMyPage: actionFullProfilePageUserTypeSaga },
  64. )(User)