session-desktop/ts/components/session/ActionsPanel.tsx

196 lines
5.2 KiB
TypeScript
Raw Normal View History

import React from 'react';
import { SessionIconButton, SessionIconSize, SessionIconType } from './icon';
import { Avatar } from '../Avatar';
import { PropsData as ConversationListItemPropsType } from '../ConversationListItem';
export enum SectionType {
Profile,
Message,
Contact,
Channel,
Settings,
Moon,
}
interface State {
avatarPath: string;
}
interface Props {
onSectionSelected: any;
selectedSection: SectionType;
conversations: Array<ConversationListItemPropsType> | undefined;
unreadMessageCount: number;
receivedFriendRequestCount: number;
}
export class ActionsPanel extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
avatarPath: '',
};
2020-01-24 02:26:15 +01:00
this.editProfileHandle = this.editProfileHandle.bind(this);
}
2020-01-03 01:49:42 +01:00
public componentDidMount() {
// tslint:disable-next-line: no-backbone-get-set-outside-model
const ourNumber = window.storage.get('primaryDevicePubKey');
window.ConversationController.getOrCreateAndWait(ourNumber, 'private').then(
(conversation: any) => {
this.setState({
avatarPath: conversation.getAvatarPath(),
});
}
);
}
2020-01-24 02:26:15 +01:00
public Section = ({
isSelected,
onSelect,
type,
avatarPath,
notificationCount,
}: {
isSelected: boolean;
onSelect?: (event: SectionType) => void;
type: SectionType;
avatarPath?: string;
avatarColor?: string;
notificationCount?: number;
}) => {
const handleClick = onSelect
? () => {
type === SectionType.Profile
? /* tslint:disable-next-line:no-void-expression */
this.editProfileHandle()
2020-01-24 02:26:15 +01:00
: /* tslint:disable-next-line:no-void-expression */
onSelect(type);
}
: undefined;
if (type === SectionType.Profile) {
return (
<Avatar
avatarPath={avatarPath}
conversationType="direct"
i18n={window.i18n}
// tslint:disable-next-line: no-backbone-get-set-outside-model
phoneNumber={window.storage.get('primaryDevicePubKey')}
size={28}
onAvatarClick={handleClick}
/>
);
}
let iconType: SessionIconType;
switch (type) {
case SectionType.Message:
iconType = SessionIconType.ChatBubble;
break;
case SectionType.Contact:
iconType = SessionIconType.Users;
break;
case SectionType.Channel:
iconType = SessionIconType.Globe;
break;
case SectionType.Settings:
iconType = SessionIconType.Gear;
break;
case SectionType.Moon:
iconType = SessionIconType.Moon;
break;
default:
iconType = SessionIconType.Moon;
}
if (!isSelected) {
return (
<SessionIconButton
iconSize={SessionIconSize.Medium}
iconType={iconType}
notificationCount={notificationCount}
onClick={handleClick}
/>
);
} else {
return (
<SessionIconButton
iconSize={SessionIconSize.Medium}
iconType={iconType}
notificationCount={notificationCount}
onClick={handleClick}
isSelected={isSelected}
/>
);
}
};
public editProfileHandle() {
window.showEditProfileDialog((avatar: any) => {
this.setState({
avatarPath: avatar,
});
});
}
public render(): JSX.Element {
const {
selectedSection,
unreadMessageCount,
receivedFriendRequestCount,
} = this.props;
2020-01-03 01:49:42 +01:00
const isProfilePageSelected = selectedSection === SectionType.Profile;
const isMessagePageSelected = selectedSection === SectionType.Message;
const isContactPageSelected = selectedSection === SectionType.Contact;
const isChannelPageSelected = selectedSection === SectionType.Channel;
2020-01-03 01:49:42 +01:00
const isSettingsPageSelected = selectedSection === SectionType.Settings;
const isMoonPageSelected = selectedSection === SectionType.Moon;
return (
<div className="module-left-pane__sections-container">
2020-01-24 02:26:15 +01:00
<this.Section
type={SectionType.Profile}
avatarPath={this.state.avatarPath}
2020-01-03 01:49:42 +01:00
isSelected={isProfilePageSelected}
onSelect={this.handleSectionSelect}
/>
2020-01-24 02:26:15 +01:00
<this.Section
type={SectionType.Message}
2020-01-03 01:49:42 +01:00
isSelected={isMessagePageSelected}
onSelect={this.handleSectionSelect}
notificationCount={unreadMessageCount}
/>
2020-01-24 02:26:15 +01:00
<this.Section
type={SectionType.Contact}
2020-01-03 01:49:42 +01:00
isSelected={isContactPageSelected}
onSelect={this.handleSectionSelect}
notificationCount={receivedFriendRequestCount}
/>
2020-01-24 02:26:15 +01:00
<this.Section
type={SectionType.Channel}
isSelected={isChannelPageSelected}
onSelect={this.handleSectionSelect}
/>
2020-01-24 02:26:15 +01:00
<this.Section
type={SectionType.Settings}
2020-01-03 01:49:42 +01:00
isSelected={isSettingsPageSelected}
onSelect={this.handleSectionSelect}
/>
2020-01-24 02:26:15 +01:00
<this.Section
type={SectionType.Moon}
2020-01-03 01:49:42 +01:00
isSelected={isMoonPageSelected}
onSelect={this.handleSectionSelect}
/>
</div>
);
}
private readonly handleSectionSelect = (section: SectionType): void => {
this.props.onSectionSelected(section);
};
}