Skip to content

Commit

Permalink
Hopefully fix the issues with loading configurations. Fixes #582.
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardMoyse committed Sep 20, 2024
1 parent 153ace6 commit 525c2b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/phoenix-event-display/src/helpers/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,31 @@ export const loadFile = (
contentType: string = 'application/json',
) => {
// Create a mock input file element and use that to read the file
let inputFile = document.createElement('input');
const inputFile = document.createElement('input');
document.body.appendChild(inputFile);
inputFile.type = 'file';
inputFile.accept = contentType;
inputFile.onchange = (e: any) => {
inputFile.onclick = (e: any) => {
e.target.value = '';
};

inputFile.addEventListener('invalid', (e) => {
console.log(JSON.stringify(e));
});

const fileSelected = (e: any) => {
const configFile = e.target?.files[0];
const reader = new FileReader();
reader.onload = (e) => {
if (e.target && e.target.result) {
onFileRead?.(e.target.result.toString());
}
inputFile.remove();
inputFile = document.createElement('input');
// For explanation, see https://stackoverflow.com/a/26221525
};
reader.readAsText(configFile);
};

inputFile.oninput = fileSelected;
inputFile.onchange = fileSelected;
inputFile.click();
setTimeout(() => {
console.log('Let us just wait a second');
}, 1000);
};
2 changes: 2 additions & 0 deletions packages/phoenix-event-display/src/managers/state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ export class StateManager {
typeof json === 'string' ? JSON.parse(json) : json;

if (jsonData['phoenixMenu'] && this.phoenixMenuRoot) {
console.log('StateManager: Processing phoenixMenu configuration');
this.phoenixMenuRoot.loadStateFromJSON(jsonData['phoenixMenu']);
this.phoenixMenuRoot.configActive = false;
}

if (jsonData['eventDisplay']) {
console.log('StateManager: Processing eventDisplay configuration');
this.activeCamera.position.fromArray(
jsonData['eventDisplay']?.['cameraPosition'],
);
Expand Down

0 comments on commit 525c2b9

Please sign in to comment.