Skip to content

Commit

Permalink
fix: export settings
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Jan 15, 2024
1 parent e572b3b commit 315508d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
16 changes: 2 additions & 14 deletions src/components/layout/drawer/Actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
<Link to={to} ref={ref} {...itemProps} />
Expand Down
22 changes: 12 additions & 10 deletions src/services/functions/downloadJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 315508d

Please sign in to comment.