diff --git a/src/containers/Editor/BottomBar.tsx b/src/containers/Editor/BottomBar.tsx index 1666a02..ac3cb7d 100644 --- a/src/containers/Editor/BottomBar.tsx +++ b/src/containers/Editor/BottomBar.tsx @@ -125,7 +125,7 @@ export const BottomBar = () => { }); if (error) throw error; - if (data[0].id) replace({ query: { json: data[0].id } }); + if (data) replace({ query: { json: data } }); toast.success("Document saved to cloud", { id: "fileSave" }); setHasChanges(false); diff --git a/src/containers/Modals/CloudModal/index.tsx b/src/containers/Modals/CloudModal/index.tsx index e00eb0a..953cbab 100644 --- a/src/containers/Modals/CloudModal/index.tsx +++ b/src/containers/Modals/CloudModal/index.tsx @@ -101,7 +101,7 @@ export const CloudModal: React.FC = ({ opened, onClose }) => { toast.success("Document saved to cloud", { id: "fileSave" }); setHasChanges(false); - replace({ query: { json: data[0].id } }); + replace({ query: { json: data } }); onClose(); } catch (error: any) { toast.error("Failed to save document!", { id: "fileSave" }); diff --git a/src/services/json.ts b/src/services/json.ts index 4970189..f8c9a4a 100644 --- a/src/services/json.ts +++ b/src/services/json.ts @@ -12,11 +12,15 @@ type CloudSave = { }; const saveToCloud = async ({ - id, - contents, - format = FileFormat.JSON, -}: CloudSave): Promise> => { - return await supabase.from("document").upsert({ id, content: contents, format }).select("id"); + id: p_id = "", + contents: p_content, + format: p_format = FileFormat.JSON, +}: CloudSave): Promise> => { + return await supabase.rpc("upsert_document", { + p_content, + p_format, + p_id, + }); }; const getFromCloud = async (doc_id: string): Promise> => {