From bd7005492cd9f5395b73a04636bf2062f2064f0a Mon Sep 17 00:00:00 2001
From: Anthony Geourjon <anthony.geourjon@tetras-libre.fr>
Date: Sun, 4 Feb 2024 21:55:40 +0100
Subject: [PATCH] WIP Saving fake data + recover last data from drawing

---
 src/AnnotationCreation.js      |  4 ++++
 src/AnnotationCreationUtils.js |  1 +
 src/WebAnnotation.js           | 22 ++++++++++++++++------
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/AnnotationCreation.js b/src/AnnotationCreation.js
index 009c035..d228815 100644
--- a/src/AnnotationCreation.js
+++ b/src/AnnotationCreation.js
@@ -95,6 +95,10 @@ function AnnotationCreation(props) {
         annoState.xywh = geomFromAnnoTarget(props.annotation.target);
         [tstart, tend] = timeFromAnnoTarget(props.annotation.target);
       }
+
+      if(props.annotation.drawingState) {
+       setDrawingState(JSON.parse(props.annotation.drawingState));
+      }
     }
 
     // If we don't have tstart setted, we are creating a new annotation.
diff --git a/src/AnnotationCreationUtils.js b/src/AnnotationCreationUtils.js
index 966f7a6..4cf9110 100644
--- a/src/AnnotationCreationUtils.js
+++ b/src/AnnotationCreationUtils.js
@@ -53,6 +53,7 @@ export function isShapesTool(activeTool) {
 export async function getSvg(windowId) {
   const stage = window.Konva.stages.find((s) => s.attrs.id === windowId);
   const svg = await exportStageSVG(stage, false); // TODO clean
+  console.log('SVG:', svg);
   return svg;
 };
 
diff --git a/src/WebAnnotation.js b/src/WebAnnotation.js
index 09984de..2267a98 100644
--- a/src/WebAnnotation.js
+++ b/src/WebAnnotation.js
@@ -10,7 +10,8 @@ export default class WebAnnotation {
     this.body = body;
     this.tags = tags;
     this.svg = svg;
-    this.image = image;
+    //this.image = image;
+    this.image = null;
     this.manifestId = manifestId;
     this.drawingState = drawingStateSerialized;
 
@@ -19,14 +20,16 @@ export default class WebAnnotation {
 
   /** */
   toJson() {
-    return {
+    const result =  {
       body: this.createBody(),
       id: this.id,
       motivation: 'commenting',
       target: this.target(),
       type: 'Annotation',
-      drawingStateSerialized: this.drawingStateSerialized,
+      drawingState: this.drawingState,
     };
+    console.log('WebAnnotation toJson', result);
+    return result;
   }
 
   /** */
@@ -41,13 +44,20 @@ export default class WebAnnotation {
     }
 
     if (this.image) {
-
+      // TODO dumb image { this.image.id}
       const imgBody = {
-        id: this.image.id,
+        id: 'https://tetras-libre.fr/themes/tetras/img/logo.svg',
         type: 'Image',
         format: 'image/svg+xml',
       };
-      bodies.push(imgBody);
+      //bodies.push(imgBody);
+      const testImageBody = {
+        "id": "http://iiif.tetras-libre.fr/data/Hakanai/media/10_HKN-Garges_A2B4243.JPG",
+        "type": "Image",
+        "format": "image/jpg",
+        "value": "<a href=\"http://iiif.tetras-libre.fr/data/Hakanai/media/10_HKN-Garges_A2B4243.JPG\" target=\"_blank\">Dispositif</a>"
+      };
+      bodies.push(testImageBody);
     }
 
     // if (this.tags) {
-- 
GitLab