Switch new display to Vue

This commit is contained in:
2024-03-04 01:18:45 +00:00
parent a8e60c2e87
commit 4aaa9064fb
62 changed files with 2863 additions and 1569 deletions

View File

@@ -0,0 +1,68 @@
import { defineStore } from 'pinia';
import { HubConnection, HubConnectionBuilder } from '@microsoft/signalr';
import axios from 'axios';
import Environment from '@/environment';
import WeatherUpdate from '@/models/weather/weather-update';
import WeatherRecent from '@/models/weather/weather-recent';
import WeatherValueType from '@/models/weather/weather-value-type';
import WeatherValueGrouped from '@/models/weather/weather-value-grouped';
export const useWeatherStore = defineStore('weather', {
state: () => {
return {
current: null as WeatherUpdate | null,
_connection: null as HubConnection | null
};
},
actions: {
async start() {
if (this._connection) {
return;
}
this._connection = new HubConnectionBuilder()
.withUrl(Environment.getUrlPrefix() + '/api/hub/weather', {
withCredentials: false
})
.build();
await this._connection.start();
this._connection.on('LatestReading', (message: string) => {
this.$patch({ current: JSON.parse(message) });
});
},
async stop() {
if (!this._connection) {
return;
}
await this._connection.stop();
this._connection = null;
},
async getLatest(): Promise<WeatherRecent> {
const response = await axios.get<WeatherRecent>(
Environment.getUrlPrefix() + `/api/weather/readings/recent`
);
return response.data;
},
async getReadingValueHistoryGrouped(
valueType: WeatherValueType,
start: Date,
end: Date,
bucketMinutes: number
): Promise<WeatherValueGrouped[]> {
const startString = start.toISOString();
const endString = end.toISOString();
const response = await axios.get<WeatherValueGrouped[]>(
Environment.getUrlPrefix() +
`/api/weather/readings/value-history-grouped?weatherValueType=${valueType}&start=${startString}&end=${endString}&bucketMinutes=${bucketMinutes}`
);
return response.data;
}
}
});