-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathTab.js
87 lines (74 loc) · 2.12 KB
/
Tab.js
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
import React, {useCallback, useContext, useEffect, useState} from 'react';
import {Tabs} from '@shopify/polaris';
import {useLocation, useNavigate, useParams} from "react-router-dom";
import * as R from "ramda";
import {UserContext} from "./App";
function Tab({items, total, selected, setSelected}) {
const user = useContext(UserContext);
const params = useParams();
const navigate = useNavigate();
const location = useLocation();
const useQuery = () => new URLSearchParams(location.search);
const query = useQuery();
const handleTabChange = useCallback(
(selectedTabIndex) => {
setSelected(selectedTabIndex);
let p = query.get("p");
if (R.isNil(p)) {
p = 1;
}
const kw = user.kw;
user.loading = true;
navigate(`/items?kw=${kw}&p=${p}&t=${tabs[selectedTabIndex].id.toUpperCase()}`);
},
[],
);
// useEffect(() => {
// console.log(123)
// }, [selected]);
const tabs = [
{
id: 'All',
content: 'All',
accessibilityLabel: 'All',
panelID: 'All',
},
{
id: 'Group',
content: 'Group',
panelID: 'Group',
},
{
id: 'Channel',
content: 'Channel',
panelID: 'Channel',
},
{
id: 'Message',
content: 'Chat',
panelID: 'Message',
},
{
id: 'Bot',
content: 'Bot',
panelID: 'Bot',
},
];
const [isSmallScreen, setIsSmallScreen] = useState(false);
useEffect(() => {
function handleResize() {
setIsSmallScreen(window.innerWidth < 768);
}
window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
};
}, []);
return (
<div>
<Tabs fitted={isSmallScreen} tabs={tabs} selected={selected} onSelect={handleTabChange}>
</Tabs>
</div>
);
}
export default Tab