@@ -6,10 +6,14 @@ import Bar from "../../charts/Bar";
6
6
import { ImplementedChartProps } from "../types" ;
7
7
import ChartCard from "../../ChartCard" ;
8
8
import LoadingImplementedChart from "../LoadingImplementedChart" ;
9
- import { selectRawIntervalDetail } from "../../../services/redux/modules/user/selector" ;
9
+ import {
10
+ selectRawIntervalDetail ,
11
+ selectStatMeasurement ,
12
+ } from "../../../services/redux/modules/user/selector" ;
10
13
import Tooltip from "../../Tooltip" ;
11
14
import { TitleFormatter , ValueFormatter } from "../../Tooltip/Tooltip" ;
12
15
import { DateFormatter } from "../../../services/date" ;
16
+ import { msToMinutes } from "../../../services/stats" ;
13
17
14
18
interface ListeningRepartitionProps extends ImplementedChartProps { }
15
19
@@ -21,6 +25,7 @@ const tooltipTitle: TitleFormatter<unknown[]> = ({ x }) =>
21
25
export default function ListeningRepartition ( {
22
26
className,
23
27
} : ListeningRepartitionProps ) {
28
+ const measurement = useSelector ( selectStatMeasurement ) ;
24
29
const { interval } = useSelector ( selectRawIntervalDetail ) ;
25
30
const result = useAPI ( api . timePerHourOfDay , interval . start , interval . end ) ;
26
31
@@ -49,14 +54,25 @@ export default function ListeningRepartition({
49
54
) ;
50
55
51
56
const tooltipValue = useCallback < ValueFormatter < typeof data > > (
52
- ( payload , value ) => (
53
- < div >
54
- { `${ value } % of your daily listening` }
55
- < br />
56
- { `${ payload . count } out of ${ total } songs` }
57
- </ div >
58
- ) ,
59
- [ total ] ,
57
+ ( payload , value ) => {
58
+ if ( measurement === "number" ) {
59
+ return (
60
+ < div >
61
+ { `${ value } % of your daily listening` }
62
+ < br />
63
+ { `${ payload . count } out of ${ total } songs` }
64
+ </ div >
65
+ ) ;
66
+ }
67
+ return (
68
+ < div >
69
+ { `${ value } % of your daily listening` }
70
+ < br />
71
+ { `${ msToMinutes ( payload . count ) } out of ${ msToMinutes ( total ) } minutes` }
72
+ </ div >
73
+ ) ;
74
+ } ,
75
+ [ measurement , total ] ,
60
76
) ;
61
77
62
78
if ( ! result ) {
0 commit comments