aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/util/GroupManager.tsx20
-rw-r--r--src/client/util/SharingManager.tsx35
2 files changed, 42 insertions, 13 deletions
diff --git a/src/client/util/GroupManager.tsx b/src/client/util/GroupManager.tsx
index fb3342e68..3264b75f7 100644
--- a/src/client/util/GroupManager.tsx
+++ b/src/client/util/GroupManager.tsx
@@ -1,11 +1,11 @@
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { action, computed, observable, runInAction } from "mobx";
+import { action, autorun, computed, Lambda, observable, reaction, runInAction } from "mobx";
import { observer } from "mobx-react";
import * as React from "react";
import Select from 'react-select';
import * as RequestPromise from "request-promise";
import { Doc, DocListCast, DocListCastAsync, Opt } from "../../fields/Doc";
-import { Cast, StrCast } from "../../fields/Types";
+import { StrCast } from "../../fields/Types";
import { setGroups } from "../../fields/util";
import { Utils } from "../../Utils";
import { DocServer } from "../DocServer";
@@ -34,10 +34,12 @@ export class GroupManager extends React.Component<{}> {
@observable private createGroupModalOpen: boolean = false;
private inputRef: React.RefObject<HTMLInputElement> = React.createRef(); // the ref for the input box.
private createGroupButtonRef: React.RefObject<HTMLButtonElement> = React.createRef(); // the ref for the group creation button
- private currentUserGroups: string[] = []; // the list of groups the current user is a member of
+ private currentUserGroups: string[] = ["Public"]; // the list of groups the current user is a member of
@observable private buttonColour: "#979797" | "black" = "#979797";
@observable private groupSort: "ascending" | "descending" | "none" = "none";
private populating: boolean = false;
+ private groupListener: Opt<Lambda>;
+ private observableAllGroups: Doc[] = observable([]);
@@ -51,7 +53,11 @@ export class GroupManager extends React.Component<{}> {
*/
componentDidMount() {
this.populateUsers();
- this.populateGroups();
+ this.groupListener = autorun(this.populateGroups);
+ }
+
+ componentWillUnmount() {
+ this.groupListener?.();
}
/**
@@ -77,13 +83,15 @@ export class GroupManager extends React.Component<{}> {
* Populates the list of groups the current user is a member of and sets this list to be used in the GetEffectiveAcl in util.ts
*/
populateGroups = () => {
+ this.observableAllGroups.map(g => g.members);
DocListCastAsync(this.GroupManagerDoc?.data).then(groups => {
groups?.forEach(group => {
const members: string[] = JSON.parse(StrCast(group.members));
- if (members.includes(Doc.CurrentUserEmail)) this.currentUserGroups.push(StrCast(group.groupName));
+ if (members.includes(Doc.CurrentUserEmail) && this.currentUserGroups.indexOf(StrCast(group.groupName)) === -1) this.currentUserGroups.push(StrCast(group.groupName));
+ if (this.observableAllGroups.indexOf(group) === -1) runInAction(() => this.observableAllGroups.push(group));
});
- this.currentUserGroups.push("Public");
setGroups(this.currentUserGroups);
+ console.log("populating groups");
});
}
diff --git a/src/client/util/SharingManager.tsx b/src/client/util/SharingManager.tsx
index 6c1ec6091..742811c18 100644
--- a/src/client/util/SharingManager.tsx
+++ b/src/client/util/SharingManager.tsx
@@ -4,7 +4,7 @@ import { observer } from "mobx-react";
import * as React from "react";
import Select from "react-select";
import * as RequestPromise from "request-promise";
-import { AclAdmin, AclPrivate, DataSym, Doc, DocListCast, Opt, AclSym, AclAddonly, AclEdit, AclReadonly } from "../../fields/Doc";
+import { AclAdmin, AclPrivate, DataSym, Doc, DocListCast, Opt, AclSym, AclAddonly, AclEdit, AclReadonly, DocListCastAsync } from "../../fields/Doc";
import { List } from "../../fields/List";
import { Cast, StrCast } from "../../fields/Types";
import { distributeAcls, GetEffectiveAcl, SharingPermissions, TraceMobx, normalizeEmail } from "../../fields/util";
@@ -145,9 +145,9 @@ export class SharingManager extends React.Component<{}> {
});
return Promise.all(evaluating).then(() => {
runInAction(() => {
- for (let i = 0; i < sharingDocs.length; i++) {
- if (!this.users.find(user => user.user.email === sharingDocs[i].user.email)) {
- this.users.push(sharingDocs[i]);
+ for (const sharingDoc of sharingDocs) {
+ if (!this.users.find(user => user.user.email === sharingDoc.user.email)) {
+ this.users.push(sharingDoc);
}
}
});
@@ -195,7 +195,21 @@ export class SharingManager extends React.Component<{}> {
*/
shareWithAddedMember = (group: Doc, emailId: string) => {
const user: ValidatedUser = this.users.find(({ user: { email } }) => email === emailId)!;
- if (group.docsShared) DocListCast(group.docsShared).forEach(doc => Doc.IndexOf(doc, DocListCast(user.sharingDoc[storage])) === -1 && Doc.AddDocToList(user.sharingDoc, storage, doc));
+ if (group.docsShared) {
+ DocListCastAsync(group.docsShared).then(async docs => {
+ if (docs) {
+ const memberDocs = await DocListCastAsync(user.sharingDoc[storage]);
+ memberDocs && docs.forEach(doc => {
+ const index = Doc.IndexOf(doc, memberDocs);
+ console.log(index);
+ console.log(doc);
+ index === -1 && (console.log(Doc.AddDocToList(user.sharingDoc, storage, doc)));
+ });
+ }
+
+ });
+ // === -1 && Doc.AddDocToList(user.sharingDoc, storage, doc));
+ }
}
/**
@@ -225,9 +239,16 @@ export class SharingManager extends React.Component<{}> {
const user: ValidatedUser = this.users.find(({ user: { email } }) => email === emailId)!;
if (group.docsShared) {
- DocListCast(group.docsShared).forEach(doc => {
- Doc.IndexOf(doc, DocListCast(user.sharingDoc[storage])) !== -1 && Doc.RemoveDocFromList(user.sharingDoc, storage, doc); // remove the doc only if it is in the list
+ DocListCastAsync(group.docsShared).then(docs => {
+ docs?.forEach(doc => {
+ DocListCastAsync(user.sharingDoc[storage]).then(sharedDocs => {
+ sharedDocs && Doc.IndexOf(doc, sharedDocs) !== -1 && Doc.RemoveDocFromList(user.sharingDoc, storage, doc);
+ });
+ });
});
+ // DocListCast(group.docsShared).forEach(doc => {
+ // Doc.IndexOf(doc, DocListCast(user.sharingDoc[storage])) !== -1 && Doc.RemoveDocFromList(user.sharingDoc, storage, doc); // remove the doc only if it is in the list
+ // });
}
}