-
Notifications
You must be signed in to change notification settings - Fork 12
/
UserHomeTabs.jsx
131 lines (118 loc) · 3.59 KB
/
UserHomeTabs.jsx
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
import React from 'react';
import { Tabs, Tab, AppBar, CircularProgress } from '@material-ui/core';
import {
List as ListIcon,
Loyalty as LoyaltyIcon,
Home as HomeIcon,
} from '@material-ui/icons';
import { isEmpty } from 'lodash';
import { WHITE, GREEN, ORANGE } from '../../common/constants';
import Search from '../search/Search';
const HEIGHT = '50px'
const ICON_STYLES = {marginRight: '10px', marginBottom: '0px'}
const TAB_STYLES = {minHeight: HEIGHT, paddingTop: '6px', height: HEIGHT}
const UserHomeTabs = props => {
const { tab, user, onTabChange } = props;
const indicatorColorClass = () => {
if(tab == 2)
return 'bg-orange'
return 'bg-green'
}
const getIconStyles = (index, color) => {
const styles = {...ICON_STYLES}
if(tab === index)
return {color: color, ...styles}
return styles
}
const getTabStyles = (index, color) => {
const styles = {...TAB_STYLES}
if(tab === index)
return {color: color, ...styles}
return styles
}
const loaded = !isEmpty(user)
return (
<div className='col-md-12'>
<AppBar position="static" color="default" style={{backgroundColor: WHITE, boxShadow: 'none'}}>
<Tabs
value={tab}
onChange={onTabChange}
indicatorColor="primary"
textColor="primary"
variant="fullWidth"
style={{height: HEIGHT}}
classes={{
indicator: indicatorColorClass()
}}
>
<Tab
className='material-tab'
label="User Sources"
icon={<ListIcon fontSize='small' style={getIconStyles(0, GREEN)} />}
style={getTabStyles(0, GREEN)}
/>
<Tab
className='material-tab'
label="User Collections"
icon={<LoyaltyIcon fontSize='small' style={getIconStyles(1, GREEN)} />}
style={getTabStyles(1, GREEN)}
/>
<Tab
className='material-tab'
label="Organization Membership"
icon={<HomeIcon fontSize='small' style={getIconStyles(2, ORANGE)} />}
style={getTabStyles(2, ORANGE)}
/>
</Tabs>
</AppBar>
<div className='sub-tab-container' style={{display: 'flex', minHeight: '500px'}}>
{
tab === 0 &&
(
loaded ?
<Search
{...props}
nested={true}
baseURL={user.sources_url}
fixedFilters={{isTable: true, limit: 25}}
resource="sources"
searchInputPlaceholder={`Search ${user.username} sources...`}
/> :
<CircularProgress color="primary" />
)
}
{
tab === 1 &&
(
loaded ?
<Search
{...props}
nested={true}
baseURL={user.collections_url}
fixedFilters={{isTable: true, limit: 25}}
resource="collections"
searchInputPlaceholder={`Search ${user.username} collections...`}
/> :
<CircularProgress color="primary" />
)
}
{
tab === 2 &&
(
loaded ?
<Search
{...props}
nested={true}
baseURL={user.organizations_url}
fixedFilters={{isTable: true, limit: 25}}
resource="organizations"
searchInputPlaceholder={`Search ${user.username} organizations...`}
/> :
<CircularProgress color="primary" />
)
}
</div>
</div>
)
}
export default UserHomeTabs;