Skip to content

Commit

Permalink
Merge pull request #414 from 3DStreet/notify-methods-in-STREET
Browse files Browse the repository at this point in the history
Notify methods in global STREET object
  • Loading branch information
kfarr authored Dec 9, 2023
2 parents c9c7250 + dd39083 commit c7f7089
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/components/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ AFRAME.registerComponent('notify', {
dismissible: this.data.dismissible
});
this.types = this.notify.options.types.map(messType => messType.type);

// add notify methods to STREET global objects
if (STREET) {
STREET.notify = {};
STREET.notify.successMessage = (messageText) => {
this.message(messageText, 'success');
}
STREET.notify.errorMessage = (messageText)=> {
this.message(messageText, 'error');
}
}
},
message: function (messageText, messageType = 'info') {
if (messageText && this.types.includes(messageType)) {
Expand Down
15 changes: 3 additions & 12 deletions src/json-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,21 +562,15 @@ AFRAME.registerComponent('set-loader-from-hash', {
console.error(
'[set-loader-from-hash] Error trying to load scene: Resource not found.'
);
AFRAME.scenes[0].components['notify'].message(
'Error trying to load scene: Resource not found.',
'error'
);
STREET.notify.errorMessage('Error trying to load scene: Resource not found.');
}
};
request.onerror = function () {
// There was a connection error of some sort
console.error(
'Loading Error: There was a connection error during JSON loading'
);
AFRAME.scenes[0].components['notify'].message(
'Could not fetch scene.',
'error'
);
STREET.notify.errorMessage('Could not fetch scene.');
};
request.send();
}
Expand Down Expand Up @@ -647,10 +641,7 @@ function createElementsFromJSON(streetJSON) {
}

createEntities(streetObject.data, streetContainerEl);
AFRAME.scenes[0].components['notify'].message(
'Scene loaded from JSON',
'success'
);
STREET.notify.successMessage('Scene loaded from JSON');
}

// viewer widget click to paste json string of 3dstreet scene
Expand Down

0 comments on commit c7f7089

Please sign in to comment.