From 58cda9cc7fb79ca9df6746de7f9662bc08dc156a Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Fri, 13 Oct 2017 12:29:40 +0200 Subject: initial commit --- src/components/services/tabs/TabBarSortableList.js | 44 +++++++ src/components/services/tabs/TabItem.js | 136 +++++++++++++++++++++ src/components/services/tabs/Tabbar.js | 77 ++++++++++++ 3 files changed, 257 insertions(+) create mode 100644 src/components/services/tabs/TabBarSortableList.js create mode 100644 src/components/services/tabs/TabItem.js create mode 100644 src/components/services/tabs/Tabbar.js (limited to 'src/components/services/tabs') diff --git a/src/components/services/tabs/TabBarSortableList.js b/src/components/services/tabs/TabBarSortableList.js new file mode 100644 index 000000000..c0a68d1a5 --- /dev/null +++ b/src/components/services/tabs/TabBarSortableList.js @@ -0,0 +1,44 @@ +import React from 'react'; +import { observer } from 'mobx-react'; +import { SortableContainer } from 'react-sortable-hoc'; + +import TabItem from './TabItem'; +import { ctrlKey } from '../../../environment'; + +export default SortableContainer(observer(({ + services, + setActive, + reload, + toggleNotifications, + deleteService, + disableService, + openSettings, +}) => ( + +))); diff --git a/src/components/services/tabs/TabItem.js b/src/components/services/tabs/TabItem.js new file mode 100644 index 000000000..9e03d2e21 --- /dev/null +++ b/src/components/services/tabs/TabItem.js @@ -0,0 +1,136 @@ +import { remote } from 'electron'; +import React, { Component } from 'react'; +import { defineMessages, intlShape } from 'react-intl'; +import PropTypes from 'prop-types'; +import { observer } from 'mobx-react'; +import classnames from 'classnames'; +import { SortableElement } from 'react-sortable-hoc'; + +import ServiceModel from '../../../models/Service'; +import { ctrlKey } from '../../../environment'; + +const { Menu } = remote; + +const messages = defineMessages({ + reload: { + id: 'tabs.item.reload', + defaultMessage: '!!!Reload', + }, + edit: { + id: 'tabs.item.edit', + defaultMessage: '!!!Edit', + }, + disableNotifications: { + id: 'tabs.item.disableNotifications', + defaultMessage: '!!!Disable notifications', + }, + enableNotifications: { + id: 'tabs.item.enableNotification', + defaultMessage: '!!!Enable notifications', + }, + disableService: { + id: 'tabs.item.disableService', + defaultMessage: '!!!Disable Service', + }, + deleteService: { + id: 'tabs.item.deleteService', + defaultMessage: '!!!Delete Service', + }, +}); + +@observer +class TabItem extends Component { + static propTypes = { + service: PropTypes.instanceOf(ServiceModel).isRequired, + clickHandler: PropTypes.func.isRequired, + shortcutIndex: PropTypes.number.isRequired, + reload: PropTypes.func.isRequired, + toggleNotifications: PropTypes.func.isRequired, + openSettings: PropTypes.func.isRequired, + deleteService: PropTypes.func.isRequired, + disableService: PropTypes.func.isRequired, + }; + + static contextTypes = { + intl: intlShape, + }; + + render() { + const { + service, + clickHandler, + shortcutIndex, + reload, + toggleNotifications, + deleteService, + disableService, + openSettings, + } = this.props; + const { intl } = this.context; + + + const menuTemplate = [{ + label: service.name || service.recipe.name, + enabled: false, + }, { + type: 'separator', + }, { + label: intl.formatMessage(messages.reload), + click: reload, + }, { + label: intl.formatMessage(messages.edit), + click: () => openSettings({ + path: `services/edit/${service.id}`, + }), + }, { + type: 'separator', + }, { + label: service.isNotificationEnabled + ? intl.formatMessage(messages.disableNotifications) + : intl.formatMessage(messages.enableNotifications), + click: () => toggleNotifications(), + }, { + label: intl.formatMessage(messages.disableService), + click: () => disableService(), + }, { + type: 'separator', + }, { + label: intl.formatMessage(messages.deleteService), + click: () => deleteService(), + }]; + const menu = Menu.buildFromTemplate(menuTemplate); + + return ( +
  • menu.popup(remote.getCurrentWindow())} + data-tip={`${service.name} ${shortcutIndex <= 9 ? `(${ctrlKey}+${shortcutIndex})` : ''}`} + > + + {service.unreadDirectMessageCount > 0 && ( + + {service.unreadDirectMessageCount} + + )} + {service.unreadIndirectMessageCount > 0 + && service.unreadDirectMessageCount === 0 + && service.isIndirectMessageBadgeEnabled && ( + + • + + )} +
  • + ); + } +} + +export default SortableElement(TabItem); diff --git a/src/components/services/tabs/Tabbar.js b/src/components/services/tabs/Tabbar.js new file mode 100644 index 000000000..fdb2c0a59 --- /dev/null +++ b/src/components/services/tabs/Tabbar.js @@ -0,0 +1,77 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { observer, PropTypes as MobxPropTypes } from 'mobx-react'; + +import TabBarSortableList from './TabBarSortableList'; + +@observer +export default class TabBar extends Component { + static propTypes = { + services: MobxPropTypes.arrayOrObservableArray.isRequired, + setActive: PropTypes.func.isRequired, + openSettings: PropTypes.func.isRequired, + enableToolTip: PropTypes.func.isRequired, + disableToolTip: PropTypes.func.isRequired, + reorder: PropTypes.func.isRequired, + reload: PropTypes.func.isRequired, + toggleNotifications: PropTypes.func.isRequired, + deleteService: PropTypes.func.isRequired, + updateService: PropTypes.func.isRequired, + } + + onSortEnd = ({ oldIndex, newIndex }) => { + const { + enableToolTip, + reorder, + } = this.props; + + enableToolTip(); + reorder({ oldIndex, newIndex }); + }; + + disableService = ({ serviceId }) => { + const { updateService } = this.props; + + if (serviceId) { + updateService({ + serviceId, + serviceData: { + isEnabled: false, + }, + redirect: false, + }); + } + } + + render() { + const { + services, + setActive, + openSettings, + disableToolTip, + reload, + toggleNotifications, + deleteService, + } = this.props; + + return ( +
    + +
    + ); + } +} -- cgit v1.2.3-54-g00ecf