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

Notify methods in global STREET object #414

Merged
merged 2 commits into from
Dec 9, 2023
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
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
Loading