const TopNavigation: FC = () => {
const { opened, setOpened } = useData()
const { state: cityState } = useCityState()
const { dispatch } = useNavigationDispatch()
const { state: navigationState } = useNavigationState()
const navRef = useRef(null)
useEffect(() => {
dispatch({ type: 'setTopNavHeight', payload: { topNavHeight: navRef.current.offsetHeight } })
}, [])
return (
<Navigation
size='tiny'
fixed
dispatch={dispatch}
transparent={navigationState.transparent}
borderBottom='white'
backgroundColor={navigationState.transparent ? 'transparent' : 'slightlyGray'}
>
<Layout justifyContent='center'>
<Box
maxWidth={['90%', '90%', '1200px']}
width='100%'
height='48px'
ref={navRef}
alignSelf='center'
alignItems='center'
>
<CityPinIcon
color={navigationState.transparent ? 'white' : ''}
width='10px'
height='13px'
/>
<Layout flexBasis='8px' />
<Text
fontSize='small'
lineHeight='normal'
color={navigationState.transparent ? 'white' : 'dustyGray'}
cursor='pointer'
onClick={() => setOpened(true)}
>
{cityState.city.name}
</Text>
<Layout flexGrow={1} />
<TopBarList />
</Box>
</Layout>
<CityModal onClose={() => setOpened(false)} opened={opened} />
</Navigation>
)
}
export default TopNavigation
const reducer = (acc, val) => {
if (val.x) {
let key = val.x.slice(3); // получаем ключ вида mm.yyyy, если только mm надо, то val.x.slice(3, 5)
if (!key in acc) {
acc[key] = 0;
}
acc[key] += val.y;
}
return acc;
}
let result = array.reduce(reducer, {});
var getDatesBetweenDates = (startDate, endDate) => {
let dates = []
const theDate = new Date(startDate)
while (theDate < endDate) {
dates = [...dates, new Date(theDate)]
theDate.setDate(theDate.getDate() + 1)
}
return dates
}
(getDatesBetweenDates(new Date(2020,11,1), new Date(2020,11,7))).map((i)=>i.toLocaleString('ru',
{
day: '2-digit',
year: '2-digit',
month: '2-digit',}))