import React, {useState, useEffect} from 'react'; import {observer, inject} from "mobx-react"; import { f7, Popup, Page, Navbar, NavLeft, NavRight, NavTitle, Link, Input, Icon, List, ListItem } from 'framework7-react'; import { useTranslation } from 'react-i18next'; import {Device} from '../../../utils/device'; // Add comment const AddCommentPopup = inject("storeComments")(observer(props => { const { t } = useTranslation(); const _t = t('Common.Collaboration', {returnObjects: true}); useEffect(() => { f7.popup.open('.add-comment-popup'); }); const userInfo = props.userInfo; const [stateText, setText] = useState(''); return ( { props.storeComments.openAddComment(false); f7.popup.close('.add-comment-popup'); }}>{_t.textCancel} {_t.textAddComment} { if (props.onAddNewComment(stateText, false)) { props.storeComments.openAddComment(false); f7.popup.close('.add-comment-popup'); } }}> {Device.android ? : _t.textDone}
{Device.android &&
{userInfo.initials}
}
{userInfo.name}
{setText(event.target.value);}}>
) })); const AddCommentDialog = inject("storeComments")(observer(props => { const { t } = useTranslation(); const _t = t('Common.Collaboration', {returnObjects: true}); const userInfo = props.userInfo; const templateInitials = `
${userInfo.initials}
`; useEffect(() => { f7.dialog.create({ destroyOnClose: true, containerEl: document.getElementById('add-comment-dialog'), content: `
${Device.android ? templateInitials : ''}
${userInfo.name}
`, on: { opened: () => { const cancel = document.getElementById('comment-cancel'); cancel.addEventListener('click', () => { f7.dialog.close(); props.storeComments.openAddComment(false); }); const done = document.getElementById('comment-done'); done.addEventListener('click', () => { const value = document.getElementById('comment-text').value; if (value.length > 0 && props.onAddNewComment(value, false)) { f7.dialog.close(); props.storeComments.openAddComment(false); } }); const area = document.getElementById('comment-text'); area.addEventListener('input', (event) => { if (event.target.value.length === 0 && !done.classList.contains('disabled')) { done.classList.add('disabled'); } else if (event.target.value.length > 0 && done.classList.contains('disabled')) { done.classList.remove('disabled'); } }); done.classList.add('disabled'); } } }).open(); }); return (
); })); const AddComment = props => { return ( Device.phone ? : ) }; // View comments const ViewComments = ({storeComments}) => { const { t } = useTranslation(); const _t = t('Common.Collaboration', {returnObjects: true}); const comments = storeComments.sortComments; return ( {!comments ?
{_t.textNoComments}
: {comments.map((comment, indexComment) => { return (
{comment.userName}
{comment.date}
{comment.quote}
{comment.comment}
{comment.replies.length > 0 &&
    {comment.replies.map((reply, indexReply) => { return (
  • {reply.userName}
    {reply.date}
    {reply.reply}
  • ) })}
}
) })}
}
) }; const _ViewComments = inject('storeComments')(observer(ViewComments)); export { AddComment, _ViewComments as ViewComments }