2016-09-21 06:27:11 -08:00
|
|
|
import {createSelector} from 'reselect';
|
|
|
|
|
|
2016-07-13 12:44:24 -08:00
|
|
|
import Header from '../components/header';
|
2016-11-11 08:18:04 -09:00
|
|
|
import {closeTab, changeTab, maximize, openHamburgerMenu, unmaximize, minimize, close} from '../actions/header';
|
2016-09-21 06:27:11 -08:00
|
|
|
import {connect} from '../utils/plugins';
|
2019-12-03 03:03:52 -09:00
|
|
|
import {getRootGroups} from '../selectors';
|
2023-06-26 01:29:50 -08:00
|
|
|
import type {HyperState, HyperDispatch, ITab} from '../hyper';
|
2016-07-13 12:44:24 -08:00
|
|
|
|
|
|
|
|
const isMac = /Mac/.test(navigator.userAgent);
|
|
|
|
|
|
2019-11-11 06:21:42 -09:00
|
|
|
const getSessions = ({sessions}: HyperState) => sessions.sessions;
|
|
|
|
|
const getActiveRootGroup = ({termGroups}: HyperState) => termGroups.activeRootGroup;
|
|
|
|
|
const getActiveSessions = ({termGroups}: HyperState) => termGroups.activeSessions;
|
|
|
|
|
const getActivityMarkers = ({ui}: HyperState) => ui.activityMarkers;
|
2016-07-13 12:44:24 -08:00
|
|
|
const getTabs = createSelector(
|
2016-10-03 18:00:50 -08:00
|
|
|
[getSessions, getRootGroups, getActiveSessions, getActiveRootGroup, getActivityMarkers],
|
2017-09-10 05:35:10 -08:00
|
|
|
(sessions, rootGroups, activeSessions, activeRootGroup, activityMarkers) =>
|
2021-05-10 04:54:21 -08:00
|
|
|
rootGroups.map((t): ITab => {
|
|
|
|
|
const activeSessionUid = activeSessions[t.uid];
|
|
|
|
|
const session = sessions[activeSessionUid];
|
|
|
|
|
return {
|
|
|
|
|
uid: t.uid,
|
|
|
|
|
title: session.title,
|
|
|
|
|
isActive: t.uid === activeRootGroup,
|
|
|
|
|
hasActivity: activityMarkers[session.uid]
|
|
|
|
|
};
|
|
|
|
|
})
|
2016-07-13 12:44:24 -08:00
|
|
|
);
|
|
|
|
|
|
2020-02-19 06:41:29 -09:00
|
|
|
const mapStateToProps = (state: HyperState) => {
|
|
|
|
|
return {
|
|
|
|
|
// active is an index
|
|
|
|
|
isMac,
|
|
|
|
|
tabs: getTabs(state),
|
|
|
|
|
activeMarkers: state.ui.activityMarkers,
|
|
|
|
|
borderColor: state.ui.borderColor,
|
|
|
|
|
backgroundColor: state.ui.backgroundColor,
|
|
|
|
|
maximized: state.ui.maximized,
|
|
|
|
|
fullScreen: state.ui.fullScreen,
|
|
|
|
|
showHamburgerMenu: state.ui.showHamburgerMenu,
|
|
|
|
|
showWindowControls: state.ui.showWindowControls
|
|
|
|
|
};
|
|
|
|
|
};
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2020-02-19 06:41:29 -09:00
|
|
|
const mapDispatchToProps = (dispatch: HyperDispatch) => {
|
|
|
|
|
return {
|
|
|
|
|
onCloseTab: (i: string) => {
|
|
|
|
|
dispatch(closeTab(i));
|
|
|
|
|
},
|
2016-08-06 02:01:01 -08:00
|
|
|
|
2020-02-19 06:41:29 -09:00
|
|
|
onChangeTab: (i: string) => {
|
|
|
|
|
dispatch(changeTab(i));
|
|
|
|
|
},
|
2016-08-06 02:01:01 -08:00
|
|
|
|
2020-02-19 06:41:29 -09:00
|
|
|
maximize: () => {
|
|
|
|
|
dispatch(maximize());
|
|
|
|
|
},
|
2016-11-11 08:18:04 -09:00
|
|
|
|
2020-02-19 06:41:29 -09:00
|
|
|
unmaximize: () => {
|
|
|
|
|
dispatch(unmaximize());
|
|
|
|
|
},
|
2016-11-11 08:18:04 -09:00
|
|
|
|
2020-02-19 06:41:29 -09:00
|
|
|
openHamburgerMenu: (coordinates: {x: number; y: number}) => {
|
|
|
|
|
dispatch(openHamburgerMenu(coordinates));
|
|
|
|
|
},
|
2016-11-11 08:18:04 -09:00
|
|
|
|
2020-02-19 06:41:29 -09:00
|
|
|
minimize: () => {
|
|
|
|
|
dispatch(minimize());
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
close: () => {
|
|
|
|
|
dispatch(close());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const HeaderContainer = connect(mapStateToProps, mapDispatchToProps, null)(Header, 'Header');
|
|
|
|
|
|
|
|
|
|
export type HeaderConnectedProps = ReturnType<typeof mapStateToProps> & ReturnType<typeof mapDispatchToProps>;
|