fix: create document

This commit is contained in:
AykutSarac 2023-08-02 20:56:52 +03:00
parent 1c153e5249
commit 028824cb3e
No known key found for this signature in database
3 changed files with 11 additions and 7 deletions

View File

@ -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);

View File

@ -101,7 +101,7 @@ export const CloudModal: React.FC<ModalProps> = ({ 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" });

View File

@ -12,11 +12,15 @@ type CloudSave = {
};
const saveToCloud = async ({
id,
contents,
format = FileFormat.JSON,
}: CloudSave): Promise<PostgrestSingleResponse<{ id: string }[]>> => {
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<PostgrestSingleResponse<string>> => {
return await supabase.rpc("upsert_document", {
p_content,
p_format,
p_id,
});
};
const getFromCloud = async (doc_id: string): Promise<PostgrestSingleResponse<File[]>> => {