import React, { useState } from 'react'; import { useSelector } from 'react-redux'; import { createDashboardIsLoadingSelector, getCurrentVesselsStatusSorted, getRecentVesselsStatusSorted, } from 'app/modules/dashboard/store/dashboard.selectors'; import datePipe from 'app/shared/pipes/date.pipe'; import { DashboardVesselListLabel } from 'app/modules/dashboard/components/dashboardVesselListLabel'; import HoverInfo from 'app/shared/components/hoverInfo/hoverInfo'; import { DashboardVesselListItem } from 'app/modules/dashboard/components/dashboardVesselListItem'; import { Spinner } from 'app/shared/components/spinner/spinner'; import { DASHBOARD } from 'app/modules/dashboard/store/dashboard.constants'; import { Headline } from 'app/shared/components/text/text'; import cx from 'classnames'; const getHoverTooltip = (isCurrentSelected) => {isCurrentSelected ? 'Earnings for the current voyage $/day' : 'Average pool earnings $/day'} ; const getConsumptionTooltip = (recentDate: string | null = null) => ( {!recentDate ? 'Total consumption from voyage start until today\'s date' : `Total consumption for ${datePipe.formatLongMonthWithYear(recentDate)}`} ); const getCO2Tooltip = (recentDate: string | null = null) => ( {!recentDate ? 'Total CO2 emission from voyage start until today\'s date' : `Total CO2 emission for ${datePipe.formatLongMonthWithYear(recentDate)}`} ); const getVoyageDaysTooltip = () => ( Number of days from voyage start until today's date ); const getVesselListTooltip = () => The list below includes all vessels that have been active in our pools during the last month ; export const DashboardVesselList = () => { const [ selectedRecentMonth, setSelectedRecentMonth ] = useState(null); const recentVesselsStatus = useSelector(getRecentVesselsStatusSorted); const currentVesselsStatus = useSelector(getCurrentVesselsStatusSorted); const dashboardFetchCollectionSelector = [ DASHBOARD.FETCH_CURRENT_VESSELS_STATUS_SELECTOR ]; const loadingStatus = useSelector(createDashboardIsLoadingSelector(dashboardFetchCollectionSelector)); const listLabelClass = cx('c-dashboard-vessel-list__item', { 'c-dashboard-vessel-list__item--previous-period': selectedRecentMonth }); const hooverTooltipsData = { earnings: getHoverTooltip(!selectedRecentMonth), consumption: getConsumptionTooltip(selectedRecentMonth), co2Emission: getCO2Tooltip(selectedRecentMonth), voyageDays: getVoyageDaysTooltip(), }; const unselectRecentMonth = () => { if (selectedRecentMonth) { setSelectedRecentMonth(null); } }; const selectRecentMonth = (date) => { if (!selectedRecentMonth) { setSelectedRecentMonth(date); } }; const recentMonths = recentVesselsStatus?.filter(item => item.date).map((item, index) => (
  • )); return
    Your Vessels
    • { recentMonths }
    { !selectedRecentMonth &&
    }
    {!selectedRecentMonth && (loadingStatus ? : currentVesselsStatus?.map(vesselStatus => )) } {selectedRecentMonth && recentVesselsStatus.find(item => item.date === selectedRecentMonth)?.summaries?.map(vesselStatus => ) }
    ; };