Dropdown generalisation and simplification

pull/710/head
Vincent 5 years ago
parent 12011a30d4
commit e9d543fe4a

@ -702,6 +702,8 @@
<script type='text/javascript' src='js/views/toast_view.js'></script>
<script type='text/javascript' src='js/views/session_toast_view.js'></script>
<script type='text/javascript' src='js/views/session_toggle_view.js'></script>
<script type='text/javascript' src='js/views/session_modal_view.js'></script>
<script type='text/javascript' src='js/views/session_dropdown_view.js'></script>
<script type='text/javascript' src='js/views/file_input_view.js'></script>
<script type='text/javascript' src='js/views/list_view.js'></script>
<script type='text/javascript' src='js/views/contact_list_view.js'></script>

@ -819,6 +819,7 @@
type: options.type || '',
};
// Give all toasts an ID. User may define.
const toastID = params.id;
const toast = !!toastID && window.toasts.get(toastID);
@ -831,8 +832,10 @@
new Whisper.SessionToastView({
el: $('#session-toast-container'),
})
);
window.toasts.get(toastID).render();
window.toasts.get(toastID).update(params);
}

@ -53,6 +53,7 @@ const { UserDetailsDialog } = require('../../ts/components/UserDetailsDialog');
const { SessionToast } = require('../../ts/components/session/SessionToast');
const { SessionToggle } = require('../../ts/components/session/SessionToggle');
const { SessionModal } = require('../../ts/components/session/SessionModal');
const { SessionDropdown } = require('../../ts/components/session/SessionDropdown');
const {
SessionRegistrationView,
} = require('../../ts/components/session/SessionRegistrationView');
@ -254,6 +255,7 @@ exports.setup = (options = {}) => {
SessionToast,
SessionToggle,
SessionModal,
SessionDropdown,
MediaGallery,
Message,
MessageBody,

@ -1375,11 +1375,11 @@
if (!isAllOurs && !isModerator) {
window.pushToast({
title: i18n('messageDeletionForbidden'),
type: 'error',
id: 'messageDeletionForbidden',
title: i18n('messageDeletionForbidden'),
type: 'error',
id: 'messageDeletionForbidden',
});
return;
}

@ -0,0 +1,38 @@
/* global Whisper */
// eslint-disable-next-line func-names
(function() {
'use strict';
window.Whisper = window.Whisper || {};
Whisper.SessionDropdownView = Whisper.View.extend({
initialize(options) {
this.props = {
items: options.items,
};
this.render();
},
render() {
this.dropdownView = new Whisper.ReactWrapperView({
className: 'session-dropdown-wrapper',
Component: window.Signal.Components.SessionDropdown,
props: this.props,
});
this.$el.append(this.dropdownView.el);
},
openDropdown() {
},
closeDropdown() {
},
});
})();

@ -562,7 +562,39 @@ label {
}
// .react-contextmenu {
// padding: 0px;
// margin: 0px;
// border: none !important;
// border-radius: 0px;
// }
// .react-contextmenu-item {
// display: flex;
// align-items: center;
// height: 25px;
// padding: 0px 10px;
// background-color: #1B1B1B;
// color: $session-color-white;
// font-family: 'Wasa';
// font-size: 12px;
// line-height: $session-icon-size-sm;
// font-weight: 700;
// &--active, &--selected{
// background-color: $session-shade-7 !important;
// }
// }
.session-dropdown{
position: absolute;
top: 50px;
left: 50px;
display: inline-block;
ul {
@ -603,5 +635,4 @@ label {
}
}
}
}

@ -53,4 +53,6 @@
margin-left: 5px;
}
}
}

@ -1,8 +1,7 @@
import React from 'react';
import { Avatar } from './Avatar';
import { SessionDropdown, SessionDropDownType } from './session/SessionDropdown';
import { SessionIconType } from './session/icon';
import { SessionDropdown } from './session/SessionDropdown';
declare global {
interface Window {
@ -35,41 +34,41 @@ export class UserDetailsDialog extends React.Component<Props> {
const cancelText = i18n('cancel');
const startConversation = i18n('startConversation');
const items = [
{
id: "myid1",
content: "Copy Chat ID",
icon: SessionIconType.Eye,
type: SessionDropDownType.Default,
active: false
content: "sdgsdfg",
display: true,//!isPublic && !isMe,
},
{
content: i18n('changeNickname'),
display: true,//!isPublic && !isMe,
},
{
content: i18n('clearNickname'),
display: true,//!isPublic && !isMe && hasNickname,
},
{
id: "myid1",
content: "Invite Friends",
icon: null,
type: SessionDropDownType.Default,
active: false
content: i18n('copyPublicKey'),
display: false,//!isPublic,
},
{
id: "myid1",
content: "Clear Chat History",
icon: SessionIconType.Check,
type: SessionDropDownType.Default,
active: true
content: i18n('deleteMessages'),
},
{
id: "myid1",
content: "Leave Group",
icon: SessionIconType.Check,
type: SessionDropDownType.Danger,
active: false
content: i18n('deleteContact'),
display: true,//!isMe && isClosable && !isPublic,
},
{
content: i18n('deletePublicChannel'),
display: true,//!isMe && isClosable && !isPublic,
},
];
return (
<div className="content">
<SessionDropdown items={items} />
<SessionDropdown items={items}/>
<div className="avatar-center">
<div className="avatar-center-inner">{this.renderAvatar()}</div>
</div>

@ -1,23 +1,26 @@
import React from 'react';
import classNames from 'classnames';
import { SessionDropdownItem, SessionDropDownItemType } from './SessionDropdownItem';
import { SessionIconType } from './icon/';
import { SessionDropdownItem, SessionDropDownItemType } from './SessionDropdownItem';
// THIS IS A FUTURE-PROOFING ELEMENT TO REPLACE ELECTRON CONTEXTMENUS IN PRELOAD.JS
interface Props {
id?: string,
items: Array<{
id: string,
content: string,
icon: SessionIconType | null,
type: SessionDropDownItemType,
active: boolean,
id?: string,
icon?: SessionIconType | null,
type?: SessionDropDownItemType,
active?: boolean,
onClick?: any,
display?: boolean,
}>,
}
export class SessionDropdown extends React.PureComponent<Props> {
public static readonly defaultProps = SessionDropdownItem.defaultProps;
constructor(props: any) {
super(props);
}
@ -28,13 +31,18 @@ export class SessionDropdown extends React.PureComponent<Props> {
return (
<div className={classNames('session-dropdown')}>
<ul>
{items.map((item: any) => <SessionDropdownItem
id={item.id}
content={item.content}
icon={item.icon}
type={item.type}
active={item.active}
/>
{items.map((item: any) => {
return item.display ? (
<SessionDropdownItem
id={item.id}
content={item.content}
icon={item.icon}
type={item.type}
active={item.active}
onClick={item.onClick}
/>
) : null
}
)}
</ul>
</div>

@ -24,6 +24,8 @@ export class SessionDropdownItem extends React.PureComponent<Props> {
public static defaultProps = {
id: generateID(),
type: SessionDropDownItemType.Default,
icon: null,
active: false,
onClick: () => null,
};

Loading…
Cancel
Save