Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Loading indicator #182 #255

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions app/ui/omni-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class OmniBox extends HTMLElement {
<form class="omni-box-form">
<input class="omni-box-target-input" readonly></input>
<input class="omni-box-input" title="Enter search params">
<button class="omni-box-button" type="submit" title="Load page or Reload">⊚</button>
<button class="omni-box-button" type="submit" title="Load page or Reload"> <span id="reloadButton">⊚</span> </button>
<button class="omni-box-button" type="submit" title="Loading..."> <div id="loadingButton" class="spinner"></div> </button>
</form>
</section>
`
Expand All @@ -34,6 +35,7 @@ class OmniBox extends HTMLElement {
this.form = this.$('.omni-box-form')
this.input = this.$('.omni-box-input')
this.targetUrl = this.$('.omni-box-target-input')
this.loader = this.$('omni-box-button')

this.input.addEventListener('focus', () => {
this.input.select()
Expand Down Expand Up @@ -242,7 +244,7 @@ class OmniBox extends HTMLElement {
}

static get observedAttributes () {
return ['src', 'back', 'forward']
return ['src', 'back', 'forward', 'loading']
}

attributeChangedCallback (name, oldValue, newValue) {
Expand All @@ -260,6 +262,14 @@ class OmniBox extends HTMLElement {
this.backButton.classList.toggle('hidden', newValue === 'hidden')
} else if (name === 'forward') {
this.forwardButton.classList.toggle('hidden', newValue === 'hidden')
} else if(name === 'loading') {
if (newValue === 'true') {
this.loader.getElementById('reloadButton').classList.toggle('hidden', newValue)
this.loader.getElementById('loadingButton').classList.toggle('visible', newValue)
} else {
this.loader.getElementById('loadingButton').classList.toggle('hidden', newValue)
this.loader.getElementById('reloadButton').classList.toggle('visible', newValue)
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions app/ui/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ currentWindow.on('browser-actions-changed', () => {
actions.renderLatest()
})

currentWindow.on('did-start-navigation', () => {
search.setAttribute('loading', 'true')
})

currentWindow.on('did-navigate', () => {
search.setAttribute('loading', 'false')
})


find.addEventListener('next', ({ detail }) => {
const { value, findNext } = detail

Expand Down
15 changes: 15 additions & 0 deletions app/ui/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ omni-box {
font-family: inherit;
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

.spinner {
border: 4px solid #f3f3f3;
border-top: 4px solid #422a85;
border-radius: 50%;
width: 5px;
height: 5px;
animation: spin 1.6s linear infinite;
}


.omni-box-nav-item {
border: 1px solid var(--ag-theme-primary);
display: flex;
Expand Down
2 changes: 2 additions & 0 deletions app/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,11 @@ export class Window extends EventEmitter {

this.web.on('did-start-navigation', (event, url, isInPlace, isMainFrame) => {
this.emitNavigate(url, isMainFrame)
this.emit('did-start-navigation')
})
this.web.on('did-navigate', (event, url) => {
this.emitNavigate(url, true)
this.emit('did-navigate')
})
this.web.on('did-navigate-in-page', (event, url, isMainFrame) => {
this.emitNavigate(url, isMainFrame)
Expand Down
Loading