@@ -2,20 +2,59 @@ import settings from "./settings.module.css";
22import Layout from "../../components/Layout/layout" ;
33import Head from "next/head" ;
44import BrandHeader from "../../components/BrandHeader/brandHeader" ;
5+ import {
6+ getJottingsRaw ,
7+ getSharedJottings ,
8+ } from "../../libs/Datastore/requests" ;
9+ import Browser from "../../libs/browser" ;
510
611export default function Settings ( props ) {
12+ /**
13+ * Loops through all data and then puts it all in one array
14+ * @param {Event } e
15+ */
16+ const handleExportDataClick = ( e ) => {
17+ Promise . all ( [ getJottingsRaw ( ) , getSharedJottings ( ) ] ) . then ( ( values ) => {
18+ console . log ( values ) ;
19+ let downloadData = [ ] . concat ( values [ 0 ] . data , values [ 1 ] . data ) ;
20+
21+ const jsonData = JSON . stringify ( downloadData ) ;
22+ const blobData = new Blob ( [ jsonData ] , {
23+ type : "text/plain;charset=utf-8" ,
24+ } ) ;
25+
26+ const FILE_NAME = "userjottings.txt" ;
27+ if ( new Browser ( window ) . isIE ) {
28+ window . navigator . msSaveBlob ( blobData , FILE_NAME ) ;
29+ } else {
30+ const url = window . URL || window . webkitURL ;
31+ const link = url . createObjectURL ( blobData ) ;
32+ const a = document . createElement ( "a" ) ;
33+ a . download = FILE_NAME ;
34+ a . href = link ;
35+ document . body . appendChild ( a ) ;
36+ a . click ( ) ;
37+ document . body . removeChild ( a ) ;
38+ }
39+ } ) ;
40+ } ;
41+
742 return (
843 < Layout >
944 < Head >
1045 < title > Settings - Borum Jot</ title >
1146 </ Head >
12-
47+
1348 < main className = { settings . main } >
1449 < BrandHeader />
50+ < section className = { settings . mainSection } >
51+ < button
52+ className = { settings . exportData }
53+ onClick = { handleExportDataClick }
54+ >
55+ Export Data
56+ </ button >
1557
16- < section >
17- < button > Export Data</ button >
18-
1958 { /* <button>Change Color Theme</button> */ }
2059
2160 < p >
0 commit comments