card_post.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import { url } from "../../App";
  2. import { Link } from "react-router-dom";
  3. import { Card, CardHeader, CardContent, CardActions, Avatar, IconButton, Typography, Box, Divider, TextField } from '@mui/material'
  4. import { FavoriteBorderRounded, Send, ChatBubbleOutline, TurnedInNot, AccountCircle } from '@mui/icons-material/'
  5. import Grid from '@mui/material/Unstable_Grid2';
  6. export function CardPost({ postData }) {
  7. // console.log('test: ', postData)
  8. // дата поста
  9. const dateofPost = new Date(+postData.createdAt)
  10. const months = ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря']
  11. const dateofPostParse = `${dateofPost.getDate() < 10 ? '0' + dateofPost.getDate() : dateofPost.getDate()} ${months[dateofPost.getMonth()]} ${dateofPost.getFullYear()} ${dateofPost.getHours()}:${dateofPost.getMinutes() < 10 ? '0' + dateofPost.getMinutes() : dateofPost.getMinutes()}`
  12. return (
  13. <Card className="tututu" sx={{
  14. display: 'flex',
  15. flexDirection: 'column',
  16. minHeight: '80vh',
  17. borderRadius: 0
  18. }}>
  19. <CardHeader
  20. avatar={
  21. <Avatar
  22. alt=""
  23. src={(url.slice(0, -7) + postData?.owner?.avatar?.url)}
  24. sx={{ width: 50, height: 50 }}
  25. style={{ margin: '5px', border: '3px solid black', borderRadius: '50%', flexShrink: '0', overflow: 'hidden' }}
  26. />
  27. }
  28. title={
  29. <Link
  30. to={`/user/${postData?.owner?._id}`}>
  31. {postData?.owner?.login}
  32. </Link>
  33. }
  34. subheader={dateofPostParse}
  35. />
  36. <Divider />
  37. <CardActions sx={{
  38. flex: '1 1 auto',
  39. alignItems: 'flex-start'
  40. }}>
  41. <CardContent>
  42. <Grid container spacing={1}>
  43. <Grid xs={3}>
  44. {/* <Item> */}
  45. <Avatar
  46. alt=""
  47. src={(url.slice(0, -7) + postData?.owner?.avatar?.url)}
  48. sx={{ width: 50, height: 50 }}
  49. style={{ margin: '5px', border: '3px solid black', borderRadius: '50%', flexShrink: '0', overflow: 'hidden' }}
  50. />
  51. {/* </Item> */}
  52. </Grid>
  53. <Grid xs={9}>
  54. {/* <Item> */}
  55. <Typography variant="subtitle2" color="text.secondary">
  56. {postData.title}
  57. </Typography>
  58. <Typography variant="body2" color="text.secondary">
  59. {postData.text}
  60. </Typography>
  61. {/* </Item> */}
  62. </Grid>
  63. </Grid>
  64. </CardContent>
  65. </CardActions>
  66. <Divider />
  67. <CardActions disableSpacing>
  68. <Box sx={{ flexGrow: 1 }}>
  69. <Grid container>
  70. <Grid
  71. xs={12}
  72. container
  73. justifyContent="space-between"
  74. alignItems="center"
  75. flexDirection={{ xs: 'column', sm: 'row' }}
  76. sx={{ fontSize: '12px' }}
  77. >
  78. <Grid container columnSpacing={1} sx={{ order: { xs: 2, sm: 1 } }}>
  79. <Grid>
  80. <IconButton aria-label="add to favorites">
  81. <FavoriteBorderRounded />
  82. </IconButton>
  83. </Grid>
  84. <Grid>
  85. <IconButton>
  86. <ChatBubbleOutline />
  87. </IconButton>
  88. </Grid>
  89. <Grid>
  90. <IconButton aria-label="share">
  91. <Send />
  92. </IconButton>
  93. </Grid>
  94. </Grid>
  95. <Grid sx={{ order: { xs: 1, sm: 2 } }}>
  96. <IconButton>
  97. <TurnedInNot />
  98. </IconButton>
  99. </Grid>
  100. </Grid>
  101. </Grid>
  102. </Box>
  103. </CardActions>
  104. <CardContent>
  105. Нравится: {postData.likesCount ? postData.likesCount : '0'}
  106. {/* Нравится: {postData.likesCount || '0'} // сработает или нет - проверить */}
  107. </CardContent>
  108. <Divider />
  109. <CardActions>
  110. <Box sx={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between' }}>
  111. <AccountCircle sx={{ color: 'action.active', mr: 1, my: 0.5 }} />
  112. <TextField id="input-with-sx" label="Add comment..." variant="standard" />
  113. <Send sx={{ color: 'action.active', mr: 1, my: 0.5 }} />
  114. </Box>
  115. </CardActions>
  116. </Card>
  117. )
  118. }