Skip to content

Commit

Permalink
add notify methods to global STREET object
Browse files Browse the repository at this point in the history
- add succesMessage and errorMessage to notify object
- replace legacy notify methods calls to new ones
  • Loading branch information
Algorush committed Nov 22, 2023
1 parent be8b997 commit d4a9dfb
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 @@ -561,21 +561,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 @@ -646,10 +640,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 d4a9dfb

Please sign in to comment.