1- import React from 'react' ;
1+ import React , { useState } from 'react' ;
22import { FormattedMessage } from 'react-intl' ;
33import Link from 'components/common/Link' ;
44import WebsiteChart from 'components/metrics/WebsiteChart' ;
55import Page from 'components/layout/Page' ;
66import EmptyPlaceholder from 'components/common/EmptyPlaceholder' ;
7+ import Button from 'components/common/Button' ;
78import useFetch from 'hooks/useFetch' ;
89import Arrow from 'assets/arrow-right.svg' ;
10+ import Chart from 'assets/chart-bar.svg' ;
911import styles from './WebsiteList.module.css' ;
1012
1113export default function WebsiteList ( { userId } ) {
1214 const { data } = useFetch ( '/api/websites' , { params : { user_id : userId } } ) ;
15+ const [ hideCharts , setHideCharts ] = useState ( false ) ;
1316
1417 if ( ! data ) {
1518 return null ;
1619 }
1720
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 >
2624 < EmptyPlaceholder
2725 msg = {
2826 < FormattedMessage
@@ -35,7 +33,26 @@ export default function WebsiteList({ userId }) {
3533 < FormattedMessage id = "message.go-to-settings" defaultMessage = "Go to settings" />
3634 </ Link >
3735 </ 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+ ) ) }
3956 </ Page >
4057 ) ;
4158}
0 commit comments