This repository was archived by the owner on Aug 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathAnalyticsPage.tsx
183 lines (175 loc) · 6.16 KB
/
AnalyticsPage.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import { Card, CardContent, CardHeader, useTheme } from '@material-ui/core';
import Grid from '@material-ui/core/Grid';
import { ErrorBox } from '@shared/components/Error/ErrorBox';
import { ContentCreator } from '@shared/models/ContentCreator';
import { Taboule } from '@taboule/components/Taboule';
import * as QR from 'avenger/lib/QueryResult';
import { declareQueries, WithQueries } from 'avenger/lib/react';
import { pipe } from 'fp-ts/lib/function';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { config } from '../../../config';
import {
ccRelatedUsers,
profile,
} from '../../../state/dashboard/creator.queries';
import { makeStyles } from '../../../theme';
import { LazyFullSizeLoader } from '../../common/FullSizeLoader';
import { LinkAccountButton } from '../../common/LinkAccountButton';
import { StatsCard } from '../../common/StatsCard';
import { ADVChannelStatsBox } from './ADVChannelStatsBox';
import { DonutChart } from './DonutChart';
const useStyles = makeStyles((theme) => ({
recommendabilityScore: {
background: theme.palette.primary.main,
borderRadius: theme.spacing(1),
'& .MuiCardHeader-content .MuiCardHeader-title': {
color: theme.palette.common.white,
...theme.typography.h4,
},
'& .MuiCardHeader-content .MuiCardHeader-subheader': {
color: theme.palette.common.white,
...theme.typography.h6,
},
},
relatedChannels: {
boxShadow: 'none',
background: 'transparent',
'& .MuiCardHeader-content .MuiCardHeader-title': {
color: theme.palette.primary.main,
...theme.typography.h4,
},
'& .MuiCardHeader-content .MuiCardHeader-subheader': {
color: theme.palette.primary.main,
...theme.typography.h6,
},
},
recommendations: {
boxShadow: 'none',
background: 'transparent',
'& .MuiCardHeader-content .MuiCardHeader-title': {
color: theme.palette.primary.main,
...theme.typography.h4,
},
'& .MuiCardHeader-content .MuiCardHeader-subheader': {
color: theme.palette.primary.main,
...theme.typography.h6,
},
},
}));
interface CreatorAnalyticsPageProps {
profile?: ContentCreator;
}
const CreatorAnalyticsPage: React.FC<CreatorAnalyticsPageProps> = ({
profile,
}) => {
const classes = useStyles();
const theme = useTheme();
const { t } = useTranslation();
const amount = 25;
return (
<Grid item md={12}>
{profile === undefined ? (
<LinkAccountButton />
) : (
<WithQueries
queries={{ stats: ccRelatedUsers }}
params={{ stats: { params: { amount, skip: 0 } } }}
render={QR.fold(LazyFullSizeLoader, ErrorBox, ({ stats }) => {
return (
<Grid container spacing={2}>
<Grid item md={3} sm={6}>
<Card className={classes.recommendations}>
<CardHeader title={t('analytics:recommendations_title')} />
<CardContent>
<Grid
container
direction="column"
alignContent="flex-start"
justifyContent="center"
>
<Grid item sm={12}>
<StatsCard
header={t('analytics:total_recommendations')}
count={stats.totalRecommendations}
/>
</Grid>
<Grid item sm={12}>
<StatsCard
header={t('analytics:total_contributions')}
count={stats.totalContributions}
color={theme.palette.primary.main}
/>
</Grid>
</Grid>
</CardContent>
</Card>
</Grid>
<Grid item md={4}>
<Card className={classes.recommendabilityScore}>
<CardHeader
title={t('analytics:recommendability_score_title')}
subheader={t('analytics:recommendability_score_subtitle')}
/>
<CardContent>
<DonutChart
id="creator-recommendations-score"
title={`${stats.score}%`}
data={{
recommended: [stats.score],
other: [100 - stats.score],
}}
colors={{
recommended: theme.palette.common.white,
other: theme.palette.grey[300],
}}
/>
</CardContent>
</Card>
</Grid>
<Grid item md={5}>
<Card className={classes.relatedChannels}>
<CardHeader
title={t('analytics:top_n_cc_related_to_your_channel', {
count: amount,
})}
/>
<CardContent style={{ paddingTop: 0 }}>
<Taboule
height={500}
showInput={false}
query="ccRelatedUsers"
baseURL={config.API_URL}
initialParams={{
channelId: profile.channelId,
}}
/>
</CardContent>
</Card>
</Grid>
<Grid item md={12}>
<ADVChannelStatsBox />
</Grid>
</Grid>
);
})}
/>
)}
</Grid>
);
};
const withQueries = declareQueries({ profile });
export const AnalyticsPage = withQueries(({ queries }): React.ReactElement => {
return pipe(
queries,
QR.fold(LazyFullSizeLoader, ErrorBox, ({ profile }) => {
return (
<Grid container spacing={3}>
<Grid item md={12}>
<CreatorAnalyticsPage profile={profile} />
</Grid>
</Grid>
);
})
);
});