From ad4b9b7cd077f514660d8c01d4d9f5e07788f1a0 Mon Sep 17 00:00:00 2001 From: Francisco Pessano Date: Tue, 5 Oct 2021 21:50:59 -0300 Subject: [PATCH] Mod. git ignore --- .gitignore | 2 +- src/components/Clockify/clockify.js | 20 +++++++ .../Clockify/getAndFormatCurrentTime.js | 58 +++++++++++++++++++ .../Clockify/uploadToClockifyTimer.js | 38 ++++++++++++ .../MainPomodoroTimer.jsx | 2 +- 5 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 src/components/Clockify/clockify.js create mode 100644 src/components/Clockify/getAndFormatCurrentTime.js create mode 100644 src/components/Clockify/uploadToClockifyTimer.js diff --git a/.gitignore b/.gitignore index 05b7a7b..5fb982a 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,4 @@ yarn-error.log* # firebase -src/components/Firebase +#/src/components/Firebase diff --git a/src/components/Clockify/clockify.js b/src/components/Clockify/clockify.js new file mode 100644 index 0000000..e1b273f --- /dev/null +++ b/src/components/Clockify/clockify.js @@ -0,0 +1,20 @@ +const makeRequest = async (apiKey) => { + try { + const request = { + method: "GET", + headers: { + 'X-Api-Key': apiKey.trim(), + "content-type": "application/json" + } + } + const response = await fetch(`https://api.clockify.me/api/v1/workspaces/`, request) + const data = await response.json() + + return await data + + } catch (error) { + console.log(error) + } +} + +export {makeRequest} \ No newline at end of file diff --git a/src/components/Clockify/getAndFormatCurrentTime.js b/src/components/Clockify/getAndFormatCurrentTime.js new file mode 100644 index 0000000..628f7df --- /dev/null +++ b/src/components/Clockify/getAndFormatCurrentTime.js @@ -0,0 +1,58 @@ +const getAndFormatCurrentTime = (KonamiCodeON) => { + const data = new Date() + + const date = { + year: data.getFullYear(), + month: data.getMonth() + 1, + day: data.getDate() + } + + const hour = { + hours: data.getHours(), + minutes: data.getMinutes(), + seconds: data.getSeconds() + } + + console.log(KonamiCodeON) + + if (KonamiCodeON) { + hour.hours = hour.hours + 3 + + console.log(hour.hours) + console.log('KONAMI ON') + } + + if (hour.hours === 24) { + + date.day = date.day + 1 + hour.hours = 0 + } + + if (hour.hours > 24) { + hour.hours = hour.hours - 24 + + date.day = date.day + 1 + } + + const formatData = (data) => { + + Object.keys(data).forEach(key => { + if (data[key] < 10) { + data[key] = `0${data[key]}` + } + }); + + //Credits to https://stackoverflow.com/a/62010113 + } + + + formatData(date) + formatData(hour) + + const structuredData = `${date.year}-${date.month}-${date.day}T${hour.hours}:${hour.minutes}:${hour.seconds}Z` + + console.log(structuredData) + return structuredData +} + +export default getAndFormatCurrentTime \ No newline at end of file diff --git a/src/components/Clockify/uploadToClockifyTimer.js b/src/components/Clockify/uploadToClockifyTimer.js new file mode 100644 index 0000000..3636a57 --- /dev/null +++ b/src/components/Clockify/uploadToClockifyTimer.js @@ -0,0 +1,38 @@ +const uploadToClockifyTimer = async (workspaceID, projectID, start, end, apiKey, taskName) => { + + if (!workspaceID && !projectID) { + return + } + + try { + const url = `https://api.clockify.me/api/v1/workspaces/${workspaceID}/time-entries` + + const body = { + start: start, + end: end, + projectId: projectID, + description: taskName + } + + const headers = { + 'X-Api-Key': apiKey, + 'Content-type' : 'application/json; charset=UTF-8' + } + + const request = { + method: 'POST', + body: JSON.stringify(body), + headers + } + + const result = await fetch(url, request) + const data = await result.json() + + console.log(data) + + } catch (error) { + console.log(error) + } +} + +export default uploadToClockifyTimer diff --git a/src/components/Main Pomodoro Childrens/MainPomodoroTimer.jsx b/src/components/Main Pomodoro Childrens/MainPomodoroTimer.jsx index 298f857..6a86664 100644 --- a/src/components/Main Pomodoro Childrens/MainPomodoroTimer.jsx +++ b/src/components/Main Pomodoro Childrens/MainPomodoroTimer.jsx @@ -167,7 +167,7 @@ const MainPomodoroTimer = (props) => { const startTimer = () => { - document.title = minutes + ':' + seconds + //document.title = minutes + ':' + seconds document.addEventListener('visibilitychange', () => {