-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from 2xAA/next
feat(editor-state): adds load and save for editor state (#162)
- Loading branch information
Showing
11 changed files
with
116 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<template> | ||
<button class="button" @click="saveState">Save State</button> | ||
</template> | ||
|
||
<script> | ||
import { compress } from "compress-json"; | ||
import { saveFile } from "../utils/save-file"; | ||
export default { | ||
methods: { | ||
saveState() { | ||
const compressed = compress(this.$store.state); | ||
saveFile("state.ged", JSON.stringify(compressed)); | ||
} | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<template> | ||
<label class="button"> | ||
<input type="file" id="input" accept=".ged" @change="fileAdded" /> | ||
</label> | ||
</template> | ||
|
||
<script> | ||
import { decompress } from "compress-json"; | ||
export default { | ||
methods: { | ||
fileAdded(e) { | ||
const { | ||
files: { 0: file } | ||
} = e.target; | ||
const reader = new FileReader(); | ||
reader.onload = () => { | ||
const newState = decompress(JSON.parse(reader.result)); | ||
this.$store.commit("SET_STATE", newState); | ||
e.target.value = ""; | ||
}; | ||
try { | ||
reader.readAsText(file); | ||
} catch (e) { | ||
console.log("Can't read file", e); | ||
} | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
input { | ||
display: none; | ||
} | ||
label::before { | ||
content: "Load State"; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const downloadURL = function(data, fileName) { | ||
const a = document.createElement("a"); | ||
a.href = data; | ||
a.download = fileName; | ||
document.body.appendChild(a); | ||
a.style = "display: none"; | ||
a.click(); | ||
a.remove(); | ||
}; | ||
|
||
export function saveFile(name, contents = "") { | ||
if (!name) { | ||
throw new Error("Name can't be blank"); | ||
} | ||
|
||
const blob = new Blob([contents], { | ||
type: "application/octet-stream" | ||
}); | ||
|
||
const url = window.URL.createObjectURL(blob); | ||
downloadURL(url, name); | ||
setTimeout(function() { | ||
return window.URL.revokeObjectURL(url); | ||
}, 1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters