-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathChannelCategories.tsx
More file actions
122 lines (115 loc) · 3.26 KB
/
ChannelCategories.tsx
File metadata and controls
122 lines (115 loc) · 3.26 KB
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
import { FC, useRef } from 'react';
import { Box, Button, CaretLeft, CaretRight, Pill, Skeleton } from 'blocks';
import { css } from 'styled-components';
import { useGetChannelCategories } from 'queries';
import { Filters } from '../hooks/useChannelsFilters';
import { AllCategories, subscribedCategory } from '../Channels.constants';
import { appConfig } from 'config';
export type ChannelCategoriesProps = {
filters: Filters;
setFilter: (filter: Partial<Filters>) => void;
walletAddress: string | null;
};
const scrollAmount = 150;
const ChannelCategories: FC<ChannelCategoriesProps> = ({ filters, setFilter, walletAddress }) => {
const categoryContainerRef = useRef<HTMLDivElement>(null);
const { data, isLoading } = useGetChannelCategories();
const channelCategories = isLoading ? Array(15).fill(0) : data?.tags || [];
return (
<Box
display="flex"
alignItems="center"
css={css`
flex-shrink: 0;
`}
gap="spacing-xs"
maxWidth={{ mm: '346px', ml: '392px' }}
position="relative"
>
<Box
backgroundColor="surface-primary"
css={css`
position: absolute;
`}
borderRadius="radius-round"
>
<Button
iconOnly={<CaretLeft />}
circular
variant="outline"
size="small"
onClick={() => {
categoryContainerRef?.current?.scrollBy({
left: -scrollAmount,
behavior: 'smooth',
});
}}
/>
</Box>
<Box
display="flex"
overflow="hidden"
gap="spacing-xs"
width="100%"
ref={categoryContainerRef}
padding="spacing-none spacing-xxl"
>
{!isLoading && (
<>
<Pill
isActive={filters.category === AllCategories}
onClick={() => setFilter({ category: AllCategories })}
>
{AllCategories}
</Pill>
{walletAddress && (
<Pill
isActive={filters.category === subscribedCategory}
onClick={() => setFilter({ category: subscribedCategory })}
>
{subscribedCategory}
</Pill>
)}
</>
)}
{channelCategories.map((cat, index) => (
<Skeleton
isLoading={isLoading}
width="200px"
borderRadius="radius-round"
>
<Pill
key={`${index}`}
isActive={cat === filters.category}
onClick={() => setFilter({ category: cat, search: '', chain: appConfig.coreContractChain.toString() })}
>
{cat}
</Pill>
</Skeleton>
))}
</Box>
<Box
backgroundColor="surface-primary"
css={css`
position: absolute;
right: 0;
`}
borderRadius="radius-round"
>
<Button
iconOnly={<CaretRight />}
circular
variant="outline"
size="small"
onClick={() => {
categoryContainerRef?.current?.scrollBy({
left: scrollAmount,
behavior: 'smooth',
});
}}
/>
</Box>
</Box>
);
};
export { ChannelCategories };