1
- import React from 'react' ;
1
+ import React , { useState } from 'react' ;
2
2
import { FormattedMessage } from 'react-intl' ;
3
3
import Link from 'components/common/Link' ;
4
4
import WebsiteChart from 'components/metrics/WebsiteChart' ;
5
5
import Page from 'components/layout/Page' ;
6
6
import EmptyPlaceholder from 'components/common/EmptyPlaceholder' ;
7
+ import Button from 'components/common/Button' ;
7
8
import useFetch from 'hooks/useFetch' ;
8
9
import Arrow from 'assets/arrow-right.svg' ;
10
+ import Chart from 'assets/chart-bar.svg' ;
9
11
import styles from './WebsiteList.module.css' ;
10
12
11
13
export default function WebsiteList ( { userId } ) {
12
14
const { data } = useFetch ( '/api/websites' , { params : { user_id : userId } } ) ;
15
+ const [ hideCharts , setHideCharts ] = useState ( false ) ;
13
16
14
17
if ( ! data ) {
15
18
return null ;
16
19
}
17
20
18
- return (
19
- < Page >
20
- { data . map ( ( { website_id, name, domain } ) => (
21
- < div key = { website_id } className = { styles . website } >
22
- < WebsiteChart websiteId = { website_id } title = { name } domain = { domain } showLink />
23
- </ div >
24
- ) ) }
25
- { data . length === 0 && (
21
+ if ( data . length === 0 ) {
22
+ return (
23
+ < Page >
26
24
< EmptyPlaceholder
27
25
msg = {
28
26
< FormattedMessage
@@ -35,7 +33,26 @@ export default function WebsiteList({ userId }) {
35
33
< FormattedMessage id = "message.go-to-settings" defaultMessage = "Go to settings" />
36
34
</ Link >
37
35
</ EmptyPlaceholder >
38
- ) }
36
+ </ Page >
37
+ ) ;
38
+ }
39
+
40
+ return (
41
+ < Page >
42
+ < div className = { styles . menubar } >
43
+ < Button icon = { < Chart /> } onClick = { ( ) => setHideCharts ( ! hideCharts ) } />
44
+ </ div >
45
+ { data . map ( ( { website_id, name, domain } ) => (
46
+ < div key = { website_id } className = { styles . website } >
47
+ < WebsiteChart
48
+ websiteId = { website_id }
49
+ title = { name }
50
+ domain = { domain }
51
+ hideChart = { hideCharts }
52
+ showLink
53
+ />
54
+ </ div >
55
+ ) ) }
39
56
</ Page >
40
57
) ;
41
58
}
0 commit comments