[SSE mobile] Fix comments

This commit is contained in:
JuliaSvinareva 2021-03-26 16:23:17 +03:00
parent 56e316738e
commit 465fd40004
6 changed files with 56 additions and 101 deletions

View file

@ -272,10 +272,7 @@ class AddCommentController extends Component {
!!comment.asc_putDocumentFlag && comment.asc_putDocumentFlag(documentFlag);
api.asc_addComment(comment);
return true;
}
return false;
}
render() {
return(
@ -316,10 +313,10 @@ class EditCommentController extends Component {
ascComment.asc_putDocumentFlag(comment.unattached);
}
var reply = comment.replies;
const reply = comment.replies;
if (reply && reply.length > 0) {
reply.forEach((reply) => {
var addReply = (typeof Asc.asc_CCommentDataWord !== 'undefined' ? new Asc.asc_CCommentDataWord(null) : new Asc.asc_CCommentData(null));
const addReply = (typeof Asc.asc_CCommentDataWord !== 'undefined' ? new Asc.asc_CCommentDataWord(null) : new Asc.asc_CCommentData(null));
if (addReply) {
addReply.asc_putText(reply.reply);
addReply.asc_putTime(utcDateToString(new Date(reply.time)));

View file

@ -7,7 +7,6 @@ export class storeComments {
collectionComments: observable,
groupCollectionComments: observable,
filter: observable,
groupCollectionFilter: observable,
showComments: observable,
changeShowComment: action,
@ -17,7 +16,7 @@ export class storeComments {
changeComment: action,
changeFilter: action,
sortComments: computed,
groupCollectionFilter: computed,
isOpenEditComment: observable,
openEditComment: action,
@ -31,7 +30,6 @@ export class storeComments {
groupCollectionComments = [];
filter = undefined;
groupCollectionFilter = []; // for sse
showComments = [];
changeShowComment (uid) {
@ -42,54 +40,16 @@ export class storeComments {
}
addComment (comment) {
comment.groupName ? this.addCommentToGroupCollection(comment) : this.addCommentToCollection(comment);
}
addCommentToCollection (comment) {
this.collectionComments.push(comment);
}
addCommentToGroupCollection (comment) {
const groupName = comment.groupName;
if (!this.groupCollectionComments[groupName]) {
this.groupCollectionComments[groupName] = [];
}
this.groupCollectionComments[groupName].push(comment);
if (typeof this.filter === 'object' && this.filter.indexOf(groupName) !== -1) {
this.groupCollectionFilter.push(comment);
}
comment.groupName ? this.groupCollectionComments.push(comment) : this.collectionComments.push(comment);
}
removeComment (id) {
if (this.collectionComments.length > 0) {
this.removeCommentFromCollection(id);
} else {
this.removeCommentFromGroups(id);
}
}
removeCommentFromCollection (id) {
const index = this.collectionComments.findIndex((comment) => {
const collection = this.collectionComments.length > 0 ? this.collectionComments : this.groupCollectionComments;
const index = collection.findIndex((comment) => {
return comment.uid === id;
});
if (index !== -1) {
this.collectionComments.splice(index, 1);
}
}
removeCommentFromGroups (id) {
for (let name in this.groupCollectionComments) {
const store = this.groupCollectionComments[name];
const comment = store.find((item) => {
return item.uid === id;
});
const index = store.indexOf(comment);
if (index !== -1) {
this.groupCollectionComments[name].splice(index, 1);
if (typeof this.filter === 'object' && this.filter.indexOf(name) !== -1) {
this.groupCollectionFilter.splice(this.groupCollectionFilter.indexOf(comment), 1);
}
}
collection.splice(index, 1);
}
}
@ -111,43 +71,28 @@ export class storeComments {
}
changeFilter (filter) {
let comments = [];
this.filter = filter;
filter.forEach((item) => {
if (!this.groupCollectionComments[item])
this.groupCollectionComments[item] = [];
comments = comments.concat(this.groupCollectionComments[item]);
});
this.groupCollectionFilter = comments;
}
findComment (id) {
let comment = this.collectionComments.find((item) => {
const collection = this.collectionComments.length > 0 ? this.collectionComments : this.groupCollectionComments;
let comment = collection.find((item) => {
return item.uid === id;
});
if (!comment) {
comment = this.findCommentInGroup(id);
}
return comment;
}
findCommentInGroup (id) {
let model;
for (let name in this.groupCollectionComments) {
const store = this.groupCollectionComments[name];
const uid = typeof id === 'object' && id.isArray() ? id[0] : id;
model = store.find((item) => {
return item.uid === uid;
get groupCollectionFilter () {
if (this.filter && this.groupCollectionComments.length > 0) {
const arr = [];
this.filter.forEach((groupName) => {
this.groupCollectionComments.forEach((comment) => {
if (comment.groupName === groupName) {
arr.push(comment);
}
});
});
if (model) return model;
}
return model;
}
get sortComments () {
const comments = (this.groupCollectionFilter.length !== 0) ? this.groupCollectionFilter : (this.collectionComments.length !== 0 ? this.collectionComments : false);
if (comments.length > 0) {
return [...comments].sort((a, b) => a.time > b.time ? 1 : -1);
return arr;
}
return false;
}

View file

@ -41,12 +41,11 @@ const AddCommentPopup = inject("storeComments")(observer(props => {
<NavRight>
<Link className={stateText.length === 0 && 'disabled'}
onClick={() => {
if (props.onAddNewComment(stateText, false)) {
f7.popup.close('.add-comment-popup');
setTimeout(() => {
props.closeAddComment();
}, 500)
}
f7.popup.close('.add-comment-popup');
setTimeout(() => {
props.closeAddComment();
props.onAddNewComment(stateText, false)
}, 500);
}}>
{Device.android ? <Icon icon='icon-done-comment-white'/> : _t.textDone}
</Link>
@ -108,9 +107,10 @@ const AddCommentDialog = inject("storeComments")(observer(props => {
const done = document.getElementById('comment-done');
done.addEventListener('click', () => {
const value = document.getElementById('comment-text').value;
if (value.length > 0 && props.onAddNewComment(value, false)) {
if (value.length > 0) {
f7.dialog.close();
props.closeAddComment();
props.onAddNewComment(value, false);
}
});
const area = document.getElementById('comment-text');
@ -197,16 +197,20 @@ const EditCommentPopup = inject("storeComments")(observer(({storeComments, comme
<NavLeft>
<Link onClick={() => {
f7.popup.close('.edit-comment-popup');
storeComments.openEditComment(false);
setTimeout(() => {
storeComments.openEditComment(false);
}, 500);
}}>{_t.textCancel}</Link>
</NavLeft>
<NavTitle>{_t.textEditComment}</NavTitle>
<NavRight>
<Link className={stateText.length === 0 && 'disabled'}
onClick={() => {
onEditComment(comment, stateText);
f7.popup.close('.edit-comment-popup');
storeComments.openEditComment(false);
setTimeout(() => {
storeComments.openEditComment(false);
onEditComment(comment, stateText);
}, 500);
}}
>
{Device.android ? <Icon icon='icon-done-comment-white'/> : _t.textDone}
@ -317,17 +321,21 @@ const AddReplyPopup = inject("storeComments")(observer(({storeComments, userInfo
<Navbar>
<NavLeft>
<Link onClick={() => {
storeComments.openAddReply(false);
f7.popup.close('.add-reply-popup');
setTimeout(() => {
storeComments.openAddReply(false);
}, 500);
}}>{_t.textCancel}</Link>
</NavLeft>
<NavTitle>{_t.textAddReply}</NavTitle>
<NavRight>
<Link className={stateText.length === 0 && 'disabled'}
onClick={() => {
onAddReply(comment, stateText);
storeComments.openAddReply(false);
f7.popup.close('.add-reply-popup');
setTimeout(() => {
storeComments.openAddReply(false);
onAddReply(comment, stateText);
}, 500);
}}>
{Device.android ? <Icon icon='icon-done-comment-white'/> : _t.textDone}
</Link>
@ -433,16 +441,20 @@ const EditReplyPopup = inject("storeComments")(observer(({storeComments, comment
<NavLeft>
<Link onClick={() => {
f7.popup.close('.edit-reply-popup');
storeComments.openEditReply(false);
setTimeout(() => {
storeComments.openEditReply(false);
}, 500);
}}>{_t.textCancel}</Link>
</NavLeft>
<NavTitle>{_t.textEditReply}</NavTitle>
<NavRight>
<Link className={stateText.length === 0 && 'disabled'}
onClick={() => {
onEditReply(comment, reply, stateText);
f7.popup.close('.edit-reply-popup');
storeComments.openEditReply(false);
setTimeout(() => {
storeComments.openEditReply(false);
onEditReply(comment, reply, stateText);
}, 500);
}}
>
{Device.android ? <Icon icon='icon-done-comment-white'/> : _t.textDone}
@ -548,7 +560,8 @@ const ViewComments = ({storeComments, storeAppOptions, onCommentMenuClick, onRes
const isAndroid = Device.android;
const viewMode = !storeAppOptions.canComments;
const comments = storeComments.sortComments;
const comments = storeComments.groupCollectionFilter || storeComments.collectionComments;
const sortComments = comments.length > 0 ? [...comments].sort((a, b) => a.time > b.time ? 1 : -1) : null;
const [clickComment, setComment] = useState();
const [commentActionsOpened, openActionComment] = useState(false);
@ -559,10 +572,10 @@ const ViewComments = ({storeComments, storeAppOptions, onCommentMenuClick, onRes
return (
<Page>
<Navbar title={_t.textComments} backLink={_t.textBack}/>
{!comments ?
{!sortComments ?
<div className='no-comments'>{_t.textNoComments}</div> :
<List className='comment-list'>
{comments.map((comment, indexComment) => {
{sortComments.map((comment, indexComment) => {
return (
<ListItem key={`comment-${indexComment}`}>
<div slot='header' className='comment-header'>

View file

@ -22,7 +22,8 @@ class AddOtherController extends Component {
const cellinfo = Common.EditorApi.get().asc_getCellInfo();
const iscelllocked = cellinfo.asc_getLocked();
const seltype = cellinfo.asc_getSelectionType();
return !(seltype === Asc.c_oAscSelectionType.RangeCells && !iscelllocked);
const isComments = cellinfo.asc_getComments().length > 0;
return (!(seltype === Asc.c_oAscSelectionType.RangeCells && !iscelllocked) || isComments);
}
render () {

View file

@ -34,9 +34,8 @@ export default class extends React.Component {
return (
<App { ...f7params } >
{/* Your main view, should have "view-main" class */}
<View main className="safe-areas" url="/">
<MainController />
</View>
<View main className="safe-areas" url="/" />
<MainController />
</App>
)
}

View file

@ -70,7 +70,7 @@ export default class MainPage extends Component {
<Link id='btn-edit' icon='icon-edit-settings' href={false} onClick={e => this.handleClickToOpenOptions('edit')}></Link>
<Link id='btn-add' icon='icon-plus' href={false} onClick={e => this.handleClickToOpenOptions('add')}></Link>
{ Device.phone ? null : <Link icon='icon-search' searchbarEnable='.searchbar' href={false}></Link> }
<Link href={false} icon='icon-collaboration' onClick={e => this.handleClickToOpenOptions('coauth')}></Link>
<Link id='btn-coauth' href={false} icon='icon-collaboration' onClick={e => this.handleClickToOpenOptions('coauth')}></Link>
<Link id='btn-settings' icon='icon-settings' href={false} onClick={e => this.handleClickToOpenOptions('settings')}></Link>
</NavRight>
<Search useSuspense={false} />