mirror of
https://github.com/FranP-code/Pomodoro-Timer-with-Clockify-integration.git
synced 2025-10-12 23:52:30 +00:00
Mod. git ignore
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -24,4 +24,4 @@ yarn-error.log*
|
|||||||
|
|
||||||
# firebase
|
# firebase
|
||||||
|
|
||||||
src/components/Firebase
|
#/src/components/Firebase
|
||||||
|
|||||||
20
src/components/Clockify/clockify.js
Normal file
20
src/components/Clockify/clockify.js
Normal file
@@ -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}
|
||||||
58
src/components/Clockify/getAndFormatCurrentTime.js
Normal file
58
src/components/Clockify/getAndFormatCurrentTime.js
Normal file
@@ -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
|
||||||
38
src/components/Clockify/uploadToClockifyTimer.js
Normal file
38
src/components/Clockify/uploadToClockifyTimer.js
Normal file
@@ -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
|
||||||
@@ -167,7 +167,7 @@ const MainPomodoroTimer = (props) => {
|
|||||||
|
|
||||||
const startTimer = () => {
|
const startTimer = () => {
|
||||||
|
|
||||||
document.title = minutes + ':' + seconds
|
//document.title = minutes + ':' + seconds
|
||||||
|
|
||||||
document.addEventListener('visibilitychange', () => {
|
document.addEventListener('visibilitychange', () => {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user