-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
HeaderView.js
135 lines (124 loc) · 5.42 KB
/
HeaderView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import React from 'react';
import {View, Pressable} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import styles from '../../styles/styles';
import ONYXKEYS from '../../ONYXKEYS';
import themeColors from '../../styles/themes/default';
import Icon from '../../components/Icon';
import {BackArrow, Pin} from '../../components/Icon/Expensicons';
import compose from '../../libs/compose';
import {togglePinnedState} from '../../libs/actions/Report';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../components/withWindowDimensions';
import MultipleAvatars from '../../components/MultipleAvatars';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import {getReportParticipantsTitle} from '../../libs/reportUtils';
import OptionRowTitle from './sidebar/OptionRowTitle';
import {getPersonalDetailsForLogins} from '../../libs/OptionsListUtils';
import {participantPropTypes} from './sidebar/optionPropTypes';
import VideoChatButtonAndMenu from '../../components/VideoChatButtonAndMenu';
import IOUBadge from '../../components/IOUBadge';
const propTypes = {
// Toggles the navigationMenu open and closed
onNavigationMenuButtonClicked: PropTypes.func.isRequired,
/* Onyx Props */
// The report currently being looked at
report: PropTypes.shape({
// Name of the report
reportName: PropTypes.string,
// List of primarylogins of participants of the report
participants: PropTypes.arrayOf(PropTypes.string),
// ID of the report
reportID: PropTypes.number,
// Value indicating if the report is pinned or not
isPinned: PropTypes.bool,
}),
// Personal details of all the users
personalDetails: PropTypes.objectOf(participantPropTypes).isRequired,
...windowDimensionsPropTypes,
};
const defaultProps = {
report: null,
};
const HeaderView = (props) => {
const participants = lodashGet(props.report, 'participants', []);
const reportOption = {
text: lodashGet(props.report, 'reportName', ''),
tooltipText: getReportParticipantsTitle(participants),
participantsList: getPersonalDetailsForLogins(participants, props.personalDetails),
};
return (
<View style={[styles.appContentHeader]} nativeID="drag-area">
<View style={[styles.appContentHeaderTitle, !props.isSmallScreenWidth && styles.pl5]}>
{props.isSmallScreenWidth && (
<Pressable
onPress={props.onNavigationMenuButtonClicked}
style={[styles.LHNToggle]}
>
<Icon src={BackArrow} />
</Pressable>
)}
{props.report && props.report.reportName && (
<View
style={[
styles.flex1,
styles.flexRow,
styles.alignItemsCenter,
styles.justifyContentBetween,
]}
>
<Pressable
onPress={() => {
if (participants.length === 1) {
Navigation.navigate(ROUTES.getDetailsRoute(participants[0]));
}
}}
style={[styles.flexRow, styles.alignItemsCenter, styles.flex1]}
>
<MultipleAvatars
avatarImageURLs={props.report.icons}
secondAvatarStyle={[styles.secondAvatarHovered]}
/>
<View style={[styles.flex1, styles.flexRow]}>
<OptionRowTitle
option={reportOption}
tooltipEnabled
numberOfLines={1}
style={[styles.headerText]}
/>
</View>
</Pressable>
<View style={[styles.reportOptions, styles.flexRow, styles.alignItemsCenter]}>
{props.report.hasOutstandingIOU && (
<IOUBadge iouReportID={props.report.iouReportID} />
)}
<VideoChatButtonAndMenu />
<Pressable
onPress={() => togglePinnedState(props.report)}
style={[styles.touchableButtonImage, styles.mr0]}
>
<Icon src={Pin} fill={props.report.isPinned ? themeColors.heading : themeColors.icon} />
</Pressable>
</View>
</View>
)}
</View>
</View>
);
};
HeaderView.propTypes = propTypes;
HeaderView.displayName = 'HeaderView';
HeaderView.defaultProps = defaultProps;
export default compose(
withWindowDimensions,
withOnyx({
report: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
},
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
}),
)(HeaderView);