From 315508d841d2289c5096581c8d5afe0582516ff2 Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Mon, 15 Jan 2024 17:49:51 -0500 Subject: [PATCH] fix: export settings --- src/components/layout/drawer/Actions.jsx | 16 ++-------------- src/services/functions/downloadJson.js | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/components/layout/drawer/Actions.jsx b/src/components/layout/drawer/Actions.jsx index babc6f6d4..f35eca7fc 100644 --- a/src/components/layout/drawer/Actions.jsx +++ b/src/components/layout/drawer/Actions.jsx @@ -36,20 +36,8 @@ const importSettings = (e) => { setTimeout(() => window.location.reload(), 1500) } -const exportSettings = () => { - const json = localStorage.getItem('local-state') - downloadJson(json, 'settings.json') - const el = document.createElement('a') - el.setAttribute( - 'href', - `data:application/json;chartset=utf-8,${encodeURIComponent(json)}`, - ) - el.setAttribute('download', 'settings.json') - el.style.display = 'none' - document.body.appendChild(el) - el.click() - document.body.removeChild(el) -} +const exportSettings = () => + downloadJson(localStorage.getItem('local-state'), 'settings.json') const renderLink = React.forwardRef(({ to, ...itemProps }, ref) => ( diff --git a/src/services/functions/downloadJson.js b/src/services/functions/downloadJson.js index 26e3f7d71..9cbb135e6 100644 --- a/src/services/functions/downloadJson.js +++ b/src/services/functions/downloadJson.js @@ -5,14 +5,16 @@ * @param {`${string}.json`} fileName */ export function downloadJson(json, fileName) { - const el = document.createElement('a') - el.setAttribute( - 'href', - `data:application/json;chartset=utf-8,${encodeURIComponent(json)}`, - ) - el.setAttribute('download', fileName) - el.style.display = 'none' - document.body.appendChild(el) - el.click() - document.body.removeChild(el) + if (json) { + const el = document.createElement('a') + el.setAttribute( + 'href', + `data:application/json;charset=utf-8,${encodeURIComponent(json)}`, + ) + el.setAttribute('download', fileName) + el.style.display = 'none' + document.body.appendChild(el) + el.click() + document.body.removeChild(el) + } }