From edf530d1524cc1896ceeb0289f946ee31b16a938 Mon Sep 17 00:00:00 2001 From: Mohammad Amoush Date: Fri, 5 Jul 2019 18:52:31 -0400 Subject: Some factorization and group building in drop fixed --- .../views/presentationview/PresentationElement.tsx | 61 +++++++++++++++++----- .../views/presentationview/PresentationList.tsx | 4 +- .../views/presentationview/PresentationView.tsx | 7 ++- 3 files changed, 55 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/client/views/presentationview/PresentationElement.tsx b/src/client/views/presentationview/PresentationElement.tsx index 656ec62a0..fcddb2ad4 100644 --- a/src/client/views/presentationview/PresentationElement.tsx +++ b/src/client/views/presentationview/PresentationElement.tsx @@ -442,6 +442,8 @@ export default class PresentationElement extends React.Component Doc.AddDocToList(this.props.mainDocument, "data", d, this.props.document, before) || added, false) @@ -454,17 +456,48 @@ export default class PresentationElement extends React.Component { + updateGroupsOnDrop = async (droppedDoc: Doc) => { let p = this.props; - let curDocGuid = StrCast(p.document.presentId, null); - if (curDocGuid) { - if (p.groupMappings.has(curDocGuid)) { - let groupArray = this.props.groupMappings.get(curDocGuid)!; - groupArray.splice(groupArray.indexOf(p.document), 1); + let droppedDocSelectedButtons: boolean[] = await this.getSelectedButtonsOfDoc(droppedDoc); + if (droppedDocSelectedButtons[buttonIndex.Group]) { + let curDocGuid = StrCast(droppedDoc.presentId, null); + if (curDocGuid) { + if (p.groupMappings.has(curDocGuid)) { + let groupArray = this.props.groupMappings.get(curDocGuid)!; + groupArray.splice(groupArray.indexOf(droppedDoc), 1); + } + } + + 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); } + } + } + + getSelectedButtonsOfDoc = async (paramDoc: Doc) => { + let p = this.props; + + let castedList = Cast(this.props.presButtonBackUp.selectedButtonDocs, listSpec(Doc)); + let foundSelectedButtons: boolean[] = new Array(6); + //if this is the first time this doc mounts, push a doc for it to store + await castedList!.forEach(async (doc) => { + let curDoc = await doc; + let curDocId = StrCast(curDoc.docId); + if (curDocId === paramDoc[Id]) { + foundSelectedButtons = Cast(curDoc.selectedButtons, listSpec("boolean"), null); + return; + } + }); + return foundSelectedButtons; - this.onGroupClick(p.document, p.index, true); } onPointerEnter = (e: React.PointerEvent): void => { @@ -551,14 +584,14 @@ export default class PresentationElement extends React.Component {`${p.index + 1}. ${title}`} - +

- - - - - - + + + + +