feature: add store for tracking network request to API
This commit is contained in:
parent
4fad8e442d
commit
128b03344b
|
@ -0,0 +1,5 @@
|
|||
import Request from './request'
|
||||
|
||||
export {
|
||||
Request,
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
export default class Request {
|
||||
constructor({
|
||||
id,
|
||||
error,
|
||||
}) {
|
||||
this.id = id
|
||||
this.error = error
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
import configStore from './configStore'
|
||||
import eventStore from './eventStore'
|
||||
import requestStore from './requestStore'
|
||||
|
||||
export {
|
||||
configStore,
|
||||
eventStore,
|
||||
requestStore,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
import { writable } from 'svelte/store'
|
||||
|
||||
export default writable(null)
|
|
@ -9,8 +9,16 @@ import { extractEventDataFromHTML } from '../../lib/services/ics-retriever'
|
|||
import generateICS from '../../lib/services/ics-generator'
|
||||
|
||||
import boot from '../frontend'
|
||||
import { requestStore } from '../frontend/stores'
|
||||
import { Request } from '../frontend/records'
|
||||
|
||||
(() => {
|
||||
let request = null
|
||||
|
||||
requestStore.subscribe((updatedRequest) => {
|
||||
request = updatedRequest
|
||||
})
|
||||
|
||||
document.addEventListener('DOMContentLoaded', boot)
|
||||
|
||||
const createRecord = (uri, summary, startTime) => {
|
||||
|
@ -73,17 +81,29 @@ import boot from '../frontend'
|
|||
input.disabled = true
|
||||
submitButton.disabled = true
|
||||
setStatusDownloading()
|
||||
|
||||
requestStore.set(new Request({
|
||||
id: uuidv4(),
|
||||
error: null,
|
||||
}))
|
||||
}
|
||||
|
||||
const finishedRequest = () => {
|
||||
input.disabled = false
|
||||
submitButton.disabled = false
|
||||
clearStatuses()
|
||||
|
||||
requestStore.set(null)
|
||||
}
|
||||
|
||||
const handleError = (error) => {
|
||||
finishedRequest()
|
||||
setStatusError(error)
|
||||
|
||||
requestStore.update((prevRequest) => {
|
||||
prevRequest.error = error
|
||||
return prevRequest
|
||||
})
|
||||
}
|
||||
|
||||
const postURL = (data) => {
|
||||
|
|
Loading…
Reference in New Issue