|
| 1 | +import { useTrendingTags } from '@/hooks' |
1 | 2 | import { |
2 | 3 | List, |
3 | 4 | ListItem, |
4 | 5 | ListItemText, |
5 | 6 | Typography, |
6 | | - Box, |
7 | | - Paper |
| 7 | + Paper, |
| 8 | + CircularProgress |
8 | 9 | } from '@mui/material' |
9 | | -import { Link, useNavigate } from 'react-router' |
| 10 | +import { Link } from 'react-router' |
10 | 11 |
|
11 | | -const TrendingTags = ({ tags }) => { |
12 | | - const navigate = useNavigate() |
| 12 | +const TrendingTags = () => { |
| 13 | + const { data: tags, isLoading } = useTrendingTags() |
13 | 14 | return ( |
14 | 15 | <Paper sx={{ p: 2 }} role="presentation" elevation={0}> |
15 | 16 | <Typography variant="h6" gutterBottom> |
16 | 17 | Trending Topics |
17 | 18 | </Typography> |
18 | | - <List sx={{ p: 0 }}> |
19 | | - {tags.map((tag) => ( |
20 | | - <ListItem |
21 | | - key={tag.hashtag} |
22 | | - to={`/hashtag/${tag.hashtag}`} |
23 | | - sx={{ |
24 | | - cursor: 'pointer', |
25 | | - ':hover': { |
26 | | - bgcolor: 'primary.main', |
27 | | - transition: 'background-color 0.2s' |
28 | | - }, |
29 | | - p: 0.5, |
30 | | - px: 1, |
31 | | - textDecoration: 'none', |
32 | | - color: 'inherit', |
33 | | - borderRadius: 1 |
34 | | - }} |
35 | | - component={Link} |
36 | | - > |
37 | | - <ListItemText |
38 | | - primary={`#${tag.hashtag}`} |
39 | | - secondary={`${tag.count} posts`} |
40 | | - primaryTypographyProps={{ |
41 | | - fontWeight: 'medium' |
42 | | - }} |
43 | | - secondaryTypographyProps={{ |
44 | | - fontSize: '0.8rem', |
45 | | - color: 'text.muted' |
46 | | - }} |
47 | | - /> |
48 | | - </ListItem> |
49 | | - ))} |
50 | | - </List> |
| 19 | + {isLoading ? ( |
| 20 | + <CircularProgress size={20} /> |
| 21 | + ) : ( |
| 22 | + <TagsList tags={tags} /> |
| 23 | + )} |
51 | 24 | </Paper> |
52 | 25 | ) |
53 | 26 | } |
54 | 27 |
|
| 28 | +const TagsList = ({ tags }) => { |
| 29 | + return ( |
| 30 | + <List sx={{ p: 0 }}> |
| 31 | + {tags.map((tag) => ( |
| 32 | + <ListItem |
| 33 | + key={tag.hashtag} |
| 34 | + to={`/hashtag/${tag.hashtag}`} |
| 35 | + sx={{ |
| 36 | + cursor: 'pointer', |
| 37 | + ':hover': { |
| 38 | + bgcolor: 'primary.main', |
| 39 | + transition: 'background-color 0.2s' |
| 40 | + }, |
| 41 | + p: 0.5, |
| 42 | + px: 1, |
| 43 | + textDecoration: 'none', |
| 44 | + color: 'inherit', |
| 45 | + borderRadius: 1 |
| 46 | + }} |
| 47 | + component={Link} |
| 48 | + > |
| 49 | + <ListItemText |
| 50 | + primary={`#${tag.hashtag}`} |
| 51 | + secondary={`${tag.count} posts`} |
| 52 | + primaryTypographyProps={{ |
| 53 | + fontWeight: 'medium' |
| 54 | + }} |
| 55 | + secondaryTypographyProps={{ |
| 56 | + fontSize: '0.8rem', |
| 57 | + color: 'text.muted' |
| 58 | + }} |
| 59 | + /> |
| 60 | + </ListItem> |
| 61 | + ))} |
| 62 | + </List> |
| 63 | + ) |
| 64 | +} |
55 | 65 | export default TrendingTags |
0 commit comments