Commit f177d81e authored by Rob Stupay's avatar Rob Stupay

Fix file-explorer for Gist rename deletes

parent 737402e9
...@@ -411,14 +411,32 @@ fileExplorer.prototype.toGist = function (id) { ...@@ -411,14 +411,32 @@ fileExplorer.prototype.toGist = function (id) {
token: tokenAccess token: tokenAccess
}) })
if (id) { if (id) {
const fileList = Object.keys(this.files.origGistFiles)
const updatedFileList = Object.keys(packaged)
// Telling the GIST API to remove files
const allItems = fileList
.filter(fileName => updatedFileList.indexOf(fileName) === -1)
.reduce((acc, deleteFileName) => ({
...acc,
[deleteFileName]: null
}), this.files.origGistFiles)
// adding new files
updatedFileList.forEach(file => allItems[file] = packaged[file])
tooltip('Saving gist (' + id + ') ...') tooltip('Saving gist (' + id + ') ...')
gists.edit({ gists.edit({
description: description, description: description,
public: true, public: true,
files: packaged, files: allItems,
id: id id: id
}, (error, result) => { }, (error, result) => {
proccedResult(error, result) proccedResult(error, result)
if (!error) {
for (const key in allItems) {
if (allItems[key] === null) delete allItems[key]
}
this.files.origGistFiles = allItems
}
}) })
} else { } else {
tooltip('Creating a new gist ...') tooltip('Creating a new gist ...')
...@@ -491,40 +509,10 @@ fileExplorer.prototype.copyFiles = function () { ...@@ -491,40 +509,10 @@ fileExplorer.prototype.copyFiles = function () {
// ------------------ gist publish -------------- // ------------------ gist publish --------------
fileExplorer.prototype.updateGist = function () { fileExplorer.prototype.updateGist = function () {
let self = this const gistId = this.files.id
var gistId = this.files.id
var fileList = Object.keys(this.files.files)
// fileList is an array of files in the github gist - not the updated one
var updatedFileList
// loop through fileList and check if each element is in updatedFileList
// if one is not there in updated file list add it and make its content null
self.packageFiles(self.files, (error, packaged) => {
if (error) {
console.log(error)
} else {
updatedFileList = Object.keys(packaged)
}
})
if (!gistId) { if (!gistId) {
tooltip('no gist content is currently loaded.') tooltip('no gist content is currently loaded.')
} else { } else {
// check that the file list is still the same
// console.log('RS ' , this.files)
// make an array with just the names of the files
// self.packageFiles(self.files, (error, packaged) => {
// if (error) {
// console.log(error)
// } else {
// console.log('file list is: ', packaged)
// }
// })
this.toGist(gistId) this.toGist(gistId)
} }
} }
......
...@@ -56,7 +56,7 @@ function GistHandler (_window) { ...@@ -56,7 +56,7 @@ function GistHandler (_window) {
fileManager.setBatchFiles(data.files, 'gist', (errorLoadingFile) => { fileManager.setBatchFiles(data.files, 'gist', (errorLoadingFile) => {
if (!errorLoadingFile) { if (!errorLoadingFile) {
gistProvider.id = gistId gistProvider.id = gistId
gistProvider.files = data.files gistProvider.origGistFiles = data.files
} }
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment