Skip to content

Commit

Permalink
Some improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinit-Pandit committed Apr 26, 2024
1 parent 3aac2ed commit 8ccc444
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
32 changes: 17 additions & 15 deletions www/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ function onAnalyze (value) {
const LoaderElement = document.createElement('div')
LoaderElement.classList.add('loader')
const fileInputElement = document.getElementById('fileInput')
const removeBtn = document.getElementById('remove')

function showLoader (bool) {
if (bool) {
Expand All @@ -197,35 +198,36 @@ function analyzer () {
const file = fileInputElement.files[0]
showLoader(true)
if (file) {
if (file.type === 'application/json') {
const reader = new FileReader()
reader.onload = function (event) {
const contents = event.target.result
onAnalyze(contents)
showLoader(false)
}
reader.readAsText(file)
} else {
console.error('Please select a JSON file.')
const reader = new FileReader()
reader.onload = function (event) {
const contents = event.target.result
onAnalyze(contents)
showLoader(false)
}
reader.readAsText(file)
} else {
code.getWrapperElement().style.display = ''
onAnalyze(code.getValue())
showLoader(false)
}
}

document.getElementById('remove').addEventListener('click', () => {
removeBtn.addEventListener('click', () => {
fileInputElement.value = ''
code.getWrapperElement().style.display = ''
code.setValue('')
code.setOption('readOnly', false)
removeBtn.classList.add('uk-disabled')
})

fileInputElement.addEventListener('change', (e) => {
if (e.target.files[0]) {
code.getWrapperElement().style.display = 'none'
code.setValue('Reading from input file')
code.setOption('readOnly', true)
removeBtn.classList.remove('uk-disabled')
} else {
console.log('else is clicked')
removeBtn.classList.add('uk-disabled')
}
})

document.getElementById('analyze').addEventListener('click', analyzer)

onAnalyze(code.getValue())
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<div>
<input type="file" id="fileInput" accept="application/json" class="uk-input uk-form-file">
<button id="remove" class="uk-button uk-button-danger uk-margin-small uk-width-1-1">Remove File</button>
<button id="remove" class="uk-button uk-button-danger uk-margin-small uk-width-1-1 uk-disabled">Remove File</button>
<button id="analyze" class="uk-button uk-button-primary uk-width-1-1">Analyze JSON</button>
</div>

Expand Down

0 comments on commit 8ccc444

Please sign in to comment.