Created
December 2, 2023 05:44
-
-
Save nickforce/860f7b70b892aa8fb8ee279b93e8775d to your computer and use it in GitHub Desktop.
AdventofCode_FileReader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LightningElement } from 'lwc'; | |
import readPuzzleInput from '@salesforce/apex/Advent.readPuzzleInput'; | |
export default class AdventofCode_FileReader extends LightningElement { | |
puzzleInput; | |
puzzleInputFileName; | |
puzzleAnswer; | |
handlePuzzleInputChange(event) { | |
this.puzzleInput = event.target.files[0]; | |
this.puzzleInputFileName = event.target.files[0].name; | |
} | |
get disabled() { | |
return this.puzzleInput ? false : true; | |
} | |
uploadPuzzleInput() { | |
if (this.puzzleInput) { | |
const reader = new FileReader(); | |
reader.onload = () => { | |
const fileContent = reader.result; | |
// process the puzzle input | |
readPuzzleInput({ fileName: this.puzzleInput.name, fileContent }) | |
.then(result => { | |
// Handle success | |
console.log('File uploaded successfully:', result); | |
this.puzzleAnswer = result; | |
}) | |
.catch(error => { | |
// Handle error | |
console.error('Error uploading file:', error); | |
}); | |
}; | |
reader.readAsText(this.puzzleInput); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment