From 95acaa25ddabd60b06e4a2686140b43b23940aae Mon Sep 17 00:00:00 2001 From: Zack Spear Date: Wed, 31 May 2023 14:13:11 -0700 Subject: [PATCH] refactor: server state and types --- store/server.ts | 45 +++++++++++++++++++++++++++++++++++---------- types/server.ts | 15 +++++++++++++-- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/store/server.ts b/store/server.ts index fbfff4f2f..e3b4f75eb 100644 --- a/store/server.ts +++ b/store/server.ts @@ -1,4 +1,6 @@ import { defineStore, createPinia, setActivePinia } from "pinia"; +import { ArrowRightOnRectangleIcon, GlobeAltIcon, KeyIcon } from '@heroicons/vue/24/solid'; + import type { Server, ServerState, ServerStateData } from '~/types/server'; /** * @see https://stackoverflow.com/questions/73476371/using-pinia-with-vue-js-web-components @@ -10,15 +12,16 @@ export const useServerStore = defineStore('server', () => { /** * State */ - const description = ref(); - const deviceCount = ref(); - const guid = ref(); - const locale = ref(); - const name = ref(); - const site = ref(); - const state = ref(); // @todo implement ServerState ENUM - const uptime = ref(); - const expireTime = ref(); + const description = ref(); + const deviceCount = ref(); + const guid = ref(); + const locale = ref(); + const lanIp = ref(); + const name = ref(); + const site = ref(); + const state = ref(); // @todo implement ServerState ENUM + const uptime = ref(); + const expireTime = ref(); /** * Getters @@ -34,11 +37,31 @@ export const useServerStore = defineStore('server', () => { state: state.value, uptime: uptime.value, expireTime: expireTime.value, + lanIp: lanIp.value, } }); const stateDataDefault: ServerStateData = { - actions: ['purchase', 'signIn', 'signOut'], + actions: [ + { + click: () => { console.debug('signIn') }, + icon: GlobeAltIcon, + name: 'signIn', + text: 'Sign In with Unraid.net Account', + }, + { + click: () => { console.debug('purchase') }, + icon: KeyIcon, + name: 'purchase', + text: 'Purchase Key', + }, + // { + // click: () => { console.debug('signOut') }, + // icon: ArrowRightOnRectangleIcon, + // name: 'signOut', + // text: 'signOut', + // }, + ], humanReadable: 'Trial', heading: 'Thank you for choosing Unraid OS!', message: '[Temp] Your Trial Key includes all the features of a Pro Key', @@ -154,6 +177,7 @@ export const useServerStore = defineStore('server', () => { state.value = data?.state; uptime.value = data?.uptime; expireTime.value = data?.expireTime; + lanIp.value = data?.lanIp; }; return { @@ -162,6 +186,7 @@ export const useServerStore = defineStore('server', () => { description, guid, locale, + lanIp, deviceCount, site, uptime, diff --git a/types/server.ts b/types/server.ts index c79bdbf89..701cb8101 100644 --- a/types/server.ts +++ b/types/server.ts @@ -1,3 +1,5 @@ +import { KeyIcon } from '@heroicons/vue/24/solid'; + export enum ServerState { BASIC = 'BASIC', PLUS = 'PLUS', @@ -34,9 +36,18 @@ export interface Server { locale?: string; uptime?: number; expireTime?: number; + lanIp?: string; } -export type ServerStateDataActions = 'redeem'|'purchase'|'upgrade'|'signOut'|'signIn'|'trialExtend'|'trialStart'|'replace'|'recover'; +// @todo convert to object with text and click payload +export type ServerStateDataActionType = 'redeem'|'purchase'|'upgrade'|'signOut'|'signIn'|'trialExtend'|'trialStart'|'replace'|'recover'; + +export interface ServerStateDataAction { + click: any; // @todo be more specific + icon?: typeof KeyIcon + name: ServerStateDataActionType; + text: string; +} export interface ServerStateDataError { heading: string; @@ -45,7 +56,7 @@ export interface ServerStateDataError { } export interface ServerStateData { - actions: ServerStateDataActions[]; + actions: ServerStateDataAction[]; humanReadable: string; // @todo create interface of ENUM to string mapping heading: string; message: string;