-
Notifications
You must be signed in to change notification settings - Fork 79
/
TopicsPage.tsx
138 lines (126 loc) · 4.19 KB
/
TopicsPage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import React, { useState } from 'react';
import { Grid, InputBase, Paper } from '@mui/material';
import SearchIcon from '@mui/icons-material/Search';
import { styled } from '@mui/material/styles';
import { ReactSelect as Select } from 'components/common';
import { motivationOptions, shuffleTopics as topics } from 'data';
import TopicCard from 'components/TopicCard';
import InfiniteScroll from 'react-infinite-scroll-component';
import { motivationState, tabIndexState, topicState } from 'store';
import { useRecoilState, useSetRecoilState } from 'recoil';
import { Topic } from 'types';
import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
const LEN = 8;
const SearchWrapper = styled(Grid)({
'.search_wrapper': {
display: 'flex',
alignItems: 'center',
},
});
const TextAreaWrapper = styled(Paper)({
marginLeft: '16px',
padding: '2px 4px',
display: 'flex',
alignItems: 'center',
backgroundColor: 'black !important',
width: 400,
'.Search_Input': {
fontSize: '20px',
padding: '0px 6px',
width: '100%',
},
});
const CardContainer = styled(Grid)({
// Display: 'flex',
// flexDirection: 'row',
// justifyContent: 'space-around',
display: 'grid',
gridTemplateColumns: 'repeat(auto-fill, 320px)',
justifyContent: 'space-between',
marginTop: '3rem',
});
const filterTopics = (topics_: Topic[], motivation: string) => {
if (motivation === 'All' || motivation === null) return topics_;
return topics.filter((topic) => topic.motivation === motivation);
};
const MentorsPage = () => {
const [motivation, setMotivation] = useRecoilState(motivationState);
const setTabIndex = useSetRecoilState(tabIndexState);
const setTopic = useSetRecoilState(topicState);
const [search, setSearch] = useState('');
const [items, setItems] = useState(topics.slice(0, LEN));
const theme = useTheme();
const matches = useMediaQuery(theme.breakpoints.up('md'));
// @ts-ignore
const motivationValue = motivation ? motivation?.value : 'All';
const fetchMoreData = () => {
const n = items.length;
setTimeout(() => {
setItems(topics.slice(0, n + LEN));
}, 300);
};
return (
<div style={{ padding: '0rem 2rem' }}>
<SearchWrapper container spacing={2}>
<Grid item xs={10} sm={4} className="search_wrapper">
<TextAreaWrapper>
<SearchIcon sx={{ color: 'darkgrey' }} />
<InputBase
value={search}
onChange={(e) => {
setSearch(e.target.value);
setItems(
topics.filter((item) =>
item.topicName.includes(e.target.value),
),
);
}}
className="Search_Input"
placeholder="Search by Topics"
inputProps={{ 'aria-label': 'Search by Topics' }}
/>
</TextAreaWrapper>
</Grid>
<Grid item xs={12} sm={4} lg={3} className="search_wrapper">
<Paper
sx={{ display: 'flex', minWidth: '240px', marginLeft: '16px' }}>
<Select
menuPlacement="auto"
name="Motivation"
sx={{ fontSize: '20px' }}
options={motivationOptions}
value={motivation}
onChange={setMotivation}
isSearchable={matches}
classNamePrefix="select"
placeholder={<span>Filter by Motivation</span>}
/>
</Paper>
</Grid>
</SearchWrapper>
<InfiniteScroll
dataLength={Math.min(topics.length, items.length)}
next={fetchMoreData}
hasMore={
filterTopics(items, motivationValue).length <
filterTopics(topics, motivationValue).length
}
loader={<h4>Loading...</h4>}>
<CardContainer container>
{filterTopics(items, motivationValue).map((item, index) => (
<div
key={index}
onClick={() => {
setTopic(index);
setTabIndex('1');
}}>
<TopicCard topic={item} />
</div>
))}
</CardContainer>
</InfiniteScroll>
</div>
);
};
export default MentorsPage;