diff --git a/gui/src/app/gists/saveAsGitHubGist.ts b/gui/src/app/gists/saveAsGitHubGist.ts index 46d2ca1c..525db5fb 100644 --- a/gui/src/app/gists/saveAsGitHubGist.ts +++ b/gui/src/app/gists/saveAsGitHubGist.ts @@ -67,7 +67,6 @@ export const updateGitHubGist = async ( files[path] = { content }; } } - console.log("--------------- files", files); await octokit.request(`PATCH /gists/${gistId}`, { gist_id: gistId, files, @@ -77,4 +76,24 @@ export const updateGitHubGist = async ( }); }; +export const createPatchForUpdatingGist = ( + existingFiles: { [key: string]: string }, + newFiles: { [key: string]: string }, +) => { + const patch: { [key: string]: string | null } = {}; + for (const fname in newFiles) { + const newContent = newFiles[fname]; + if (existingFiles[fname] === newContent) continue; + if (!newContent.trim()) continue; + patch[fname] = newContent; + } + // handle deleted files + for (const fname in existingFiles) { + if (!newFiles[fname] || !newFiles[fname].trim()) { + patch[fname] = null; + } + } + return patch; +}; + export default saveAsGitHubGist; diff --git a/gui/src/app/pages/HomePage/SaveProjectWindow.tsx b/gui/src/app/pages/HomePage/SaveProjectWindow.tsx index 515a1483..39f61cc5 100644 --- a/gui/src/app/pages/HomePage/SaveProjectWindow.tsx +++ b/gui/src/app/pages/HomePage/SaveProjectWindow.tsx @@ -4,6 +4,7 @@ import { serializeAsZip } from "@SpCore/ProjectSerialization"; import { FileRegistry, mapModelToFileManifest } from "@SpCore/FileMapping"; import { ProjectContext } from "@SpCore/ProjectContextProvider"; import saveAsGitHubGist, { + createPatchForUpdatingGist, updateGitHubGist, } from "@SpCore/gists/saveAsGitHubGist"; import { triggerDownload } from "@SpUtil/triggerDownload"; @@ -309,26 +310,6 @@ const SpecifyGistUrlToUpdateComponent: FunctionComponent< ); }; -const createPatchForUpdatingGist = ( - existingFiles: { [key: string]: string }, - newFiles: { [key: string]: string }, -) => { - const patch: { [key: string]: string | null } = {}; - for (const fname in newFiles) { - const newContent = newFiles[fname]; - if (existingFiles[fname] === newContent) continue; - if (!newContent.trim()) continue; - patch[fname] = newContent; - } - // handle deleted files - for (const fname in existingFiles) { - if (!newFiles[fname] || !newFiles[fname].trim()) { - patch[fname] = null; - } - } - return patch; -}; - const makeSPShareableLinkFromGistUrl = (gistUrl: string) => { const protocol = window.location.protocol; const host = window.location.host;