소스 검색

Store background color in backend (#475)

* Store background color in backend

* Background
Lipis 5 년 전
부모
커밋
a210f442f4
1개의 변경된 파일12개의 추가작업 그리고 7개의 파일을 삭제
  1. 12 7
      src/scene/data.ts

+ 12 - 7
src/scene/data.ts

@@ -175,13 +175,14 @@ export async function loadFromJSON() {
   }
 }
 
-export async function exportToBackend(elements: readonly ExcalidrawElement[]) {
+export async function exportToBackend(
+  elements: readonly ExcalidrawElement[],
+  appState: AppState
+) {
   const response = await fetch(BACKEND_POST, {
     method: "POST",
-    headers: {
-      "Content-Type": "application/json"
-    },
-    body: serializeAsJSON(elements)
+    headers: { "Content-Type": "application/json" },
+    body: serializeAsJSON(elements, appState)
   });
   const json = await response.json();
   if (json.id) {
@@ -189,7 +190,7 @@ export async function exportToBackend(elements: readonly ExcalidrawElement[]) {
     url.searchParams.append("json", json.id);
 
     await navigator.clipboard.writeText(url.toString());
-    window.alert(`Copied shareable link ${url.toString()} to clipboard`);
+    window.alert(`Copied to clipboard: ${url.toString()}`);
   } else {
     window.alert("Couldn't create shareable link");
   }
@@ -269,7 +270,11 @@ export async function exportCanvas(
       window.alert("Couldn't copy to clipboard. Try using Chrome browser.");
     }
   } else if (type === "backend") {
-    exportToBackend(elements);
+    const appState = getDefaultAppState();
+    if (exportBackground) {
+      appState.viewBackgroundColor = viewBackgroundColor;
+    }
+    exportToBackend(elements, appState);
   }
 
   // clean up the DOM