-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2.9.0: Export, import and delete saved routes
- Loading branch information
1 parent
07e631c
commit 4193f5d
Showing
11 changed files
with
139 additions
and
9 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
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,77 @@ | ||
<script lang="ts"> | ||
import Sidebar from "../components/Sidebar.svelte"; | ||
function exportFile(content: string, filename?: string) { | ||
var textToSaveAsBlob = new Blob([content], { type: "application/json" }); | ||
var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob); | ||
var downloadLink = document.createElement("a"); | ||
downloadLink.download = filename ? filename : "export.json"; | ||
downloadLink.href = textToSaveAsURL; | ||
downloadLink.onclick = function () { | ||
downloadLink.remove(); | ||
}; | ||
downloadLink.style.display = "none"; | ||
document.body.appendChild(downloadLink); | ||
downloadLink.click(); | ||
} | ||
async function exportSavedPlaylists() { | ||
const playlists = await window.getPlaylists(); | ||
const playlistsExports: PlaylistExport[] = playlists.map( | ||
({ title, videos, timestamp }) => ({ | ||
title, | ||
videos, | ||
timestamp, | ||
}) | ||
); | ||
exportFile(JSON.stringify(playlistsExports), "saved-playlists.json"); | ||
} | ||
async function removeSavedPlaylists() { | ||
if (confirm("All the saved playlists are about to be deleted")) { | ||
await window.removeSavedPlaylists(); | ||
alert("All saved playlists were successfully removed"); | ||
} | ||
} | ||
async function importSavedPlaylists() { | ||
const fileInput = document.getElementById( | ||
"ImportSavedPlaylists" | ||
) as HTMLInputElement; | ||
fileInput.onchange = () => { | ||
let fr = new FileReader(); | ||
fr.onload = async () => { | ||
try { | ||
let playlistsExport: PlaylistExport[] = JSON.parse( | ||
fr.result as string | ||
); | ||
await window.importPlaylists(playlistsExport); | ||
alert("The playlists were successfully imported"); | ||
} catch (e) { | ||
console.log(e); | ||
alert("The file is incorrectly formatted"); | ||
} | ||
fileInput.value = null; | ||
}; | ||
const file = fileInput.files[0]; | ||
fr.readAsText(file); | ||
}; | ||
fileInput.click(); | ||
} | ||
</script> | ||
|
||
<Sidebar /> | ||
|
||
<main style="padding: 5rem;"> | ||
<button on:click={exportSavedPlaylists}>Export saved playlists</button> | ||
<button on:click={importSavedPlaylists} style="margin-top: 1rem;" | ||
>Import saved playlists</button | ||
> | ||
<button on:click={removeSavedPlaylists} style="margin-top: 1rem;" | ||
>Delete all saved playlists</button | ||
> | ||
</main> | ||
|
||
<input id="ImportSavedPlaylists" style="visibility: hidden;" type="file" /> | ||
|
||
<style> | ||
</style> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.