mirror of
https://github.com/cupcakearmy/ora.git
synced 2026-04-02 20:15:25 +00:00
consolidate all views
This commit is contained in:
47
src/dashboard/components/FileUpload.svelte
Normal file
47
src/dashboard/components/FileUpload.svelte
Normal file
@@ -0,0 +1,47 @@
|
||||
<script>
|
||||
import { isEqual } from 'lodash'
|
||||
|
||||
let text = 'Select File'
|
||||
|
||||
export let value = undefined
|
||||
|
||||
let input
|
||||
let error
|
||||
|
||||
function validate() {
|
||||
if (!input || !input.files.length) return
|
||||
|
||||
const file = input.files[0]
|
||||
text = file.name
|
||||
|
||||
const reader = new FileReader()
|
||||
reader.onload = (data) => {
|
||||
try {
|
||||
error = false
|
||||
const text = data.target.result
|
||||
const parsed = JSON.parse(text)
|
||||
value = parsed
|
||||
} catch {
|
||||
error = true
|
||||
value = undefined
|
||||
}
|
||||
}
|
||||
reader.readAsText(file)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
label {
|
||||
width: 18em;
|
||||
max-width: 100%;
|
||||
display: inline-block;
|
||||
}
|
||||
label input[type='file'] {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
<label class="btn">
|
||||
{#if error}Invalid file{:else}{text}{/if}
|
||||
<input bind:this={input} on:change={validate} class="input" accept="application/json" type="file" />
|
||||
</label>
|
||||
Reference in New Issue
Block a user