Initial setup for new frontend.
This commit is contained in:
parent
7671bfd4d3
commit
59f7897d8e
33 changed files with 2594 additions and 12 deletions
frontend/src/stores
38
frontend/src/stores/version.ts
Normal file
38
frontend/src/stores/version.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { isObject, isVersion, type Version } from "@/types";
|
||||
import { api } from "@/utils/Api";
|
||||
|
||||
interface VersionResponse {
|
||||
version: Version;
|
||||
}
|
||||
|
||||
function isVersionResponse(arg: unknown): arg is VersionResponse {
|
||||
return isObject(arg) && isVersion((arg as VersionResponse).version);
|
||||
}
|
||||
|
||||
interface VersionStoreState {
|
||||
version: Version | null;
|
||||
}
|
||||
|
||||
export const useVersionStore = defineStore({
|
||||
id: "version",
|
||||
state(): VersionStoreState {
|
||||
return {
|
||||
version: null,
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
getVersion(state: VersionStoreState): Version | null {
|
||||
return state.version;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async refresh(): Promise<void> {
|
||||
const response = await api.get<VersionResponse>(
|
||||
"version",
|
||||
isVersionResponse
|
||||
);
|
||||
this.version = response.version;
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue