Skip to content

Commit 169a7b6

Browse files
committed
Implement "Export Data" button
* Implement handleExportDataClick in Settings page * Fix consistency with margin above BrandHeader * Implement getJottingsRaw for not splitting into object of notes and tasks
1 parent a96940d commit 169a7b6

5 files changed

Lines changed: 65 additions & 10 deletions

File tree

components/Layout/layout.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.container {
22
display: grid;
33
min-height: 100vh;
4-
padding: 0 0.5rem;
4+
padding: 10px 0.5rem 0 0.5rem;
55
justify-content: stretch;
66
align-items: flex-start;
77
}

libs/Datastore/requests.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ export async function submitLogin(email, password) {
1313
.makeRequest();
1414
}
1515

16+
export async function getJottingsRaw() {
17+
const response = await BorumJotRequest.initialize("jottings")
18+
.authorize()
19+
.makeRequest();
20+
21+
return response ?? response.data;
22+
}
23+
1624
/**
1725
* Makes GET request
1826
*/
1927
export async function getJottings() {
2028
if (window) {
21-
let { data } = await BorumJotRequest.initialize("jottings")
22-
.authorize()
23-
.makeRequest();
29+
let { data } = await getJottingsRaw();
2430

2531
const tasks = data.filter((item) => item.source == "task");
2632
tasks.forEach((item) => (item.body = unescapeSlashes(item.body)));

pages/Home/home.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
display: grid;
33
grid-template-rows: auto 100px repeat(2, 200px) 30px;
44
grid-template-columns: 200px 3fr 200px repeat(3, 1fr) 1fr 2fr;
5-
margin-top: 10px;
65
}
76

87
.ownNoteList {

pages/Settings/index.js

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,59 @@ import settings from "./settings.module.css";
22
import Layout from "../../components/Layout/layout";
33
import Head from "next/head";
44
import BrandHeader from "../../components/BrandHeader/brandHeader";
5+
import {
6+
getJottingsRaw,
7+
getSharedJottings,
8+
} from "../../libs/Datastore/requests";
9+
import Browser from "../../libs/browser";
510

611
export 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>

pages/Settings/settings.module.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
.main {
2-
display: grid;
32

3+
}
4+
5+
.mainSection {
6+
display: flex;
7+
flex-direction: column;
8+
align-items: center;
9+
}
10+
11+
.exportData {
12+
font-size: 2em;
13+
width: 30%;
14+
height: 100px;
415
}

0 commit comments

Comments
 (0)