diff options
author | madelinegr <mgriswold99@gmail.com> | 2019-06-07 12:23:34 -0400 |
---|---|---|
committer | madelinegr <mgriswold99@gmail.com> | 2019-06-07 12:23:34 -0400 |
commit | 8699b8bb3a3b93e2ec5eff7ca239bccbdccab8ae (patch) | |
tree | af08a0e8c1075cca46eb9d663d71c71db0126566 /src | |
parent | 3473a78055d657829efb8818b643a5348c15fffc (diff) |
Next and Prev adjusted to groups
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/presentationview/PresentationView.tsx | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/src/client/views/presentationview/PresentationView.tsx b/src/client/views/presentationview/PresentationView.tsx index 6089665fe..bede2dd66 100644 --- a/src/client/views/presentationview/PresentationView.tsx +++ b/src/client/views/presentationview/PresentationView.tsx @@ -130,16 +130,62 @@ export class PresentationView extends React.Component<PresViewProps> { @observable collapsed: boolean = false; closePresentation = action(() => this.props.Document.width = 0); - next = () => { + next = async () => { const current = NumCast(this.props.Document.selectedDoc); // let currentPresId = StrCast(current.presentId); + let docAtCurrent = await this.getDocAtIndex(current); + if (docAtCurrent === undefined) { + return; + } + let curPresId = StrCast(docAtCurrent.presentId); + let nextSelected = current + 1; + + if (this.groupMappings.has(curPresId)) { + let currentsArray = this.groupMappings.get(StrCast(docAtCurrent.presentId))!; + console.log("It reaches here"); + console.log("CurArray Len: ", currentsArray.length) + //nextSelected = current + currentsArray.length - current - 1; + nextSelected = current + currentsArray.length - currentsArray.indexOf(docAtCurrent) - 1; + if (nextSelected === current) nextSelected = current + 1; + } + // this.groupMappings.get(current.presentId); - this.gotoDocument(current + 1); + this.gotoDocument(nextSelected); } - back = () => { + back = async () => { const current = NumCast(this.props.Document.selectedDoc); - this.gotoDocument(current - 1); + let docAtCurrent = await this.getDocAtIndex(current); + if (docAtCurrent === undefined) { + return; + } + let curPresId = StrCast(docAtCurrent.presentId); + let prevSelected = current - 1; + + if (this.groupMappings.has(curPresId)) { + let currentsArray = this.groupMappings.get(StrCast(docAtCurrent.presentId))!; + prevSelected = current - currentsArray.length + (currentsArray.length - currentsArray.indexOf(docAtCurrent)); + if (prevSelected === current) prevSelected = current - 1; + + + } + + + this.gotoDocument(prevSelected); + } + + getDocAtIndex = async (index: number) => { + const list = FieldValue(Cast(this.props.Document.data, listSpec(Doc))); + if (!list) { + return undefined; + } + if (index < 0 || index >= list.length) { + return undefined; + } + + this.props.Document.selectedDoc = index; + const doc = await list[index]; + return doc; } @action |