Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

(FIX FOR ERROR TypeError: this.x.toFixed) Saving and Reloading without edit Doubles the length of the updates array #75

@Solvengo

Description

@Solvengo

A problem occurs when the drawing gets saved to Sessionstorage, or in our case to a string variable. After an initial save, when the drawing is loaded it can't be saved again. update.stringify() throws an TypeError "this.x.toFixed()". I noticed that the length of the updates arrays doubles. What causes this? Did you forget to reset the array after an initial update.stringify()? Or does this.canvasWhiteboardService.drawCanvas(updates) add the drawing twice which causes problems?

savetoDB() {
    const updates: Array<CanvasWhiteboardUpdate> = this.canvasWhiteboardComponent.getDrawingHistory();
    console.log(updates.length); // 415 first time, 830 second time without editing

    const stringifiedUpdatesArray: Array<string> = updates.map((update) =>
      update.stringify()
    );
    console.log(stringifiedUpdatesArray.length);
    const stringifiedStorageUpdates: string = JSON.stringify(
      stringifiedUpdatesArray
    );
    // Save the item in storage of choice
    this.formService.currentProject.drawingBase64 = stringifiedStorageUpdates;
  }

  loadFromDB() {
    console.log(this.formService.currentProject.drawingBase64);
    const canvasDrawingsJson: string = this.formService.currentProject
      .drawingBase64;

    if (canvasDrawingsJson != null && canvasDrawingsJson !== '') {
      console.log('null');
      const parsedStorageUpdates: Array<string> = JSON.parse(
        canvasDrawingsJson
      );

      const updates: Array<CanvasWhiteboardUpdate> = parsedStorageUpdates.map(
        (updateJSON) => CanvasWhiteboardUpdate.deserializeJson(updateJSON)
      );

      this.canvasWhiteboardService.drawCanvas(updates);
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions