Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

URL bar updating improvements #8

Merged
merged 5 commits into from
Dec 8, 2015
Merged
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
13 changes: 12 additions & 1 deletion js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ const AppActions = {
})
},

setNavBarInput: function (location) {
setLocation: function (loc, key) {
if (UrlUtil.isURL(loc)) {
loc = UrlUtil.getUrlFromInput(loc)
}
AppDispatcher.dispatch({
actionType: AppConstants.APP_SET_LOCATION,
location: loc,
key: key
})
},

setNavBarUserInput: function (location) {
AppDispatcher.dispatch({
actionType: AppConstants.APP_SET_NAVBAR_INPUT,
location
Expand Down
17 changes: 12 additions & 5 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,21 @@ class Frame extends ImmutableComponent {
this.webview.addEventListener('dom-ready', () => {
console.log('dom is ready')
})
this.webview.addEventListener('did-get-redirect-request', (oldUrl, newUrl) => {
console.log('got redirect', newUrl)
AppActions.setNavBarInput(newUrl)
this.webview.addEventListener('did-get-redirect-request', (event) => {
// Update the url bar for top-level location changes
if (event.isMainFrame) {
let key = this.props.frame.get('key')
console.log('got redirect', event.oldURL, event.newURL, key)
AppActions.setLocation(event.newURL, key)
}
})
this.webview.addEventListener('did-start-loading', () => {
console.log('spinner start loading')
let key = this.props.frame.get('key')
let location = this.props.frame.get('location')
console.log('spinner start loading', location, key)
AppActions.onWebviewLoadStart(
this.props.frame)
AppActions.setLocation(location, key)
})
this.webview.addEventListener('did-stop-loading', () => {
console.log('spinner stop loading')
Expand Down Expand Up @@ -126,7 +133,7 @@ class Frame extends ImmutableComponent {
})}>
<webview
ref='webview'
src={this.props.frame.get('location')}
src={this.props.frame.get('src')}
preload='content/webviewPreload.js'/>
</div>
}
Expand Down
9 changes: 8 additions & 1 deletion js/components/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,21 @@ class UrlBar extends ImmutableComponent {
}

onChange (e) {
AppActions.setNavBarInput(e.target.value)
AppActions.setNavBarUserInput(e.target.value)
}

onFocus (e) {
this.select()
AppActions.setNavBarFocused(true)
}

componentWillReceiveProps (newProps) {
let location = newProps.activeFrameProps.get('location')
if (location !== this.props.activeFrameProps.get('location')) {
AppActions.setLocation(location)
}
}

render () {
return <form
action='#'
Expand Down
2 changes: 1 addition & 1 deletion js/components/urlBarSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class UrlBarSuggestions extends ImmutableComponent {

let navigateClickHandler = formatUrl => site => {
let location = formatUrl(site)
AppActions.setNavBarInput(location)
AppActions.setNavBarUserInput(location)
AppActions.loadUrl(location)
this.blur()
}
Expand Down
3 changes: 2 additions & 1 deletion js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ module.exports = {
APP_SET_URL_BAR_PREVIEW: 18,
APP_SET_URL_BAR_SUGGESTION_SEARCH_RESULTS: 19,
APP_WEBVIEW_LOAD_START: 20,
APP_SET_FRAME_TITLE: 21
APP_SET_FRAME_TITLE: 21,
APP_SET_LOCATION: 22 // sets location of a frame
}
2 changes: 1 addition & 1 deletion js/constants/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
height: 100
},
defaultLocale: 'en-US',
defaultUrl: 'http://www.brave.com',
defaultUrl: 'about:blank',
urlBarSuggestions: {
maxTopSites: 5,
maxSearch: 3,
Expand Down
20 changes: 16 additions & 4 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ const updateUrl = (loc) =>
title: ''
})

const setLocation = (loc, key) => {
key = key || appState.get('activeFrameKey')
console.log('updating location', loc, key)
appState = appState.mergeIn(['frames', FrameStateUtil.findIndexForFrameKey(appState.get('frames'), key)], {
location: loc
})
// Update the displayed location in the urlbar
if (key === appState.get('activeFrameKey')) {
updateNavBarInput(loc)
}
}

const updateNavBarInput = (loc) => {
appState = appState.setIn(['ui', 'navbar', 'urlbar', 'location'], loc)
appState = appState.setIn(['ui', 'navbar', 'urlbar', 'urlPreview'], null)
Expand Down Expand Up @@ -79,6 +91,10 @@ AppDispatcher.register((action) => {
updateUrl(action.location)
appStore.emitChange()
break
case AppConstants.APP_SET_LOCATION:
setLocation(action.location, action.key)
appStore.emitChange()
break
case AppConstants.APP_SET_NAVBAR_INPUT:
updateNavBarInput(action.location)
appStore.emitChange()
Expand All @@ -96,10 +112,6 @@ AppDispatcher.register((action) => {
appStore.emitChange()
break
case AppConstants.APP_WEBVIEW_LOAD_END:
// Only update for the active frame.
if (action.frameProps === appState.getIn(['frames', FrameStateUtil.findIndexForFrameKey(appState.get('frames'), appState.get('activeFrameKey'))])) {
updateNavBarInput(action.location)
}
appState = appState.mergeIn(['frames', FrameStateUtil.getFramePropsIndex(appState.get('frames'), action.frameProps)], {
loading: false
})
Expand Down