You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
4.4 KiB
TypeScript
180 lines
4.4 KiB
TypeScript
5 years ago
|
import React from 'react';
|
||
5 years ago
|
import { SessionIconButton, SessionIconSize, SessionIconType } from './icon';
|
||
|
import { Avatar } from '../Avatar';
|
||
5 years ago
|
|
||
5 years ago
|
export enum SectionType {
|
||
5 years ago
|
Profile,
|
||
|
Message,
|
||
|
People,
|
||
|
Globe,
|
||
|
Settings,
|
||
|
Moon,
|
||
|
}
|
||
|
|
||
|
interface State {
|
||
|
avatarPath: string;
|
||
|
}
|
||
|
|
||
5 years ago
|
interface Props {
|
||
|
onSectionSelected: any;
|
||
|
selectedSection: SectionType;
|
||
|
}
|
||
|
|
||
5 years ago
|
const Section = ({
|
||
|
isSelected,
|
||
|
onSelect,
|
||
|
type,
|
||
|
avatarPath,
|
||
|
notificationCount,
|
||
|
}: {
|
||
|
isSelected: boolean;
|
||
|
onSelect?: (event: SectionType) => void;
|
||
|
type: SectionType;
|
||
|
avatarPath?: string;
|
||
|
avatarColor?: string;
|
||
|
notificationCount?: number;
|
||
|
}) => {
|
||
|
const handleClick = onSelect
|
||
|
? () => {
|
||
|
onSelect(type);
|
||
|
}
|
||
|
: undefined;
|
||
|
|
||
|
if (type === SectionType.Profile) {
|
||
|
if (!isSelected) {
|
||
|
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}
|
||
|
/>
|
||
|
);
|
||
|
} else {
|
||
|
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}
|
||
|
borderColor={'#fff'}
|
||
|
/>
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
let iconType: SessionIconType;
|
||
|
switch (type) {
|
||
|
case SectionType.Message:
|
||
5 years ago
|
iconType = SessionIconType.ChatBubble;
|
||
5 years ago
|
break;
|
||
|
case SectionType.People:
|
||
|
iconType = SessionIconType.Users;
|
||
|
break;
|
||
|
case SectionType.Globe:
|
||
|
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}
|
||
|
/>
|
||
|
);
|
||
|
}
|
||
|
};
|
||
|
|
||
5 years ago
|
export class ActionsPanel extends React.Component<Props, State> {
|
||
5 years ago
|
constructor(props: Props) {
|
||
|
super(props);
|
||
5 years ago
|
this.state = {
|
||
|
avatarPath: '',
|
||
|
};
|
||
|
}
|
||
|
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(),
|
||
|
});
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
public render(): JSX.Element {
|
||
5 years ago
|
const { selectedSection } = this.props;
|
||
5 years ago
|
|
||
|
return (
|
||
|
<div className="module-left-pane__sections-container">
|
||
|
<Section
|
||
|
type={SectionType.Profile}
|
||
|
avatarPath={this.state.avatarPath}
|
||
5 years ago
|
isSelected={selectedSection === SectionType.Profile}
|
||
5 years ago
|
onSelect={this.handleSectionSelect}
|
||
|
/>
|
||
|
<Section
|
||
|
type={SectionType.Message}
|
||
5 years ago
|
isSelected={selectedSection === SectionType.Message}
|
||
5 years ago
|
onSelect={this.handleSectionSelect}
|
||
|
notificationCount={0}
|
||
|
/>
|
||
|
<Section
|
||
|
type={SectionType.People}
|
||
5 years ago
|
isSelected={selectedSection === SectionType.People}
|
||
5 years ago
|
onSelect={this.handleSectionSelect}
|
||
|
/>
|
||
|
<Section
|
||
|
type={SectionType.Globe}
|
||
5 years ago
|
isSelected={selectedSection === SectionType.Globe}
|
||
5 years ago
|
onSelect={this.handleSectionSelect}
|
||
|
/>
|
||
|
<Section
|
||
|
type={SectionType.Settings}
|
||
5 years ago
|
isSelected={selectedSection === SectionType.Settings}
|
||
5 years ago
|
onSelect={this.handleSectionSelect}
|
||
|
/>
|
||
|
<Section
|
||
|
type={SectionType.Moon}
|
||
5 years ago
|
isSelected={selectedSection === SectionType.Moon}
|
||
5 years ago
|
onSelect={this.handleSectionSelect}
|
||
|
/>
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
private readonly handleSectionSelect = (section: SectionType): void => {
|
||
5 years ago
|
this.props.onSectionSelected(section);
|
||
5 years ago
|
};
|
||
|
}
|