Skip to content

Commit

Permalink
🚸 add loading spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
Norfeldt committed Jan 12, 2023
1 parent 9002fde commit 2464df8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "github-issue-reactions-browser-extension",
"version": "2.0.2",
"version": "2.1.0",
"repository": "git@github.com:Norfeldt/github-issue-reactions-browser-extension.git",
"author": "Lasse Nørfeldt <lasse@norfeldt.com>",
"license": "MIT",
Expand Down
35 changes: 31 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ function debounce(func: Function, timeout = 2000): Function {
}
}

// INITIAL LOADING INDICATOR
injectWrapper({ withLoadingSpinner: true })

// CHANGE PAGE
const mainObserver = new MutationObserver((mutations) => {
// console.log('mainObserver')
Expand Down Expand Up @@ -50,8 +53,8 @@ function startObservingComments() {
}

// Create a sticking wrapper to place all reactions
function injectWrapper() {
// console.log('injectWrapper')
function injectWrapper({ withLoadingSpinner } = { withLoadingSpinner: false }) {
console.log('injectWrapper')
const header = document.querySelector(sideBarId) as HTMLDivElement
if (!header) return
header.style.position = 'relative'
Expand All @@ -64,10 +67,36 @@ function injectWrapper() {
wrapper.style.position = 'sticky'
wrapper.style.setProperty('position', '-webkit-sticky', 'important')
wrapper.style.top = top + 'px'
wrapper.innerHTML = ''
wrapper.appendChild(Title('Reactions'))

if (withLoadingSpinner) {
wrapper.appendChild(LoadingSpinner())
}

header.appendChild(wrapper)
}

function LoadingSpinner() {
const loadingSpinner = document.createElement('div')
loadingSpinner.style.width = '50px'
loadingSpinner.style.height = '50px'
loadingSpinner.style.border = '2px solid #f3f3f3'
loadingSpinner.style.borderTop = '2px solid #3498db'
loadingSpinner.style.borderRadius = '50%'
loadingSpinner.style.animation = 'spin 1s linear infinite'
const style = document.createElement('style')
document.head.appendChild(style)
const keyframes = `
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}`
style.sheet?.insertRule(keyframes)

return loadingSpinner
}

// Scan the site for reactions and stick it into the wrapper
function addReactionNav() {
// console.log('addReactionNav')
Expand All @@ -78,8 +107,6 @@ function addReactionNav() {
return
}

wrapper.innerHTML = ''
wrapper.appendChild(Title('Reactions'))
wrapper.appendChild(Reactions())
if (window.location.pathname.match(/\/discussions\//)) {
wrapper.appendChild(Title('Discussion Votes'))
Expand Down

0 comments on commit 2464df8

Please sign in to comment.