commit
aa5c456611
19 changed files with 115 additions and 26 deletions
@ -1 +1,3 @@ |
|||||||
# Bash scripting |
# Bash scripting |
||||||
|
|
||||||
|
- [Bash Scripting Tutorial](https://www.freecodecamp.org/news/bash-scripting-tutorial-linux-shell-script-and-command-line-for-beginners/) |
@ -0,0 +1,57 @@ |
|||||||
|
import { httpGet } from './http'; |
||||||
|
import { isLoggedIn } from './jwt'; |
||||||
|
|
||||||
|
type UserProgressResponse = { |
||||||
|
resourceId: string; |
||||||
|
resourceType: 'roadmap' | 'best-practice'; |
||||||
|
done: number; |
||||||
|
learning: number; |
||||||
|
skipped: number; |
||||||
|
total: number; |
||||||
|
updatedAt: Date; |
||||||
|
}[]; |
||||||
|
|
||||||
|
async function renderProgress() { |
||||||
|
if (!isLoggedIn()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
const { response: progressList, error } = await httpGet<UserProgressResponse>( |
||||||
|
`${import.meta.env.PUBLIC_API_URL}/v1-get-user-all-progress` |
||||||
|
); |
||||||
|
|
||||||
|
if (error || !progressList) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
progressList.forEach((progress) => { |
||||||
|
const href = |
||||||
|
progress.resourceType === 'best-practice' |
||||||
|
? `/best-practices/${progress.resourceId}` |
||||||
|
: `/${progress.resourceId}`; |
||||||
|
const element = document.querySelector(`a[href="${href}"]`); |
||||||
|
if (!element) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
const totalDone = progress.done + progress.skipped; |
||||||
|
const percentageDone = (totalDone / progress.total) * 100; |
||||||
|
|
||||||
|
const progressBar = document.createElement('div'); |
||||||
|
progressBar.style.backgroundColor = 'rgb(23 42 58)'; |
||||||
|
progressBar.style.position = 'absolute'; |
||||||
|
progressBar.style.width = `${percentageDone}%`; |
||||||
|
progressBar.style.height = '100%'; |
||||||
|
progressBar.style.bottom = '0'; |
||||||
|
progressBar.style.left = '0'; |
||||||
|
progressBar.style.top = '0'; |
||||||
|
progressBar.style.zIndex = '1'; |
||||||
|
|
||||||
|
element.appendChild(progressBar); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
// on DOM load
|
||||||
|
window.addEventListener('DOMContentLoaded', () => { |
||||||
|
window.setTimeout(renderProgress, 0); |
||||||
|
}); |
Loading…
Reference in new issue