Skip to content

Commit

Permalink
Merge pull request #700 from HSF/main-fix-state-loading
Browse files Browse the repository at this point in the history
Main fix state loading
  • Loading branch information
EdwardMoyse authored Nov 29, 2024
2 parents ff3d72a + dfd23ba commit 0ec494f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ export class PhoenixMenuNode {

this.childrenActive = jsonObject['childrenActive'];
this.toggleState = jsonObject['toggleState'];
// eslint-disable-next-line
this.toggleState !== undefined && this.onToggle?.(this.toggleState);

this.onToggle?.(this.toggleState);

for (const configState of jsonObject['configs']) {
const nodeConfigs = this.configs.filter(
Expand Down
26 changes: 21 additions & 5 deletions packages/phoenix-event-display/src/managers/url-options-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,32 @@ export class URLOptionsManager {
}

if (!this.urlOptions.get('file') || !this.urlOptions.get('type')) {
console.log('Setting and config from defaults');
file = defaultEventPath;
type = defaultEventType;
} else {
console.log('Setting and config from urlOptions');
file = this.urlOptions.get('file') ?? '';
type = this.urlOptions.get('type')?.toLowerCase() ?? '';
console.log(
'Default file(',
defaultEventPath,
') was overridden by URL options to: ',
file,
);
}

console.log('Loading ', file, 'of type', type);
// Load config from URL
console.log('Try to load event file: ', file, 'of type', type);
// Try to load config from URL
const loadConfig = () => {
if (this.urlOptions.get('config')) {
this.eventDisplay.getLoadingManager().addLoadableItem('url_config');
fetch(this.urlOptions.get('config') ?? '')
.then((res) => res.json())
.then((jsonState) => {
console.log(
'Applying configuration ',
this.urlOptions.get('config'),
' from urlOptions',
);
const stateManager = new StateManager();
stateManager.loadStateFromJSON(jsonState);
})
Expand Down Expand Up @@ -141,7 +150,14 @@ export class URLOptionsManager {
* @returns An empty promise. ;(
*/
private async handleJiveXMLEvent(fileURL: string) {
const fileData = await (await fetch(fileURL)).text();
const fileData = await (
await fetch(fileURL).then((response) => {
if (response.status >= 400 && response.status < 600) {
throw new Error('Bad response from server');
}
return response;
})
).text();
if (!this.configuration.eventDataLoader) {
this.configuration.eventDataLoader = new JiveXMLLoader();
}
Expand Down

0 comments on commit 0ec494f

Please sign in to comment.