From a92828dde048d95720d717adbea661453d010622 Mon Sep 17 00:00:00 2001 From: ZXY101 Date: Fri, 6 Oct 2023 01:53:18 +0200 Subject: [PATCH] Add profile importing/exporting --- .../Profiles/ManageProfilesModal.svelte | 2 +- .../Settings/Profiles/Profiles.svelte | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/lib/components/Settings/Profiles/ManageProfilesModal.svelte b/src/lib/components/Settings/Profiles/ManageProfilesModal.svelte index d7742ad..5df5e68 100644 --- a/src/lib/components/Settings/Profiles/ManageProfilesModal.svelte +++ b/src/lib/components/Settings/Profiles/ManageProfilesModal.svelte @@ -7,7 +7,7 @@ renameProfile } from '$lib/settings'; import { promptConfirmation, showSnackbar } from '$lib/util'; - import { Listgroup, ListgroupItem, Modal, Input, Popover } from 'flowbite-svelte'; + import { Listgroup, ListgroupItem, Modal, Input } from 'flowbite-svelte'; import { CirclePlusSolid, CopySolid, diff --git a/src/lib/components/Settings/Profiles/Profiles.svelte b/src/lib/components/Settings/Profiles/Profiles.svelte index e3bc248..adda0c3 100644 --- a/src/lib/components/Settings/Profiles/Profiles.svelte +++ b/src/lib/components/Settings/Profiles/Profiles.svelte @@ -2,6 +2,7 @@ import { changeProfile, currentProfile, profiles } from '$lib/settings'; import { AccordionItem, Button, Select } from 'flowbite-svelte'; import ManageProfilesModal from './ManageProfilesModal.svelte'; + import { showSnackbar } from '$lib/util'; export let onClose: () => void; @@ -16,6 +17,37 @@ onClose(); } + function exportProfiles() { + const link = document.createElement('a'); + const json = localStorage.getItem('profiles') || ''; + link.href = URL.createObjectURL(new Blob([json], { type: 'application/json' })); + link.download = 'profiles.json'; + link.click(); + showSnackbar('Profiles exported'); + } + + let files: FileList; + function importProfile() { + const [file] = files; + const reader = new FileReader(); + + reader.onloadend = () => { + const imported = JSON.parse(reader.result?.toString() || ''); + profiles.update((prev) => { + return { + ...prev, + ...imported + }; + }); + onClose(); + showSnackbar('Profiles imported'); + }; + + if (file) { + reader.readAsText(file); + } + } + let manageModalOpen = false; @@ -30,5 +62,13 @@ >Manage profiles +
+
+ + + +