feature: create Svelte component for showing status UI

This commit is contained in:
Ondřej Synáček 2020-12-20 14:29:21 +01:00
parent b28995aa1e
commit 290d7115d0
6 changed files with 45 additions and 22 deletions

View File

@ -10,10 +10,15 @@ const getEventHTML = async (url) => {
formData.set('url', url) formData.set('url', url)
try { try {
const request = new Request({ id: uuidv4() }) const request = new Request({
id: uuidv4(),
url,
})
requestStore.set(request) requestStore.set(request)
const response = await postURL(formData) const response = await postURL(formData)
const text = await response.text() const text = await response.text()
requestStore.set(null)
return text return text
} catch (error) { } catch (error) {
requestStore.update((prevRequest) => { requestStore.update((prevRequest) => {

View File

@ -1,7 +1,8 @@
<script> <script>
import Input from './Input.svelte' import Input from './Input.svelte'
import TrackingPanel from './TrackingPanel.svelte'
import EventList from './EventList.svelte' import EventList from './EventList.svelte'
import Status from './Status.svelte'
import TrackingPanel from './TrackingPanel.svelte'
import { configStore, eventStore } from '../stores' import { configStore, eventStore } from '../stores'
@ -13,6 +14,7 @@
<TrackingPanel /> <TrackingPanel />
{/if} {/if}
<Status />
<Input /> <Input />
{#if showEventList} {#if showEventList}
<EventList /> <EventList />

View File

@ -0,0 +1,34 @@
<style>
#status {
flex: 1;
height: 1rem;
margin: 5px;
}
.status-item {
min-width: 200px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
</style>
<script>
import { requestStore } from '../stores'
$: error = ($requestStore && $requestStore.error) ? $requestStore.error : null
$: pendingRequest = Boolean($requestStore && !$requestStore.error)
</script>
<div id='status'>
{#if error}
<div class='status-item'>
{error.toString()}
</div>
{/if}
{#if pendingRequest}
<div class='status-item'>
Fetching event {$requestStore.url}
</div>
{/if}
</div>

View File

@ -1,9 +1,11 @@
export default class Request { export default class Request {
constructor({ constructor({
id, id,
url,
error, error,
}) { }) {
this.id = id this.id = id
this.url = url
this.error = error this.error = error
} }
} }

View File

@ -42,12 +42,6 @@
</noscript> </noscript>
<div id="status"> <div id="status">
<div class="status-item" id="network">
Fetching file...
</div>
<div class="status-item" id="parsing">
Parsing data...
</div>
<div class="status-item" id="error"> <div class="status-item" id="error">
</div> </div>
<div class="status-item" id="service-worker"> <div class="status-item" id="service-worker">

View File

@ -91,20 +91,6 @@ input#url {
flex: 1; flex: 1;
} }
#status {
flex: 1;
height: 1rem;
margin: 5px;
}
.status-item {
display: none;
min-width: 200px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.show { .show {
display: block; display: block;
} }