[mobile] Fix users and comments stores according to mobx v. 6
This commit is contained in:
parent
48c50b145b
commit
1cf1bb5df3
|
@ -1,11 +1,35 @@
|
||||||
|
|
||||||
import {observable, action, computed} from 'mobx';
|
import {makeObservable, observable, action, computed} from 'mobx';
|
||||||
|
|
||||||
export class storeComments {
|
export class storeComments {
|
||||||
@observable collectionComments = [];
|
constructor() {
|
||||||
@observable groupCollectionComments = [];
|
makeObservable(this, {
|
||||||
|
collectionComments: observable,
|
||||||
|
groupCollectionComments: observable,
|
||||||
|
filter: observable,
|
||||||
|
groupCollectionFilter: observable,
|
||||||
|
|
||||||
@action addComment (comment) {
|
addComment: action,
|
||||||
|
removeComment: action,
|
||||||
|
changeFilter: action,
|
||||||
|
|
||||||
|
sortComments: computed,
|
||||||
|
|
||||||
|
isOpenEditComment: observable,
|
||||||
|
openEditComment: action,
|
||||||
|
isOpenAddReply: observable,
|
||||||
|
openAddReply: action,
|
||||||
|
isOpenEditReply: observable,
|
||||||
|
openEditReply: action
|
||||||
|
})
|
||||||
|
}
|
||||||
|
collectionComments = [];
|
||||||
|
groupCollectionComments = [];
|
||||||
|
|
||||||
|
filter = undefined;
|
||||||
|
groupCollectionFilter = []; // for sse
|
||||||
|
|
||||||
|
addComment (comment) {
|
||||||
comment.groupName ? this.addCommentToGroupCollection(comment) : this.addCommentToCollection(comment);
|
comment.groupName ? this.addCommentToGroupCollection(comment) : this.addCommentToCollection(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +48,7 @@ export class storeComments {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action removeComment (id) {
|
removeComment (id) {
|
||||||
if (this.collectionComments.length > 0) {
|
if (this.collectionComments.length > 0) {
|
||||||
this.removeCommentFromCollection(id);
|
this.removeCommentFromCollection(id);
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,10 +81,7 @@ export class storeComments {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@observable filter; // for sse
|
changeFilter (filter) {
|
||||||
@observable groupCollectionFilter = []; // for sse
|
|
||||||
|
|
||||||
@action changeFilter (filter) {
|
|
||||||
let comments = [];
|
let comments = [];
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
filter.forEach((item) => {
|
filter.forEach((item) => {
|
||||||
|
@ -94,7 +115,7 @@ export class storeComments {
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get sortComments () {
|
get sortComments () {
|
||||||
const comments = (this.groupCollectionFilter.length !== 0) ? this.groupCollectionFilter : (this.collectionComments.length !== 0 ? this.collectionComments : false);
|
const comments = (this.groupCollectionFilter.length !== 0) ? this.groupCollectionFilter : (this.collectionComments.length !== 0 ? this.collectionComments : false);
|
||||||
if (comments.length > 0) {
|
if (comments.length > 0) {
|
||||||
return [...comments].sort((a, b) => a.time > b.time ? 1 : -1);
|
return [...comments].sort((a, b) => a.time > b.time ? 1 : -1);
|
||||||
|
@ -104,8 +125,8 @@ export class storeComments {
|
||||||
|
|
||||||
// Edit comment
|
// Edit comment
|
||||||
currentComment = null;
|
currentComment = null;
|
||||||
@observable isOpenEditComment = false;
|
isOpenEditComment = false;
|
||||||
@action openEditComment (open, comment) {
|
openEditComment (open, comment) {
|
||||||
if (open !== this.isOpenEditComment) {
|
if (open !== this.isOpenEditComment) {
|
||||||
this.currentComment = open ? comment : null;
|
this.currentComment = open ? comment : null;
|
||||||
this.isOpenEditComment = open;
|
this.isOpenEditComment = open;
|
||||||
|
@ -113,16 +134,16 @@ export class storeComments {
|
||||||
}
|
}
|
||||||
|
|
||||||
currentReply = null;
|
currentReply = null;
|
||||||
@observable isOpenAddReply = false;
|
isOpenAddReply = false;
|
||||||
@action openAddReply (open, comment) {
|
openAddReply (open, comment) {
|
||||||
if (open !== this.isOpenAddReply) {
|
if (open !== this.isOpenAddReply) {
|
||||||
this.currentComment = open ? comment : null;
|
this.currentComment = open ? comment : null;
|
||||||
this.isOpenAddReply = open;
|
this.isOpenAddReply = open;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@observable isOpenEditReply = false;
|
isOpenEditReply = false;
|
||||||
@action openEditReply (open, comment, reply) {
|
openEditReply (open, comment, reply) {
|
||||||
if (open !== this.isOpenEditReply) {
|
if (open !== this.isOpenEditReply) {
|
||||||
this.currentComment = open ? comment : null;
|
this.currentComment = open ? comment : null;
|
||||||
this.currentReply = open ? reply : null;
|
this.currentReply = open ? reply : null;
|
||||||
|
|
|
@ -1,16 +1,25 @@
|
||||||
|
|
||||||
import {observable, action, computed} from 'mobx';
|
import {makeObservable, observable, action} from 'mobx';
|
||||||
|
|
||||||
export class storeUsers {
|
export class storeUsers {
|
||||||
@observable users = [];
|
constructor() {
|
||||||
|
makeObservable(this, {
|
||||||
|
users: observable,
|
||||||
|
reset: action,
|
||||||
|
currentUser: observable,
|
||||||
|
setCurrentUser: action,
|
||||||
|
connection: action
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
@action reset(users) {
|
users = [];
|
||||||
|
currentUser;
|
||||||
|
|
||||||
|
reset (users) {
|
||||||
this.users = Object.values(users)
|
this.users = Object.values(users)
|
||||||
}
|
}
|
||||||
|
|
||||||
@observable currentUser;
|
setCurrentUser (id) {
|
||||||
|
|
||||||
@action setCurrentUser(id) {
|
|
||||||
this.users.forEach((item) => {
|
this.users.forEach((item) => {
|
||||||
if (item.asc_getIdOriginal() === id) {
|
if (item.asc_getIdOriginal() === id) {
|
||||||
this.currentUser = item;
|
this.currentUser = item;
|
||||||
|
@ -18,7 +27,7 @@ export class storeUsers {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@action connection (change) {
|
connection (change) {
|
||||||
let changed = false;
|
let changed = false;
|
||||||
for (let uid in this.users) {
|
for (let uid in this.users) {
|
||||||
if (undefined !== uid) {
|
if (undefined !== uid) {
|
||||||
|
|
Loading…
Reference in a new issue