lint code

pull/712/head
Audric Ackermann 5 years ago
parent 6209d7d2e2
commit 9cc6807b22

@ -320,8 +320,6 @@ $session-compose-margin: 20px;
line-height: 50px; line-height: 50px;
} }
} }
} }
.panel-text-divider { .panel-text-divider {

@ -80,8 +80,7 @@ export class ConversationListItem extends React.PureComponent<Props> {
isPendingFriendRequest, isPendingFriendRequest,
} = this.props; } = this.props;
let borderColor;
let borderColor = undefined;
if (!isPendingFriendRequest) { if (!isPendingFriendRequest) {
borderColor = isOnline ? Colors.ONLINE : Colors.OFFLINE; borderColor = isOnline ? Colors.ONLINE : Colors.OFFLINE;
} }
@ -125,7 +124,14 @@ export class ConversationListItem extends React.PureComponent<Props> {
} }
public renderHeader() { public renderHeader() {
const { unreadCount, i18n, isMe, lastUpdated, isFriendItem, hasReceivedFriendRequest } = this.props; const {
unreadCount,
i18n,
isMe,
lastUpdated,
isFriendItem,
hasReceivedFriendRequest,
} = this.props;
return ( return (
<div className="module-conversation-list-item__header"> <div className="module-conversation-list-item__header">
@ -139,7 +145,7 @@ export class ConversationListItem extends React.PureComponent<Props> {
> >
{isMe ? i18n('noteToSelf') : this.renderUser()} {isMe ? i18n('noteToSelf') : this.renderUser()}
</div> </div>
{hasReceivedFriendRequest || this.renderUnread()} {hasReceivedFriendRequest || this.renderUnread()}
{!isFriendItem && ( {!isFriendItem && (
<div <div
className={classNames( className={classNames(
@ -149,13 +155,14 @@ export class ConversationListItem extends React.PureComponent<Props> {
: null : null
)} )}
> >
{!hasReceivedFriendRequest && (<Timestamp {!hasReceivedFriendRequest && (
timestamp={lastUpdated} <Timestamp
extended={false} timestamp={lastUpdated}
module="module-conversation-list-item__header__timestamp" extended={false}
i18n={i18n} module="module-conversation-list-item__header__timestamp"
/>) i18n={i18n}
} />
)}
</div> </div>
)} )}
</div> </div>
@ -283,12 +290,19 @@ export class ConversationListItem extends React.PureComponent<Props> {
} }
public renderFriendRequestButtons() { public renderFriendRequestButtons() {
const { acceptFriendRequest, declineFriendRequest } = this.props; const { acceptFriendRequest, declineFriendRequest } = this.props;
return ( return (
<div className="module-conversation-list-item__buttons"> <div className="module-conversation-list-item__buttons">
<SessionButton text={window.i18n('decline')} buttonColor={SessionButtonColor.None} onClick={declineFriendRequest}/> <SessionButton
<SessionButton text={window.i18n('accept')} onClick={acceptFriendRequest}/> text={window.i18n('decline')}
buttonColor={SessionButtonColor.None}
onClick={declineFriendRequest}
/>
<SessionButton
text={window.i18n('accept')}
onClick={acceptFriendRequest}
/>
</div> </div>
); );
} }
@ -306,7 +320,6 @@ export class ConversationListItem extends React.PureComponent<Props> {
mentionedUs, mentionedUs,
} = this.props; } = this.props;
const triggerId = `${phoneNumber}-ctxmenu-${Date.now()}`; const triggerId = `${phoneNumber}-ctxmenu-${Date.now()}`;
return ( return (

@ -59,92 +59,8 @@ export class LeftPane extends React.Component<Props, State> {
this.handleSectionSelected = this.handleSectionSelected.bind(this); this.handleSectionSelected = this.handleSectionSelected.bind(this);
} }
public handleSectionSelected(section: SectionType) {
this.setState({ selectedSection: section });
}
public render(): JSX.Element {
return (
<div className="module-left-pane-session">
<ActionsPanel
selectedSection={this.state.selectedSection}
onSectionSelected={this.handleSectionSelected}
conversations={this.props.conversations}
/>
<div className="module-left-pane">{this.renderSection()}</div>
</div>
);
}
private renderSection(): JSX.Element | undefined {
switch (this.state.selectedSection) {
case SectionType.Message:
return this.renderMessageSection();
case SectionType.Contact:
return this.renderContactSection();
default:
return undefined;
}
}
private renderMessageSection() {
const {
openConversationInternal,
conversations,
searchResults,
searchTerm,
isSecondaryDevice,
updateSearchTerm,
search,
clearSearch,
} = this.props;
return (
<LeftPaneMessageSection
openConversationInternal={openConversationInternal}
conversations={conversations}
searchResults={searchResults}
searchTerm={searchTerm}
isSecondaryDevice={isSecondaryDevice}
updateSearchTerm={updateSearchTerm}
search={search}
clearSearch={clearSearch}
/>
);
}
private renderContactSection() {
const {
openConversationInternal,
friends,
conversations,
searchResults,
searchTerm,
isSecondaryDevice,
updateSearchTerm,
search,
clearSearch,
} = this.props;
return (
<LeftPaneContactSection
openConversationInternal={openConversationInternal}
conversations={conversations}
friends={friends}
searchResults={searchResults}
searchTerm={searchTerm}
isSecondaryDevice={isSecondaryDevice}
updateSearchTerm={updateSearchTerm}
search={search}
clearSearch={clearSearch}
/>
);
}
// this static function is set here to be used by all subsections (message, contacts,...) to render their headers // this static function is set here to be used by all subsections (message, contacts,...) to render their headers
static renderHeader( public static RENDER_HEADER(
labels: Array<string>, labels: Array<string>,
onTabSelected?: any, onTabSelected?: any,
buttonLabel?: string, buttonLabel?: string,
@ -163,7 +79,7 @@ export class LeftPane extends React.Component<Props, State> {
); );
} }
static renderClosableOverlay( public static RENDER_CLOSABLE_OVERLAY(
isAddContactView: boolean, isAddContactView: boolean,
onChangeSessionID: any, onChangeSessionID: any,
onCloseClick: any, onCloseClick: any,
@ -237,4 +153,86 @@ export class LeftPane extends React.Component<Props, State> {
</div> </div>
); );
} }
public handleSectionSelected(section: SectionType) {
this.setState({ selectedSection: section });
}
public render(): JSX.Element {
return (
<div className="module-left-pane-session">
<ActionsPanel
selectedSection={this.state.selectedSection}
onSectionSelected={this.handleSectionSelected}
conversations={this.props.conversations}
/>
<div className="module-left-pane">{this.renderSection()}</div>
</div>
);
}
private renderSection(): JSX.Element | undefined {
switch (this.state.selectedSection) {
case SectionType.Message:
return this.renderMessageSection();
case SectionType.Contact:
return this.renderContactSection();
default:
return undefined;
}
}
private renderMessageSection() {
const {
openConversationInternal,
conversations,
searchResults,
searchTerm,
isSecondaryDevice,
updateSearchTerm,
search,
clearSearch,
} = this.props;
return (
<LeftPaneMessageSection
openConversationInternal={openConversationInternal}
conversations={conversations}
searchResults={searchResults}
searchTerm={searchTerm}
isSecondaryDevice={isSecondaryDevice}
updateSearchTerm={updateSearchTerm}
search={search}
clearSearch={clearSearch}
/>
);
}
private renderContactSection() {
const {
openConversationInternal,
friends,
conversations,
searchResults,
searchTerm,
isSecondaryDevice,
updateSearchTerm,
search,
clearSearch,
} = this.props;
return (
<LeftPaneContactSection
openConversationInternal={openConversationInternal}
conversations={conversations}
friends={friends}
searchResults={searchResults}
searchTerm={searchTerm}
isSecondaryDevice={isSecondaryDevice}
updateSearchTerm={updateSearchTerm}
search={search}
clearSearch={clearSearch}
/>
);
}
} }

@ -121,6 +121,27 @@ export class ActionsPanel extends React.Component<Props, State> {
avatarPath: '', avatarPath: '',
}; };
} }
public static GET_FRIEND_REQUESTS_COUNT(
conversations: Array<ConversationListItemPropsType> | undefined
): number {
let friendRequestCount = 0;
if (conversations !== undefined) {
// We assume a friend request already read is still a friend valid request
conversations.some(conversation => {
// Ignore friend request with lastmessage status as sent as this is a friend request we made ourself
friendRequestCount += conversation.hasReceivedFriendRequest ? 1 : 0;
if (friendRequestCount > 9) {
return true;
}
return false;
});
}
return friendRequestCount;
}
public componentDidMount() { public componentDidMount() {
// tslint:disable-next-line: no-backbone-get-set-outside-model // tslint:disable-next-line: no-backbone-get-set-outside-model
const ourNumber = window.storage.get('primaryDevicePubKey'); const ourNumber = window.storage.get('primaryDevicePubKey');
@ -137,42 +158,51 @@ export class ActionsPanel extends React.Component<Props, State> {
public render(): JSX.Element { public render(): JSX.Element {
const { selectedSection, conversations } = this.props; const { selectedSection, conversations } = this.props;
const friendRequestCount = ActionsPanel.getFriendRequestsCount(conversations); const friendRequestCount = ActionsPanel.GET_FRIEND_REQUESTS_COUNT(
conversations
);
const unreadMessageCount = this.getUnreadMessageCount(); const unreadMessageCount = this.getUnreadMessageCount();
const isProfilePageSelected = selectedSection === SectionType.Profile;
const isMessagePageSelected = selectedSection === SectionType.Message;
const isContactPageSelected = selectedSection === SectionType.Contact;
const isGlobePageSelected = selectedSection === SectionType.Globe;
const isSettingsPageSelected = selectedSection === SectionType.Settings;
const isMoonPageSelected = selectedSection === SectionType.Moon;
return ( return (
<div className="module-left-pane__sections-container"> <div className="module-left-pane__sections-container">
<Section <Section
type={SectionType.Profile} type={SectionType.Profile}
avatarPath={this.state.avatarPath} avatarPath={this.state.avatarPath}
isSelected={selectedSection === SectionType.Profile} isSelected={isProfilePageSelected}
onSelect={this.handleSectionSelect} onSelect={this.handleSectionSelect}
/> />
<Section <Section
type={SectionType.Message} type={SectionType.Message}
isSelected={selectedSection === SectionType.Message} isSelected={isMessagePageSelected}
onSelect={this.handleSectionSelect} onSelect={this.handleSectionSelect}
notificationCount={unreadMessageCount} notificationCount={unreadMessageCount}
/> />
<Section <Section
type={SectionType.Contact} type={SectionType.Contact}
isSelected={selectedSection === SectionType.Contact} isSelected={isContactPageSelected}
onSelect={this.handleSectionSelect} onSelect={this.handleSectionSelect}
notificationCount={friendRequestCount} notificationCount={friendRequestCount}
/> />
<Section <Section
type={SectionType.Globe} type={SectionType.Globe}
isSelected={selectedSection === SectionType.Globe} isSelected={isGlobePageSelected}
onSelect={this.handleSectionSelect} onSelect={this.handleSectionSelect}
/> />
<Section <Section
type={SectionType.Settings} type={SectionType.Settings}
isSelected={selectedSection === SectionType.Settings} isSelected={isSettingsPageSelected}
onSelect={this.handleSectionSelect} onSelect={this.handleSectionSelect}
/> />
<Section <Section
type={SectionType.Moon} type={SectionType.Moon}
isSelected={selectedSection === SectionType.Moon} isSelected={isMoonPageSelected}
onSelect={this.handleSectionSelect} onSelect={this.handleSectionSelect}
/> />
</div> </div>
@ -183,36 +213,21 @@ export class ActionsPanel extends React.Component<Props, State> {
const { conversations } = this.props; const { conversations } = this.props;
let unreadCount = 0; let unreadCount = 0;
if (conversations !== undefined) { if (conversations !== undefined) {
conversations.some(function (conversation) { conversations.some(conversation => {
if (conversation.isPendingFriendRequest) { if (conversation.isPendingFriendRequest) {
return false; return false;
} }
unreadCount += conversation.unreadCount; unreadCount += conversation.unreadCount;
if (unreadCount > 9) { if (unreadCount > 9) {
return true;
}
return false;
});
}
return unreadCount;
}
static getFriendRequestsCount(conversations: Array<ConversationListItemPropsType> | undefined): number {
let friendRequestCount = 0;
if (conversations !== undefined) {
// We assume a friend request already read is still a friend valid request
conversations.some(function (conversation) {
// Ignore friend request with lastmessage status as sent as this is a friend request we made ourself
friendRequestCount += conversation.hasReceivedFriendRequest ? 1 : 0;
if (friendRequestCount > 9) {
return true; return true;
} }
return false; return false;
}); });
} }
return friendRequestCount; return unreadCount;
} }
private readonly handleSectionSelect = (section: SectionType): void => { private readonly handleSectionSelect = (section: SectionType): void => {

@ -1,8 +1,8 @@
import React from 'react'; import React from 'react';
import { import {
PropsData as ConversationListItemPropsType,
ConversationListItem, ConversationListItem,
PropsData as ConversationListItemPropsType
} from '../ConversationListItem'; } from '../ConversationListItem';
import { PropsData as SearchResultsProps } from '../SearchResults'; import { PropsData as SearchResultsProps } from '../SearchResults';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
@ -11,8 +11,8 @@ import { SearchOptions } from '../../types/Search';
import { LeftPane, RowRendererParamsType } from '../LeftPane'; import { LeftPane, RowRendererParamsType } from '../LeftPane';
import { import {
SessionButton, SessionButton,
SessionButtonType,
SessionButtonColor, SessionButtonColor,
SessionButtonType,
} from './SessionButton'; } from './SessionButton';
import { AutoSizer, List } from 'react-virtualized'; import { AutoSizer, List } from 'react-virtualized';
import { validateNumber } from '../../types/PhoneNumber'; import { validateNumber } from '../../types/PhoneNumber';
@ -65,9 +65,11 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
public renderHeader(): JSX.Element | undefined { public renderHeader(): JSX.Element | undefined {
const labels = [window.i18n('contactsHeader'), window.i18n('lists')]; const labels = [window.i18n('contactsHeader'), window.i18n('lists')];
const friendRequestCount = ActionsPanel.getFriendRequestsCount(this.props.conversations); const friendRequestCount = ActionsPanel.GET_FRIEND_REQUESTS_COUNT(
this.props.conversations
);
return LeftPane.renderHeader( return LeftPane.RENDER_HEADER(
labels, labels,
this.handleTabSelected, this.handleTabSelected,
undefined, undefined,
@ -81,7 +83,7 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
<div className="left-pane-contact-section"> <div className="left-pane-contact-section">
{this.renderHeader()} {this.renderHeader()}
{this.state.showAddContactView {this.state.showAddContactView
? LeftPane.renderClosableOverlay( ? LeftPane.RENDER_CLOSABLE_OVERLAY(
true, true,
this.handleRecipientSessionIDChanged, this.handleRecipientSessionIDChanged,
this.handleToggleOverlay, this.handleToggleOverlay,
@ -93,6 +95,99 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
); );
} }
public getCurrentFriends(): Array<ConversationType> {
const { friends } = this.props;
let friendList = friends;
if (friendList !== undefined) {
friendList = friendList.filter(
friend => friend.type === 'direct' && !friend.isMe
);
}
return friendList;
}
public renderRow = ({
index,
key,
style,
}: RowRendererParamsType): JSX.Element | undefined => {
const receivedFriendsRequest = this.getFriendRequests(true);
const sentFriendsRequest = this.getFriendRequests(false);
const friends = this.getCurrentFriends();
const combined = [
...receivedFriendsRequest,
...sentFriendsRequest,
...friends,
];
const item = combined[index];
let onClick;
if (index >= receivedFriendsRequest.length) {
onClick = this.props.openConversationInternal;
}
return (
<ConversationListItem
key={key}
style={style}
{...item}
i18n={window.i18n}
onClick={onClick}
/>
);
};
public updateSearch(searchTerm: string) {
const { updateSearchTerm, clearSearch } = this.props;
if (!searchTerm) {
clearSearch();
return;
}
// reset our pubKeyPasted, we can either have a pasted sessionID or a sessionID got from a search
this.setState({ pubKeyPasted: '' }, () => {
window.Session.emptyContentEditableDivs();
});
if (updateSearchTerm) {
updateSearchTerm(searchTerm);
}
if (searchTerm.length < 2) {
return;
}
const cleanedTerm = cleanSearchTerm(searchTerm);
if (!cleanedTerm) {
return;
}
this.debouncedSearch(cleanedTerm);
}
public clearSearch() {
this.props.clearSearch();
//this.setFocus();
}
public search() {
const { search } = this.props;
const { searchTerm, isSecondaryDevice } = this.props;
if (search) {
search(searchTerm, {
noteToSelf: window.i18n('noteToSelf').toLowerCase(),
ourNumber: window.textsecure.storage.user.getNumber(),
regionCode: '',
isSecondaryDevice,
});
}
}
private handleToggleOverlay() { private handleToggleOverlay() {
this.setState((prevState: { showAddContactView: any }) => ({ this.setState((prevState: { showAddContactView: any }) => ({
showAddContactView: !prevState.showAddContactView, showAddContactView: !prevState.showAddContactView,
@ -136,6 +231,7 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
const edit = window.i18n('edit'); const edit = window.i18n('edit');
const addContact = window.i18n('addContact'); const addContact = window.i18n('addContact');
const createGroup = window.i18n('createGroup'); const createGroup = window.i18n('createGroup');
return ( return (
<div className="left-pane-contact-bottom-buttons"> <div className="left-pane-contact-bottom-buttons">
<SessionButton <SessionButton
@ -162,33 +258,23 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
); );
} }
public getCurrentFriends():
| Array<ConversationType> {
const { friends } = this.props;
let friendList = friends;
if (friendList !== undefined) {
friendList = friendList.filter(
friend =>
friend.type ==='direct' && !friend.isMe
);
}
return friendList;
}
// true: received only, false: sent only // true: received only, false: sent only
private getFriendRequests(received:boolean): Array<ConversationListItemPropsType> { private getFriendRequests(
received: boolean
): Array<ConversationListItemPropsType> {
const { conversations } = this.props; const { conversations } = this.props;
let conversationsList = conversations; let conversationsList = conversations;
if (conversationsList !== undefined) { if (conversationsList !== undefined) {
if (received) { if (received) {
conversationsList = conversationsList.filter( conversationsList = conversationsList.filter(
conversation => (conversation.hasReceivedFriendRequest)); conversation => conversation.hasReceivedFriendRequest
);
} else { } else {
conversationsList = conversationsList.filter( conversationsList = conversationsList.filter(
conversation => (conversation.hasSentFriendRequest)); conversation => conversation.hasSentFriendRequest
);
} }
} }
@ -200,7 +286,11 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
const sentFriendsRequest = this.getFriendRequests(false); const sentFriendsRequest = this.getFriendRequests(false);
const friends = this.getCurrentFriends(); const friends = this.getCurrentFriends();
const combined = [...receivedFriendsRequest, ...sentFriendsRequest, ...friends]; const combined = [
...receivedFriendsRequest,
...sentFriendsRequest,
...friends,
];
const length = combined.length; const length = combined.length;
@ -224,80 +314,4 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
return [list]; return [list];
} }
public renderRow = ({
index,
key,
style,
}: RowRendererParamsType): JSX.Element | undefined => {
const receivedFriendsRequest = this.getFriendRequests(true);
const sentFriendsRequest = this.getFriendRequests(false);
const friends = this.getCurrentFriends();
const combined = [...receivedFriendsRequest, ...sentFriendsRequest, ...friends];
const item = combined[index];
let onClick = undefined;
if (index >= receivedFriendsRequest.length) {
onClick = this.props.openConversationInternal;
}
return (
<ConversationListItem
key={key}
style={style}
{...item}
i18n={window.i18n}
onClick={onClick}
/>
);
};
public updateSearch(searchTerm: string) {
const { updateSearchTerm, clearSearch } = this.props;
if (!searchTerm) {
clearSearch();
return;
}
// reset our pubKeyPasted, we can either have a pasted sessionID or a sessionID got from a search
this.setState({ pubKeyPasted: '' }, () => {
window.Session.emptyContentEditableDivs();
});
if (updateSearchTerm) {
updateSearchTerm(searchTerm);
}
if (searchTerm.length < 2) {
return;
}
const cleanedTerm = cleanSearchTerm(searchTerm);
if (!cleanedTerm) {
return;
}
this.debouncedSearch(cleanedTerm);
}
public clearSearch() {
this.props.clearSearch();
//this.setFocus();
}
public search() {
const { search } = this.props;
const { searchTerm, isSecondaryDevice } = this.props;
if (search) {
search(searchTerm, {
noteToSelf: window.i18n('noteToSelf').toLowerCase(),
ourNumber: window.textsecure.storage.user.getNumber(),
regionCode: '',
isSecondaryDevice,
});
}
}
} }

@ -14,7 +14,7 @@ import { debounce } from 'lodash';
import { cleanSearchTerm } from '../../util/cleanSearchTerm'; import { cleanSearchTerm } from '../../util/cleanSearchTerm';
import { SearchOptions } from '../../types/Search'; import { SearchOptions } from '../../types/Search';
import { validateNumber } from '../../types/PhoneNumber'; import { validateNumber } from '../../types/PhoneNumber';
import { RowRendererParamsType, LeftPane } from '../LeftPane'; import { LeftPane, RowRendererParamsType } from '../LeftPane';
export interface Props { export interface Props {
searchTerm: string; searchTerm: string;
@ -60,8 +60,8 @@ export class LeftPaneMessageSection extends React.Component<Props, any> {
let conversationList = conversations; let conversationList = conversations;
if (conversationList !== undefined) { if (conversationList !== undefined) {
conversationList = conversationList.filter( conversationList = conversationList.filter(
conversation => !conversation.isSecondary conversation =>
&& !conversation.isPendingFriendRequest !conversation.isSecondary && !conversation.isPendingFriendRequest
); );
} }
@ -145,7 +145,8 @@ export class LeftPaneMessageSection extends React.Component<Props, any> {
public renderHeader(): JSX.Element { public renderHeader(): JSX.Element {
const labels = [window.i18n('messagesHeader')]; const labels = [window.i18n('messagesHeader')];
return LeftPane.renderHeader(
return LeftPane.RENDER_HEADER(
labels, labels,
null, null,
window.i18n('compose'), window.i18n('compose'),
@ -158,7 +159,7 @@ export class LeftPaneMessageSection extends React.Component<Props, any> {
<div> <div>
{this.renderHeader()} {this.renderHeader()}
{this.state.showComposeView {this.state.showComposeView
? LeftPane.renderClosableOverlay( ? LeftPane.RENDER_CLOSABLE_OVERLAY(
false, false,
this.handleOnPasteSessionID, this.handleOnPasteSessionID,
this.handleComposeClick, this.handleComposeClick,

@ -84,16 +84,14 @@ export class LeftPaneSectionHeader extends React.Component<Props, State> {
<SessionButton <SessionButton
text={window.i18n('compose')} text={window.i18n('compose')}
onClick={buttonClicked} onClick={buttonClicked}
key='compose' key="compose"
/> />
); );
} else if (notificationCount && notificationCount > 0) { } else if (notificationCount && notificationCount > 0) {
const shortenedNotificationCount = const shortenedNotificationCount =
notificationCount > 9 ? 9 : notificationCount; notificationCount > 9 ? 9 : notificationCount;
children.push( children.push(
<div <div className="contact-notification-count-bubble">
className="contact-notification-count-bubble"
>
{shortenedNotificationCount} {shortenedNotificationCount}
</div> </div>
); );

Loading…
Cancel
Save