Skip to content

Commit

Permalink
Removed the "Save as" button
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioCasCeb committed Oct 13, 2023
1 parent 3fc9287 commit a3e60cf
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 55 deletions.
101 changes: 51 additions & 50 deletions packages/web-new/src/scripts/save-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const thingTypeText = document.querySelector('#thing-type-text')
const shareUrlBtn = document.querySelector("#share-url-btn")
const openEditdorBtn = document.querySelector('#open-editdor-btn')
const downloadBtn = document.querySelector("#download-btn")
const saveAsBtn = document.querySelector("#save-as-btn")
const saveAsWarning = document.querySelector(".save-warning")
// const saveAsBtn = document.querySelector("#save-as-btn")
// const saveAsWarning = document.querySelector(".save-warning")
const saveMenuContainer = document.querySelector(".save-menu__container")
let fileHandle;
openUrlTab.disabled = true
Expand Down Expand Up @@ -161,9 +161,9 @@ downloadBtn.addEventListener("click", () => {
})

/* Save as btn functionality */
saveAsBtn.addEventListener("click", () => {
saveAsFile()
})
// saveAsBtn.addEventListener("click", () => {
// saveAsFile()
// })

/**
* Saves the td as a file in the file system
Expand All @@ -175,56 +175,57 @@ async function saveFileInSystem(content) {
await stream.close()
}

//TODO: Uncomment when https is implemented
/**
* Opens the file system allows the user to input a file
* name and save it as json , jsonld or yaml
* This function only works for chrome, edge and oper as of now (26.05.2023)
*/
async function saveAsFile() {
try {
let fileName = ""
let editorContent = ""
let acceptOpts = {}
let acceptDesc = ""
editorList.forEach(editorInstance => {
if (editorInstance["_domElement"].classList.contains("active")) {
const editorValues = getEditorData(editorInstance)
fileName = `${editorValues[2]["title"]}.${editorValues[0]}`
editorContent = editorInstance.getValue()
acceptOpts = editorValues[0] === "json" ? { "text/plain": [".jsonld", ".json"] } : { "text/plain": [".yaml"] }
acceptDesc = editorValues[0] === "json" ? "json or jsonld files only" : "yaml files only"
}
})


const opts = {
suggestedName: fileName,
types: [
{
description: acceptDesc,
accept: acceptOpts,
},
],
excludeAcceptAllOption: true,
}

fileHandle = await window.showSaveFilePicker(opts)

saveFileInSystem(editorContent)

} catch (err) {
const errTxt = `${err}`
if (errTxt === "AbortError: The user aborted a request.") {
console.error(err)
}
else {
saveAsWarning.classList.add("active")
setTimeout(() => {
saveAsWarning.classList.remove("active")
}, 1500)
}
}
}
// async function saveAsFile() {
// try {
// let fileName = ""
// let editorContent = ""
// let acceptOpts = {}
// let acceptDesc = ""
// editorList.forEach(editorInstance => {
// if (editorInstance["_domElement"].classList.contains("active")) {
// const editorValues = getEditorData(editorInstance)
// fileName = `${editorValues[2]["title"]}.${editorValues[0]}`
// editorContent = editorInstance.getValue()
// acceptOpts = editorValues[0] === "json" ? { "text/plain": [".jsonld", ".json"] } : { "text/plain": [".yaml"] }
// acceptDesc = editorValues[0] === "json" ? "json or jsonld files only" : "yaml files only"
// }
// })


// const opts = {
// suggestedName: fileName,
// types: [
// {
// description: acceptDesc,
// accept: acceptOpts,
// },
// ],
// excludeAcceptAllOption: true,
// }

// fileHandle = await window.showSaveFilePicker(opts)

// saveFileInSystem(editorContent)

// } catch (err) {
// const errTxt = `${err}`
// if (errTxt === "AbortError: The user aborted a request.") {
// console.error(err)
// }
// else {
// saveAsWarning.classList.add("active")
// setTimeout(() => {
// saveAsWarning.classList.remove("active")
// }, 1500)
// }
// }
// }

//TODO IMPORT FROM FILES
/** Experimental file manager fucntion*/
Expand Down
2 changes: 2 additions & 0 deletions packages/web-new/src/styles/_save-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
justify-content: space-between;
gap: 1rem;
margin-bottom: .5rem;
padding-top: 3rem;
border-top: 2px solid var(--clr-primary-500);

& > *{
flex: 1;
Expand Down
2 changes: 2 additions & 0 deletions packages/web-new/src/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2230,6 +2230,8 @@ main .console {
justify-content: space-between;
gap: 1rem;
margin-bottom: 0.5rem;
padding-top: 3rem;
border-top: 2px solid var(--clr-primary-500);
}
.save-menu__container .save-td > * {
flex: 1;
Expand Down
Loading

0 comments on commit a3e60cf

Please sign in to comment.