-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Involve-Digital/progress-bar
[WIP] progress bar
- Loading branch information
Showing
9 changed files
with
466 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const BASE_API_URL = 'https://involve-backend.local/api/v1'; | ||
const TOGGL_REPORT_URL = 'https://track.toggl.com/reports/summary/1033184/description/__taskName__/period/last12Months'; | ||
|
||
const handleRunTracking = async (taskName, project, tags) => { | ||
const togglApiKey = await getDataFromChromeStorage('togglApiKey'); | ||
|
||
if (!togglApiKey){ | ||
return; | ||
} | ||
|
||
fetch(BASE_API_URL + '/asana-extension/run-tracking', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
apiKey: togglApiKey, | ||
taskName, | ||
project, | ||
tags: tags | ||
}) | ||
}).catch(err => console.error(err)); | ||
}; | ||
|
||
const getTaskInfo = async (taskId) => { | ||
const asanaApiKey = await getDataFromChromeStorage('asanaApiKey'); | ||
|
||
if (!asanaApiKey){ | ||
return; | ||
} | ||
|
||
const response = await fetch(BASE_API_URL + '/asana-extension/task-information', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
apiKey: asanaApiKey, | ||
taskId, | ||
}) | ||
}); | ||
|
||
const jsonResponse = await response.json(); | ||
|
||
return jsonResponse?.data | ||
}; | ||
|
||
const getUsedBudget = async (taskId) => { | ||
const asanaApiKey = await getDataFromChromeStorage('asanaApiKey'); | ||
const togglApiKey = await getDataFromChromeStorage('togglApiKey'); | ||
|
||
if (!asanaApiKey || !togglApiKey){ | ||
return; | ||
} | ||
|
||
const response = await fetch(BASE_API_URL + '/asana-extension/time-spent', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
apiKey: asanaApiKey, | ||
togglApiKey, | ||
taskId, | ||
}) | ||
}); | ||
|
||
const jsonResponse = await response.json(); | ||
|
||
return jsonResponse?.data?.usedBudget ?? null; | ||
}; | ||
|
||
const getDataFromChromeStorage = (key) => { | ||
return new Promise((resolve, reject) => { | ||
chrome.storage.sync.get(key, function (data) { | ||
if (chrome.runtime.lastError) { | ||
reject(chrome.runtime.lastError); | ||
} else if (data[key]) { | ||
resolve(data[key]); | ||
} else { | ||
console.log('Could not get data for key: ' + key); | ||
resolve(null); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const ICONS_TO_BUTTON = { | ||
[COPY_BUTTON_ID]: 'copy', | ||
[START_TRACKING_BUTTON_ID]: 'start', | ||
[START_CODE_REVIEW_TRACKING_BUTTON_ID]: 'start-cr', | ||
} | ||
|
||
const appendButton = ( | ||
elementToAppendButton, | ||
id, | ||
svg, | ||
onClickCallback, | ||
title, | ||
childrenToInsertBeforeIndex = 3, | ||
) => { | ||
const buttonExists = document.getElementById(id); | ||
let button = buttonExists; | ||
|
||
if (!button) { | ||
button = document.createElement('button'); | ||
} | ||
|
||
button.id = id; | ||
button.innerHTML = svg; | ||
|
||
if (title) { | ||
button.title = title; | ||
} | ||
|
||
button.onclick = (e) => onClickCallback(e); | ||
|
||
if (!buttonExists) { | ||
const referenceElement = elementToAppendButton.children[childrenToInsertBeforeIndex]; | ||
|
||
elementToAppendButton.insertBefore(button,referenceElement); | ||
} | ||
}; | ||
|
||
const getSvgIcon = (name) => { | ||
const svgPath = chrome.runtime.getURL('icons/' + name + '.svg'); | ||
|
||
return fetch(svgPath) | ||
.then(response => response.text()) | ||
.catch(error => { | ||
console.error('Error loading SVG:', error); | ||
|
||
return ''; | ||
}); | ||
} |
Oops, something went wrong.