Getting lvgmc csv files in frontend
This commit is contained in:
+3
-1
@@ -9,12 +9,13 @@ import { Station } from './station/Station';
|
||||
import { apiHost } from './consts';
|
||||
import { WeatherIconStub } from './components/weatherIcons/WeatherIconStub';
|
||||
import { Harmonie } from './harmonie/Harmonie'
|
||||
import { LvgmcForecast } from './lvgmc-forecast/LvgmcForecast'
|
||||
|
||||
console.log("env:", import.meta.env.MODE)
|
||||
console.log("api host:", apiHost)
|
||||
|
||||
const App: Component = () => {
|
||||
const pages = ['station', 'cities', 'latvia', 'database', 'harmonie']
|
||||
const pages = ['station', 'cities', 'latvia', 'database', 'harmonie', 'lvgmc-forecast']
|
||||
return (
|
||||
<div>
|
||||
<div class="grid-1-1">
|
||||
@@ -32,6 +33,7 @@ const App: Component = () => {
|
||||
<Router>
|
||||
<Route path="/" component={Harmonie} />
|
||||
<Route path="/harmonie" component={Harmonie} />
|
||||
<Route path="/lvgmc-forecast" component={LvgmcForecast} />
|
||||
<Route path="/station" component={Station} />
|
||||
<Route path="/cities" component={Cities} />
|
||||
<Route path="/latvia" component={Country} />
|
||||
|
||||
@@ -25,6 +25,32 @@ export const fetchJson = (url: string, options = {}) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchText = (url: string, options = {}) => {
|
||||
return fetch(url, options).then(async response => {
|
||||
let responseCode = ''
|
||||
if (!response.ok) {
|
||||
responseCode = `error ${response.status}`
|
||||
}
|
||||
|
||||
let text = ''
|
||||
let responseMessage = ''
|
||||
try {
|
||||
text = await response.text()
|
||||
} catch (err) {
|
||||
responseMessage = 'Invalid TEXT response'
|
||||
}
|
||||
|
||||
if (responseCode) {
|
||||
if (responseMessage) throw new Error(`${responseCode}: ${responseMessage}`)
|
||||
else throw new Error(responseCode)
|
||||
} else if (responseMessage) {
|
||||
throw new Error(responseMessage)
|
||||
}
|
||||
|
||||
return text
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export const fetchBuffer = (url: string, options = {}) => {
|
||||
return fetch(url, options).then(async response => {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Component } from 'solid-js'
|
||||
import { apiHost } from '../consts'
|
||||
import { fetchText } from '../helpers/fetch'
|
||||
|
||||
// Eiropa_LTV_pilsetas_nakama_dn.csv
|
||||
// Eiropa_LTV_pilsetas_tekosa_dn.csv
|
||||
// Latvija_LTV_pilsetas_nakama_dnn.csv
|
||||
// Latvija_LTV_pilsetas_tekosa_dn.csv
|
||||
// Latvija_faktiskais_laiks.csv
|
||||
|
||||
export const LvgmcForecast: Component<{}> = () => {
|
||||
fetchText(`${apiHost}/api/show/lvgmc-forecast/Latvija_LTV_pilsetas_tekosa_dn.csv`)
|
||||
.then(console.log)
|
||||
|
||||
return <>
|
||||
LvgmcForecast
|
||||
</>
|
||||
}
|
||||
Reference in New Issue
Block a user