From febc614ce8278fde4a85ef1f7bb4eec94b7c3862 Mon Sep 17 00:00:00 2001 From: Maksim Eltyshev Date: Wed, 29 Apr 2020 23:55:16 +0500 Subject: [PATCH] Add attachment popup, hide attachments if more than 4 --- .../components/CardModal/AddAttachment.jsx | 23 -------- .../CardModal/AddAttachmentPopup.jsx | 54 +++++++++++++++++++ .../CardModal/AddAttachmentPopup.module.css | 20 +++++++ .../CardModal/Attachments/Attachments.jsx | 30 ++++++++++- .../Attachments/Attachments.module.css | 16 ++++++ client/src/components/CardModal/CardModal.jsx | 6 +-- client/src/locales/en/app.js | 6 +++ client/src/locales/ru/app.js | 6 +++ 8 files changed, 134 insertions(+), 27 deletions(-) delete mode 100644 client/src/components/CardModal/AddAttachment.jsx create mode 100644 client/src/components/CardModal/AddAttachmentPopup.jsx create mode 100644 client/src/components/CardModal/AddAttachmentPopup.module.css create mode 100644 client/src/components/CardModal/Attachments/Attachments.module.css diff --git a/client/src/components/CardModal/AddAttachment.jsx b/client/src/components/CardModal/AddAttachment.jsx deleted file mode 100644 index b71926da..00000000 --- a/client/src/components/CardModal/AddAttachment.jsx +++ /dev/null @@ -1,23 +0,0 @@ -import React, { useCallback } from 'react'; -import PropTypes from 'prop-types'; -import { FilePicker } from '../../lib/custom-ui'; - -const AddAttachment = React.memo(({ children, onCreate }) => { - const handleFileSelect = useCallback( - (file) => { - onCreate({ - file, - }); - }, - [onCreate], - ); - - return {children}; -}); - -AddAttachment.propTypes = { - children: PropTypes.element.isRequired, - onCreate: PropTypes.func.isRequired, -}; - -export default AddAttachment; diff --git a/client/src/components/CardModal/AddAttachmentPopup.jsx b/client/src/components/CardModal/AddAttachmentPopup.jsx new file mode 100644 index 00000000..de31b830 --- /dev/null +++ b/client/src/components/CardModal/AddAttachmentPopup.jsx @@ -0,0 +1,54 @@ +import React, { useCallback } from 'react'; +import PropTypes from 'prop-types'; +import { useTranslation } from 'react-i18next'; +import { Menu } from 'semantic-ui-react'; +import { withPopup } from '../../lib/popup'; +import { FilePicker, Popup } from '../../lib/custom-ui'; + +import styles from './AddAttachmentPopup.module.css'; + +const AddAttachmentStep = React.memo(({ onCreate, onClose }) => { + const [t] = useTranslation(); + + const handleFileSelect = useCallback( + (file) => { + onCreate({ + file, + }); + onClose(); + }, + [onCreate, onClose], + ); + + return ( + <> + + {t('common.addAttachment', { + context: 'title', + })} + + + + + + {t('common.fromComputer', { + context: 'title', + })} + + + +
+
+ {t('common.pressPasteShortcutToAddAttachmentFromClipboard')} +
+
+ + ); +}); + +AddAttachmentStep.propTypes = { + onCreate: PropTypes.func.isRequired, + onClose: PropTypes.func.isRequired, +}; + +export default withPopup(AddAttachmentStep); diff --git a/client/src/components/CardModal/AddAttachmentPopup.module.css b/client/src/components/CardModal/AddAttachmentPopup.module.css new file mode 100644 index 00000000..8f831bab --- /dev/null +++ b/client/src/components/CardModal/AddAttachmentPopup.module.css @@ -0,0 +1,20 @@ +.divider { + background-color: #eee; + border: 0; + height: 1px; + margin-bottom: 8px; +} + +.menu { + margin: -7px -12px -5px !important; + width: calc(100% + 24px) !important; +} + +.menuItem { + margin: 0 !important; + padding-left: 14px !important; +} + +.tip { + opacity: 0.5; +} diff --git a/client/src/components/CardModal/Attachments/Attachments.jsx b/client/src/components/CardModal/Attachments/Attachments.jsx index 4c95f08e..a62c4006 100644 --- a/client/src/components/CardModal/Attachments/Attachments.jsx +++ b/client/src/components/CardModal/Attachments/Attachments.jsx @@ -1,9 +1,21 @@ import React, { useCallback } from 'react'; import PropTypes from 'prop-types'; +import { useTranslation } from 'react-i18next'; +import { Button } from 'semantic-ui-react'; +import { useToggle } from '../../../lib/hooks'; import Item from './Item'; +import styles from './Attachments.module.css'; + const Attachments = React.memo(({ items, onUpdate, onDelete, onCoverUpdate }) => { + const [t] = useTranslation(); + const [isOpened, toggleOpened] = useToggle(); + + const handleToggleClick = useCallback(() => { + toggleOpened(); + }, [toggleOpened]); + const handleCoverSelect = useCallback( (id) => { onCoverUpdate(id); @@ -29,9 +41,11 @@ const Attachments = React.memo(({ items, onUpdate, onDelete, onCoverUpdate }) => [onDelete], ); + const visibleItems = isOpened ? items : items.slice(0, 4); + return ( <> - {items.map((item) => ( + {visibleItems.map((item) => ( onDelete={() => handleDelete(item.id)} /> ))} + {items.length > 4 && ( + - + - +
{t('common.actions')} diff --git a/client/src/locales/en/app.js b/client/src/locales/en/app.js index eb2d68be..6e25c00d 100644 --- a/client/src/locales/en/app.js +++ b/client/src/locales/en/app.js @@ -11,6 +11,7 @@ export default { common: { account: 'Account', actions: 'Actions', + addAttachment_title: 'Add Attachment', addComment: 'Add comment', addMember_title: 'Add Member', addUser_title: 'Add User', @@ -77,6 +78,7 @@ export default { enterTaskDescription: 'Enter task description...', filterByLabels_title: 'Filter By Labels', filterByMembers_title: 'Filter By Members', + fromComputer_title: 'From Computer', hours: 'Hours', invalidCurrentPassword: 'Invalid current password', labels: 'Labels', @@ -95,6 +97,8 @@ export default { organization: 'Organization', phone: 'Phone', preferences: 'Preferences', + pressPasteShortcutToAddAttachmentFromClipboard: + 'Tip: press Ctrl-V (Cmd-V on Mac) to add an attachment from the clipboard.', projectNotFound_title: 'Project Not Found', refreshPageToLoadLastDataAndReceiveUpdates: '<0>Refresh the page to load last data
and receive updates', @@ -166,6 +170,8 @@ export default { removeFromProject: 'Remove from project', removeMember: 'Remove member', save: 'Save', + showAllAttachments: 'Show all attachments ({{hidden}} hidden)', + showFewerAttachments: 'Show fewer attachments', start: 'Start', stop: 'Stop', subscribe: 'Subscribe', diff --git a/client/src/locales/ru/app.js b/client/src/locales/ru/app.js index 8219f827..3ad24e1e 100644 --- a/client/src/locales/ru/app.js +++ b/client/src/locales/ru/app.js @@ -15,6 +15,7 @@ export default { common: { account: 'Учетная запись', actions: 'Действия', + addAttachment: 'Добавление вложения', addComment: 'Добавление комментария', addMember: 'Добавление участника', addUser: 'Добавление пользователя', @@ -81,6 +82,7 @@ export default { enterTaskDescription: 'Введите описание задачи...', filterByLabels: 'Фильтр по меткам', filterByMembers: 'Фильтр по участникам', + fromComputer: 'С компьютера', hours: 'Часы', invalidCurrentPassword: 'Неверный текущий пароль', labels: 'Метки', @@ -99,6 +101,8 @@ export default { organization: 'Организация', phone: 'Телефон', preferences: 'Предпочтения', + pressPasteShortcutToAddAttachmentFromClipboard: + 'Совет: нажмите Ctrl-V (Cmd-V на Mac), чтобы добавить вложение из буфера обмена.', projectNotFound: 'Доска не найдена', refreshPageToLoadLastDataAndReceiveUpdates: '<0>Обновите страницу, чтобы загрузить
актуальные данные и получать обновления', @@ -167,6 +171,8 @@ export default { removeFromProject: 'Удалить из проекта', removeMember: 'Удалить участника', save: 'Сохранить', + showAllAttachments: 'Показать все вложения ({{hidden}} скрыто)', + showFewerAttachments: 'Показать меньше вложений', start: 'Начать', stop: 'Остановить', subscribe: 'Подписаться',