diff --git a/public/locales/de/translation.json b/public/locales/de/translation.json index 355bd89..56c66cc 100644 --- a/public/locales/de/translation.json +++ b/public/locales/de/translation.json @@ -1,3 +1,4 @@ { - "hello_world": "Hallo Welt" + "hello_world": "Hallo Welt", + "download": "Download" } \ No newline at end of file diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 4ea0b47..850859e 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -1,3 +1,4 @@ { - "hello_world": "Hello World" + "hello_world": "Hello World", + "download": "Download" } \ No newline at end of file diff --git a/src/components/DownloadButton.jsx b/src/components/DownloadButton.jsx new file mode 100644 index 0000000..f18bd65 --- /dev/null +++ b/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 (); +} + +export default DownloadButton; \ No newline at end of file