Skip to content

Commit

Permalink
fix twice loading street issue (fixes #50)
Browse files Browse the repository at this point in the history
also removes som extra logging
  • Loading branch information
kfarr committed Jul 14, 2020
1 parent 3868fba commit bfb3eba
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/aframe-streetmix-loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,20 @@ function loadStreet (streetURL) {
}

function initStreet () {
// Run processURLChange when Enter pressed on input field
// This function should probably be somewhere else
document.getElementById('input-url').onkeypress = function (e) {
if (!e) e = window.event;
var keyCode = e.keyCode || e.which;
if (keyCode == '13') {
// Enter pressed
processURLChange();
}
};

// Is there a URL in the URL HASH?
var streetURL = location.hash.substring(1);
console.log('hash check: ' + streetURL);
// console.log('hash check: ' + streetURL);

if (streetURL) {
var pathArray = new URL(streetURL).pathname.split('/');
Expand All @@ -48,25 +59,17 @@ function initStreet () {

// REMOTE WITH REDIRECT:
var streetURL = 'https://streetmix.net/api/v1/streets?namespacedId=3&creatorId=kfarr';

window.location.hash = '#' + streetmixAPIToUser(streetURL);
document.getElementById('input-url').value = streetmixAPIToUser(streetURL);
return;
// DIRECT TO REMOTE FILE: - don't use this since it's hard to convert back to user friendly URL
// var streetURL = 'https://streetmix.net/api/v1/streets/7a633310-e598-11e6-80db-ebe3de713876';
}

console.log('streetURL check: ' + streetURL);
// console.log('streetURL check: ' + streetURL);
loadStreet(streetURL);
window.location.hash = '#' + streetmixAPIToUser(streetURL);
document.getElementById('input-url').value = streetmixAPIToUser(streetURL);

// Run processURLChange when Enter pressed on input field
document.getElementById('input-url').onkeypress = function (e) {
if (!e) e = window.event;
var keyCode = e.keyCode || e.which;
if (keyCode == '13') {
// Enter pressed
processURLChange();
}
};
}
window.onload = initStreet; // TODO: move somewhere else (maybe index.html)

Expand All @@ -75,7 +78,7 @@ function locationHashChanged () {
// check if valid hash
// if yes, then clear old city // load new city with that hash
var streetURL = location.hash.substring(1);
console.log('hash changed to: ' + streetURL);
// console.log('hash changed to: ' + streetURL);

if (streetURL) {
var pathArray = new URL(streetURL).pathname.split('/');
Expand All @@ -95,16 +98,14 @@ window.onhashchange = locationHashChanged; // TODO: move somewhere else (maybe i
// Load new street from input-url value
function processURLChange () {
var streetURL = document.getElementById('input-url').value;
console.log('hash changed to: ' + streetURL);
// console.log('hash changed to: ' + streetURL);

if (streetURL) {
var pathArray = new URL(streetURL).pathname.split('/');
// optimistically try to convert from streetmix URL to api url
if (pathArray[1] != 'api') {
streetURL = streetmixUserToAPI(streetURL);
}

loadStreet(streetURL);
window.location.hash = '#' + streetmixAPIToUser(streetURL);
}
}

0 comments on commit bfb3eba

Please sign in to comment.