Browse Source

feat: Added data download button

master
Denis Thiessen 6 months ago
parent
commit
803ae60cd4
  1. 3
      public/locales/de/translation.json
  2. 3
      public/locales/en/translation.json
  3. 33
      src/components/DownloadButton.jsx

3
public/locales/de/translation.json

@ -1,3 +1,4 @@
{ {
"hello_world": "Hallo Welt"
"hello_world": "Hallo Welt",
"download": "Download"
} }

3
public/locales/en/translation.json

@ -1,3 +1,4 @@
{ {
"hello_world": "Hello World"
"hello_world": "Hello World",
"download": "Download"
} }

33
src/components/DownloadButton.jsx

@ -0,0 +1,33 @@
import React from "react";
import { getTranslation } from "../core/i18n/I18NHandler";
import { getSensorLog } from "../core/log/SensorLogger";
import { Button } from '@geist-ui/core';
function DownloadButton() {
const downloadFile = ({ data, fileName, fileType }) => {
const blob = new Blob([data], { type: fileType });
const a = document.createElement('a');
a.download = fileName;
a.href = window.URL.createObjectURL(blob);
const clickEvt = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
});
a.dispatchEvent(clickEvt);
a.remove();
}
const exportToJson = e => {
e.preventDefault();
downloadFile({
data: JSON.stringify(getSensorLog()),
fileName: 'sensorData.json',
fileType: 'text/json',
})
}
return (<Button onClick={exportToJson}>{getTranslation("download")}</Button>);
}
export default DownloadButton;
Loading…
Cancel
Save