HeaderButtons.jsx 1.6 KB

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