|
1 | 1 | import { Box } from '@mui/system' |
2 | 2 | import React from 'react' |
| 3 | +import Highlighter from 'react-highlight-words' |
3 | 4 | import { News } from '../../../types' |
| 5 | +import { useAppSelector } from '../../hooks/storeHooks' |
| 6 | +import { selectSearchRequest } from '../../store/storeSlices/searchSlice' |
4 | 7 | import { StyledTypography } from '../../styles/styledComponents' |
5 | 8 |
|
6 | 9 | export const CardDescription: React.FC<Props> = ({ newsData }) => { |
| 10 | + const searchRequest = atob(useAppSelector(selectSearchRequest)).split(' ') |
| 11 | + const description = getDescription(newsData) |
| 12 | + |
7 | 13 | return ( |
8 | 14 | <Box> |
9 | | - <StyledTypography |
10 | | - sx={{ fontSize: '24px', fontWeight: '400', lineHeight: '29px', marginY: '20px' }} |
11 | | - > |
12 | | - {getTitle(newsData)} |
13 | | - </StyledTypography> |
14 | | - |
15 | 15 | <StyledTypography sx={{ marginBottom: '20px', fontWeight: 400, lineHeight: '24px' }}> |
16 | | - {getDescription(newsData)} |
| 16 | + <Highlighter |
| 17 | + searchWords={searchRequest} |
| 18 | + autoEscape={true} |
| 19 | + textToHighlight={description} |
| 20 | + highlightStyle={{ backgroundColor: '#fff619a1' }} |
| 21 | + /> |
17 | 22 | </StyledTypography> |
18 | 23 | </Box> |
19 | 24 | ) |
20 | 25 | } |
21 | 26 |
|
22 | | -const getTitle = (newsData: News) => { |
23 | | - if (newsData.title.length > 37) { |
24 | | - return `${newsData.title.split('-')[0].slice(0, 37)}...` |
25 | | - } |
26 | | - return newsData.title |
27 | | -} |
28 | | - |
29 | 27 | const getDescription = (newsData: News) => { |
30 | | - if (newsData.description && newsData.description.length > 139) { |
31 | | - return `${newsData.description.slice(0, 139)}...` |
| 28 | + if (newsData.summary && newsData.summary.length > 100) { |
| 29 | + return `${newsData.summary.slice(0, 100)}...` |
32 | 30 | } |
33 | | - return newsData.description |
| 31 | + return newsData.summary |
34 | 32 | } |
35 | 33 |
|
36 | 34 | type Props = { |
|
0 commit comments