Skip to content

Commit

Permalink
Merge pull request #781 from Expensify/alberto-draftsPinned
Browse files Browse the repository at this point in the history
Keep chats with draft comments in the LHN
  • Loading branch information
tgolen authored Dec 1, 2020
2 parents 207056a + 974e2e3 commit 8ccd76e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
Binary file added assets/images/icon-pencil.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions src/pages/home/sidebar/ChatLinkRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import styles, {colors} from '../../../styles/StyleSheet';
import ChatSwitcherOptionPropTypes from './ChatSwitcherOptionPropTypes';
import ROUTES from '../../../ROUTES';
import pencilIcon from '../../../../assets/images/icon-pencil.png';
import PressableLink from '../../../components/PressableLink';

const propTypes = {
Expand Down Expand Up @@ -87,9 +88,9 @@ const ChatLinkRow = ({
)
}
<View style={[styles.flex1]}>
{option.text === option.alternateText ? (
{(option.text === option.alternateText || option.alternateText.length === 0) ? (
<Text style={[styles.chatSwitcherDisplayName, textUnreadStyle]} numberOfLines={1}>
{option.alternateText}
{option.text}
</Text>
) : (
<>
Expand Down Expand Up @@ -122,6 +123,13 @@ const ChatLinkRow = ({
</TouchableOpacity>
</View>
)}
{option.hasDraftComment && (
<Image
style={[styles.LHNPencilIcon]}
resizeMode="contain"
source={pencilIcon}
/>
)}
</View>
);
};
Expand Down
29 changes: 26 additions & 3 deletions src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const propTypes = {
unreadActionCount: PropTypes.number,
})),

// List of draft comments. We don't know the shape, since the keys include the report numbers
comments: PropTypes.objectOf(PropTypes.string),

isChatSwitcherActive: PropTypes.bool,

// List of users' personal details
Expand All @@ -43,12 +46,15 @@ const propTypes = {
displayName: PropTypes.string.isRequired,
})),
};

const defaultProps = {
reports: {},
isChatSwitcherActive: false,
comments: {},
personalDetails: {},
};


const SidebarLinks = (props) => {
const reportIDInUrl = parseInt(props.match.params.reportID, 10);
const sortedReports = lodashOrderby(props.reports, [
Expand All @@ -59,9 +65,22 @@ const SidebarLinks = (props) => {
'asc'
]);

// Filter the reports so that the only reports shown are pinned, unread, and the one matching the URL
// eslint-disable-next-line max-len
const reportsToDisplay = _.filter(sortedReports, report => (report.isPinned || (report.unreadActionCount > 0) || report.reportID === reportIDInUrl));
/**
* Check if the report has a draft comment
*
* @param {number} reportID
* @returns {boolean}
*/
function hasComment(reportID) {
const allComments = get(props.comments, `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`, '');
return allComments.length > 0;
}

// Filter the reports so that the only reports shown are pinned, unread, have draft
// comments (but are not the open one), and the one matching the URL
const reportsToDisplay = _.filter(sortedReports, report => (report.isPinned || (report.unreadActionCount > 0)
|| report.reportID === reportIDInUrl
|| (report.reportID !== reportIDInUrl && hasComment(report.reportID))));

// Update styles to hide the report links if they should not be visible
const sidebarLinksStyle = !props.isChatSwitcherActive
Expand Down Expand Up @@ -103,6 +122,7 @@ const SidebarLinks = (props) => {
login: participantDetails ? participantDetails.login : '',
reportID: report.reportID,
isUnread: report.unreadActionCount > 0,
hasDraftComment: report.reportID !== reportIDInUrl && hasComment(report.reportID)
}}
onSelectRow={props.onLinkClick}
optionIsFocused={report.reportID === reportIDInUrl}
Expand All @@ -124,6 +144,9 @@ export default compose(
reports: {
key: ONYXKEYS.COLLECTION.REPORT,
},
comments: {
key: ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT,
},
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
Expand Down
5 changes: 5 additions & 0 deletions src/styles/StyleSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,11 @@ const styles = {
width: 18,
},

LHNPencilIcon: {
height: 16,
width: 16,
},

attachmentCloseIcon: {
height: 20,
width: 20,
Expand Down

0 comments on commit 8ccd76e

Please sign in to comment.