Browse Source

Added data preset.

master
Denis Thiessen 10 months ago
parent
commit
cd4aab95ce
  1. 28
      src/components/SingleFileUpload.jsx
  2. 18812
      src/data/clockify_data1.js

28
src/components/SingleFileUpload.jsx

@ -1,6 +1,7 @@
import React, { useState, useEffect } from "react" import React, { useState, useEffect } from "react"
import { useToasts } from '@geist-ui/core';
import { ButtonGroup, Button, Spacer, useToasts } from "@geist-ui/core"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import { clockifyDataSet1 } from "../data/clockify_data1"
export var fileContent = "{}" export var fileContent = "{}"
var uploadFailed = false var uploadFailed = false
@ -10,14 +11,23 @@ function SingleFileUpload({ onFileUploaded }) {
const [fileUploaded, setFileUploaded] = useState(false) const [fileUploaded, setFileUploaded] = useState(false)
const { setToast } = useToasts() const { setToast } = useToasts()
const showSuccessToast = () => setToast({ text: "File successfully uploaded", delay: 2000 });
const showInvalidCSVToast = () => setToast({ text: "Invalid CSV File", delay: 2000 });
const showInvalidFileToast = () => setToast({ text: "Wrong file type", delay: 2000 });
const showSuccessToast = () =>
setToast({ text: "File successfully uploaded", delay: 2000 })
const showInvalidCSVToast = () =>
setToast({ text: "Invalid CSV File", delay: 2000 })
const showInvalidFileToast = () =>
setToast({ text: "Wrong file type", delay: 2000 })
const loadFirstDataSet = () => {
fileContent = clockifyDataSet1
uploadFailed = false
setFileUploaded(true)
}
useEffect(() => { useEffect(() => {
if (fileUploaded) { if (fileUploaded) {
onFileUploaded() onFileUploaded()
showSuccessToast();
showSuccessToast()
} }
if (uploadFailed && !fileUploaded) { if (uploadFailed && !fileUploaded) {
onFileUploaded() onFileUploaded()
@ -27,7 +37,7 @@ function SingleFileUpload({ onFileUploaded }) {
// Reads file. // Reads file.
var readCallback = function (csvRawData) { var readCallback = function (csvRawData) {
if (!checkCSVValidity(csvRawData)) { if (!checkCSVValidity(csvRawData)) {
showInvalidCSVToast();
showInvalidCSVToast()
uploadFailed = true uploadFailed = true
setFileUploaded(false) setFileUploaded(false)
fileContent = {} fileContent = {}
@ -56,7 +66,7 @@ function SingleFileUpload({ onFileUploaded }) {
reader.onload = function (evt) { reader.onload = function (evt) {
var uploadedFile = document.getElementById("fileInput").files[0] var uploadedFile = document.getElementById("fileInput").files[0]
if (uploadedFile.type != "application/vnd.ms-excel") { if (uploadedFile.type != "application/vnd.ms-excel") {
showInvalidFileToast();
showInvalidFileToast()
fileContent = "{}" fileContent = "{}"
return return
} }
@ -70,6 +80,10 @@ function SingleFileUpload({ onFileUploaded }) {
<h2>Upload file</h2> <h2>Upload file</h2>
<input id="fileInput" type="file" accept=".csv" onChange={handleChange} /> <input id="fileInput" type="file" accept=".csv" onChange={handleChange} />
</form> </form>
<Spacer h={2} />
<ButtonGroup>
<Button onClick={loadFirstDataSet}>Data Set 1 (26/09/23 - 30/01/24)</Button>
</ButtonGroup>
</div> </div>
) )
} }

18812
src/data/clockify_data1.js
File diff suppressed because it is too large
View File

Loading…
Cancel
Save