aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorMohammad Amoush <mohammad_amoush@brown.edu>2019-07-08 19:19:25 -0400
committerMohammad Amoush <mohammad_amoush@brown.edu>2019-07-08 19:19:25 -0400
commitbfd6e4cfbe79f75ba68e94e29e858611ec8f9f9c (patch)
treed42c737b3307b50af7ef046c7ca23713fc4a72b4 /src/client
parent288198ab8aa8127bb69928ab9a827af146287cb2 (diff)
SOme bugs fixed but still buggy
Diffstat (limited to 'src/client')
-rw-r--r--src/client/views/presentationview/PresentationElement.tsx86
-rw-r--r--src/client/views/presentationview/PresentationList.tsx10
-rw-r--r--src/client/views/presentationview/PresentationView.tsx9
3 files changed, 87 insertions, 18 deletions
diff --git a/src/client/views/presentationview/PresentationElement.tsx b/src/client/views/presentationview/PresentationElement.tsx
index 95e949b87..83fca88da 100644
--- a/src/client/views/presentationview/PresentationElement.tsx
+++ b/src/client/views/presentationview/PresentationElement.tsx
@@ -35,7 +35,7 @@ interface PresentationElementProps {
presButtonBackUp: Doc;
presGroupBackUp: Doc;
removeDocByRef(doc: Doc): boolean;
- setPresElementsMappings: (keyDoc: Doc, elem: PresentationElement) => void;
+ PresElementsMappings: Map<Doc, PresentationElement>;
}
@@ -103,6 +103,9 @@ export default class PresentationElement extends React.Component<PresentationEle
async componentDidUpdate() {
//this.receiveButtonBackUp();
//this.props.setPresElementsMappings(this.props.document, this);
+ if (!this.props.PresElementsMappings.has(this.props.document)) {
+ this.props.PresElementsMappings.set(this.props.document, this);
+ }
if (this.presElRef.current) {
this.header = this.presElRef.current;
@@ -447,7 +450,8 @@ export default class PresentationElement extends React.Component<PresentationEle
//where does treeViewId come from
let movedDocs = (de.data.options === this.props.mainDocument[Id] ? de.data.draggedDocuments : de.data.droppedDocuments);
//console.log("How is this causing an issue");
- this.updateGroupsOnDrop(de.data.droppedDocuments[0]);
+ let droppedDoc: Doc = de.data.droppedDocuments[0];
+ this.updateGroupsOnDrop(droppedDoc);
document.removeEventListener("pointermove", this.onDragMove, true);
return (de.data.dropAction || de.data.userDropAction) ?
de.data.droppedDocuments.reduce((added: boolean, d: Doc) => Doc.AddDocToList(this.props.mainDocument, "data", d, this.props.document, before) || added, false)
@@ -463,27 +467,85 @@ export default class PresentationElement extends React.Component<PresentationEle
updateGroupsOnDrop = async (droppedDoc: Doc) => {
let p = this.props;
let droppedDocSelectedButtons: boolean[] = await this.getSelectedButtonsOfDoc(droppedDoc);
+ let droppedDocIndex = this.props.allListElements.indexOf(droppedDoc);
+ let curDocGuid = StrCast(droppedDoc.presentId, null);
if (droppedDocSelectedButtons[buttonIndex.Group]) {
- let curDocGuid = StrCast(droppedDoc.presentId, null);
if (curDocGuid) {
if (p.groupMappings.has(curDocGuid)) {
+ console.log("Splicing from a group");
let groupArray = this.props.groupMappings.get(curDocGuid)!;
groupArray.splice(groupArray.indexOf(droppedDoc), 1);
+ droppedDoc.presentId = Utils.GenerateGuid();
+ }
+ }
+ let aboveDocIndex: number;
+ if (droppedDocIndex >= 1) {
+ aboveDocIndex = droppedDocIndex - 1;
+
+ let aboveDoc: Doc = this.props.allListElements[aboveDocIndex];
+ let aboveDocGuid = StrCast(aboveDoc.presentId, null);
+ console.log("Above document: ", aboveDoc, " has presentId: ", aboveDocGuid);
+ console.log("Dropped document: ", droppedDoc, " has presentId: ", curDocGuid);
+
+ if (p.groupMappings.has(aboveDocGuid)) {
+ p.groupMappings.get(aboveDocGuid)!.push(droppedDoc);
+ droppedDoc.presentId = aboveDocGuid;
+ console.log("First case got called!");
+ } else {
+ let newGroup: Doc[] = [];
+ newGroup.push(p.document);
+ newGroup.push(droppedDoc);
+ droppedDoc.presentId = aboveDocGuid;
+ p.groupMappings.set(aboveDocGuid, newGroup);
+ console.log("Second case got called!");
}
}
+ } else {
- let aboveDocGuid = StrCast(p.document.presentId, null);
- if (p.groupMappings.has(aboveDocGuid)) {
- p.groupMappings.get(aboveDocGuid)!.push(droppedDoc);
- } else {
- let newGroup: Doc[] = [];
- newGroup.push(p.document);
- newGroup.push(droppedDoc);
- droppedDoc.presentId = aboveDocGuid;
- p.groupMappings.set(aboveDocGuid, newGroup);
+ if (p.groupMappings.has(curDocGuid)) {
+ droppedDoc.presentId = Utils.GenerateGuid();
}
+ if (droppedDocIndex < this.props.allListElements.length - 1) {
+ let belowDoc = this.props.allListElements[droppedDocIndex + 1];
+ let belowDocSelectedButtons: boolean[] = await this.getSelectedButtonsOfDoc(belowDoc);
+
+ if (belowDocSelectedButtons[buttonIndex.Group]) {
+ if (droppedDocIndex >= 1) {
+ let aboveDocIndex = droppedDocIndex - 1;
+
+ let aboveDoc: Doc = this.props.allListElements[aboveDocIndex];
+ let aboveDocGuid = StrCast(aboveDoc.presentId, null);
+ let aboveGroupArray = this.props.groupMappings.get(aboveDocGuid)!;
+ let aboveDocSelectedButtons: boolean[] = await this.getSelectedButtonsOfDoc(aboveDoc);
+
+ if (aboveDocSelectedButtons[buttonIndex.Group]) {
+
+ let targetIndex = aboveGroupArray.indexOf(aboveDoc);
+ let firstPart = aboveGroupArray.slice(0, targetIndex + 1);
+ let firstPartNewGuid = Utils.GenerateGuid();
+ firstPart.forEach((doc: Doc) => doc.presentId = firstPartNewGuid);
+ let secondPart = aboveGroupArray.slice(targetIndex + 1);
+ p.groupMappings.set(StrCast(aboveDoc.presentId, Utils.GenerateGuid()), firstPart);
+ p.groupMappings.set(StrCast(belowDoc.presentId, Utils.GenerateGuid()), secondPart);
+
+ } else {
+ let belowDocPresentId = StrCast(belowDoc.presentId);
+ let groupArray: Doc[] = this.props.groupMappings.get(belowDocPresentId)!;
+ groupArray.splice(groupArray.indexOf(aboveDoc), 1);
+ aboveDoc.presentId = Utils.GenerateGuid();
+ droppedDoc.presentId = belowDocPresentId;
+ groupArray.push(droppedDoc);
+ }
+ }
+ }
+
+
+
+ }
}
+
+ console.log("New Groups: ", p.groupMappings);
}
getSelectedButtonsOfDoc = async (paramDoc: Doc) => {
diff --git a/src/client/views/presentationview/PresentationList.tsx b/src/client/views/presentationview/PresentationList.tsx
index 90a163f20..2d63d41b5 100644
--- a/src/client/views/presentationview/PresentationList.tsx
+++ b/src/client/views/presentationview/PresentationList.tsx
@@ -19,12 +19,13 @@ interface PresListProps {
deleteDocument(index: number): void;
gotoDocument(index: number, fromDoc: number): Promise<void>;
groupMappings: Map<String, Doc[]>;
- setPresElementsMappings: (keyDoc: Doc, elem: PresentationElement) => void;
+ PresElementsMappings: Map<Doc, PresentationElement>;
setChildrenDocs: (docList: Doc[]) => void;
presStatus: boolean;
presButtonBackUp: Doc;
presGroupBackUp: Doc;
removeDocByRef(doc: Doc): boolean;
+ clearElemMap(): void;
}
@@ -84,13 +85,14 @@ export default class PresentationViewList extends React.Component<PresListProps>
this.initializeGroupIds(children);
this.initializeScaleViews(children);
this.props.setChildrenDocs(children);
+ this.props.clearElemMap();
return (
<div className="presentationView-listCont" >
{children.map((doc: Doc, index: number) =>
<PresentationElement
ref={(e) => {
- if (e) {
- this.props.setPresElementsMappings(doc, e);
+ if (e && e !== null) {
+ this.props.PresElementsMappings.set(doc, e);
}
}}
key={doc[Id]}
@@ -105,7 +107,7 @@ export default class PresentationViewList extends React.Component<PresListProps>
presButtonBackUp={this.props.presButtonBackUp}
presGroupBackUp={this.props.presGroupBackUp}
removeDocByRef={this.props.removeDocByRef}
- setPresElementsMappings={this.props.setPresElementsMappings}
+ PresElementsMappings={this.props.PresElementsMappings}
/>
)}
</div>
diff --git a/src/client/views/presentationview/PresentationView.tsx b/src/client/views/presentationview/PresentationView.tsx
index c1f5fac60..5db87a692 100644
--- a/src/client/views/presentationview/PresentationView.tsx
+++ b/src/client/views/presentationview/PresentationView.tsx
@@ -1,6 +1,6 @@
import { observer } from "mobx-react";
import React = require("react");
-import { observable, action, runInAction, reaction } from "mobx";
+import { observable, action, runInAction, reaction, autorun } from "mobx";
import "./PresentationView.scss";
import { DocumentManager } from "../../util/DocumentManager";
import { Utils } from "../../../Utils";
@@ -65,6 +65,7 @@ export class PresentationView extends React.Component<PresViewProps> {
constructor(props: PresViewProps) {
super(props);
PresentationView.Instance = this;
+ // autorun(() => console.log("Updated: ", this.presElementsMappings));
}
//The first lifecycle function that gets called to set up the current presentation.
@@ -327,6 +328,8 @@ export class PresentationView extends React.Component<PresViewProps> {
if (curDocPresId !== undefined) {
if (this.groupMappings.has(curDocPresId)) {
let currentDocGroup = this.groupMappings.get(curDocPresId)!;
+ Array.from(this.presElementsMappings.keys()).map(doc => console.log(doc[Id]));
+ console.log("\n");
currentDocGroup.forEach((doc: Doc, index: number) => {
let selectedButtons: boolean[] = this.presElementsMappings.get(doc)!.selected;
if (selectedButtons[buttonIndex.Navigate]) {
@@ -773,6 +776,7 @@ export class PresentationView extends React.Component<PresViewProps> {
addPressElem = (keyDoc: Doc, elem: PresentationElement) => {
this.presElementsMappings.set(keyDoc, elem);
+ // console.log(keyDoc, " : ", elem, " => ", this.presElementsMappings.size);
}
@@ -805,12 +809,13 @@ export class PresentationView extends React.Component<PresViewProps> {
deleteDocument={this.RemoveDoc}
gotoDocument={this.gotoDocument}
groupMappings={this.groupMappings}
- setPresElementsMappings={this.addPressElem}
+ PresElementsMappings={this.presElementsMappings}
setChildrenDocs={this.setChildrenDocs}
presStatus={this.presStatus}
presButtonBackUp={this.presButtonBackUp}
presGroupBackUp={this.presGroupBackUp}
removeDocByRef={this.removeDocByRef}
+ clearElemMap={() => this.presElementsMappings.clear()}
/>
</div>
);