From 2a584d4827c9ece87f3bd618201f356237ba7fc7 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 1 May 2023 12:49:06 -0400
Subject: fixed RecordingBox/View serialization to save docid, not Doc.

---
 .../views/nodes/RecordingBox/RecordingBox.tsx      | 106 +++++++++++----------
 1 file changed, 56 insertions(+), 50 deletions(-)

(limited to 'src/client/views/nodes/RecordingBox/RecordingBox.tsx')

diff --git a/src/client/views/nodes/RecordingBox/RecordingBox.tsx b/src/client/views/nodes/RecordingBox/RecordingBox.tsx
index 0ff7c4292..f406ffbea 100644
--- a/src/client/views/nodes/RecordingBox/RecordingBox.tsx
+++ b/src/client/views/nodes/RecordingBox/RecordingBox.tsx
@@ -1,58 +1,64 @@
-import { action, observable } from "mobx";
-import { observer } from "mobx-react";
-import * as React from "react";
-import { VideoField } from "../../../../fields/URLField";
-import { Upload } from "../../../../server/SharedMediaTypes";
-import { ViewBoxBaseComponent } from "../../DocComponent";
-import { FieldView } from "../FieldView";
-import { VideoBox } from "../VideoBox";
+import { action, observable } from 'mobx';
+import { observer } from 'mobx-react';
+import * as React from 'react';
+import { VideoField } from '../../../../fields/URLField';
+import { Upload } from '../../../../server/SharedMediaTypes';
+import { ViewBoxBaseComponent } from '../../DocComponent';
+import { FieldView } from '../FieldView';
+import { VideoBox } from '../VideoBox';
 import { RecordingView } from './RecordingView';
-import { DocumentType } from "../../../documents/DocumentTypes";
-import { Presentation } from "../../../util/TrackMovements";
-import { Doc } from "../../../../fields/Doc";
-import { Id } from "../../../../fields/FieldSymbols";
-
+import { DocumentType } from '../../../documents/DocumentTypes';
+import { Presentation } from '../../../util/TrackMovements';
+import { Doc } from '../../../../fields/Doc';
+import { Id } from '../../../../fields/FieldSymbols';
 
 @observer
 export class RecordingBox extends ViewBoxBaseComponent() {
+    public static LayoutString(fieldKey: string) {
+        return FieldView.LayoutString(RecordingBox, fieldKey);
+    }
 
-      public static LayoutString(fieldKey: string) { return FieldView.LayoutString(RecordingBox, fieldKey); }
-
-      private _ref: React.RefObject<HTMLDivElement> = React.createRef();
+    private _ref: React.RefObject<HTMLDivElement> = React.createRef();
 
-      constructor(props: any) {
+    constructor(props: any) {
         super(props);
-      }
-
-      componentDidMount() {
-            Doc.SetNativeWidth(this.dataDoc, 1280);
-            Doc.SetNativeHeight(this.dataDoc, 720);
-      }
-
-      @observable result: Upload.AccessPathInfo | undefined = undefined
-      @observable videoDuration: number | undefined = undefined
-
-      @action
-      setVideoDuration = (duration: number) => {
-            this.videoDuration = duration
-      }
-
-      @action
-      setResult = (info: Upload.AccessPathInfo, presentation?: Presentation) => {
-            this.result = info
-            this.dataDoc.type = DocumentType.VID;
-            this.dataDoc[this.fieldKey + "-duration"] = this.videoDuration;
-
-            this.dataDoc.layout = VideoBox.LayoutString(this.fieldKey);
-            this.dataDoc[this.props.fieldKey] = new VideoField(this.result.accessPaths.client);
-            this.dataDoc[this.fieldKey + "-recorded"] = true;
-            // stringify the presentation and store it
-            presentation?.movements && (this.dataDoc[this.fieldKey + "-presentation"] = JSON.stringify(presentation));
-      }
-
-      render() {
-            return <div className="recordingBox" ref={this._ref}>
-                  {!this.result && <RecordingView setResult={this.setResult} setDuration={this.setVideoDuration} id={this.rootDoc.proto?.[Id] || ''} />}
-            </div>;
-      }
+    }
+
+    componentDidMount() {
+        Doc.SetNativeWidth(this.dataDoc, 1280);
+        Doc.SetNativeHeight(this.dataDoc, 720);
+    }
+
+    @observable result: Upload.AccessPathInfo | undefined = undefined;
+    @observable videoDuration: number | undefined = undefined;
+
+    @action
+    setVideoDuration = (duration: number) => {
+        this.videoDuration = duration;
+    };
+
+    @action
+    setResult = (info: Upload.AccessPathInfo, presentation?: Presentation) => {
+        this.result = info;
+        this.dataDoc.type = DocumentType.VID;
+        this.dataDoc[this.fieldKey + '-duration'] = this.videoDuration;
+
+        this.dataDoc.layout = VideoBox.LayoutString(this.fieldKey);
+        this.dataDoc[this.props.fieldKey] = new VideoField(this.result.accessPaths.client);
+        this.dataDoc[this.fieldKey + '-recorded'] = true;
+        // stringify the presentation and store it
+        if (presentation?.movements) {
+            const presCopy = { ...presentation };
+            presCopy.movements = presentation.movements.map(movement => ({ ...movement, doc: movement.doc[Id] })) as any;
+            this.dataDoc[this.fieldKey + '-presentation'] = JSON.stringify(presCopy);
+        }
+    };
+
+    render() {
+        return (
+            <div className="recordingBox" ref={this._ref}>
+                {!this.result && <RecordingView setResult={this.setResult} setDuration={this.setVideoDuration} id={this.rootDoc.proto?.[Id] || ''} />}
+            </div>
+        );
+    }
 }
-- 
cgit v1.2.3-70-g09d2

