From 822f7a30f56d4b8ce2f96a495e1f3356eb9ee155 Mon Sep 17 00:00:00 2001 From: Valtteri Karesto Date: Tue, 3 May 2022 16:33:17 +0300 Subject: [PATCH] "Save" files before syncing to github --- state/actions/saveFile.ts | 10 ++++++++++ state/actions/syncToGist.ts | 2 ++ 2 files changed, 12 insertions(+) diff --git a/state/actions/saveFile.ts b/state/actions/saveFile.ts index 1b5bc70..ac79d9c 100644 --- a/state/actions/saveFile.ts +++ b/state/actions/saveFile.ts @@ -15,3 +15,13 @@ export const saveFile = (showToast: boolean = true) => { toast.success("Saved successfully", { position: "bottom-center" }); } }; + +export const saveAllFiles = () => { + const editorModels = state.editorCtx?.getModels(); + state.files.forEach(file => { + const currentModel = editorModels?.find(model => model.uri.path.endsWith('/' + file.name)) + if (currentModel) { + file.content = currentModel?.getValue() || ''; + } + }) +} diff --git a/state/actions/syncToGist.ts b/state/actions/syncToGist.ts index d70362e..696526b 100644 --- a/state/actions/syncToGist.ts +++ b/state/actions/syncToGist.ts @@ -4,6 +4,7 @@ import { Octokit } from "@octokit/core"; import Router from "next/router"; import state from '../index'; +import { saveAllFiles } from "./saveFile"; const octokit = new Octokit(); @@ -12,6 +13,7 @@ export const syncToGist = async ( session?: Session | null, createNewGist?: boolean ) => { + saveAllFiles(); let files: Record = {}; state.gistLoading = true;