diff --git a/.gitignore b/.gitignore index df708e2..cefc70d 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ dist-ssr *.sw? .env /certs/* +/vite.config.d.ts +/vite.config.js diff --git a/Dockerfile b/Dockerfile index 4a2cd8d..67cf067 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,8 @@ ARG build_cmd="build" FROM node:lts-alpine as build ARG build_cmd +ENV VITE_API_URL=https://api.vatusa.dev + WORKDIR /app COPY package*.json ./ COPY . . diff --git a/src/App.vue b/src/App.vue index 2d17720..a314aa5 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,20 +1,29 @@ diff --git a/src/components/animations/FadeOut.vue b/src/components/animations/FadeOut.vue new file mode 100644 index 0000000..4aee051 --- /dev/null +++ b/src/components/animations/FadeOut.vue @@ -0,0 +1,19 @@ + + + + + diff --git a/src/components/animations/Loader.vue b/src/components/animations/Loader.vue new file mode 100644 index 0000000..9b4cc4b --- /dev/null +++ b/src/components/animations/Loader.vue @@ -0,0 +1,24 @@ + + + + + diff --git a/src/components/animations/Spinner.vue b/src/components/animations/Spinner.vue new file mode 100644 index 0000000..b2204ef --- /dev/null +++ b/src/components/animations/Spinner.vue @@ -0,0 +1,26 @@ + + + + + diff --git a/src/components/profile/Profile.vue b/src/components/profile/Profile.vue index 7a6c2a7..60f01db 100644 --- a/src/components/profile/Profile.vue +++ b/src/components/profile/Profile.vue @@ -70,7 +70,7 @@

Facility Details

-
+
Facility
Type
@@ -78,7 +78,7 @@
Exit Date
import { ref } from "vue"; -import { User, Roster } from "@/types"; +import { User } from "@/types"; const props = defineProps<{ user: User | null; - rosters: Roster[] | null; }>(); const editableUser = ref(props.user); diff --git a/src/data/facilities.ts b/src/data/facilities.ts deleted file mode 100644 index f88d224..0000000 --- a/src/data/facilities.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { Facility } from "@/types"; - -const Facilities: Facility[] = [ - { - id: "ZAB", - name: "Albuquerque ARTCC", - }, - { - id: "ZDV", - name: "Denver ARTCC", - }, - { - id: "ZLC", - name: "Salt Lake ARTCC", - }, -]; - -export default Facilities; diff --git a/src/stores/facility.ts b/src/stores/facility.ts new file mode 100644 index 0000000..71a63e9 --- /dev/null +++ b/src/stores/facility.ts @@ -0,0 +1,44 @@ +import { defineStore } from "pinia"; +import { API } from "@/utils/api"; +import { Facility } from "@/types"; + +interface FacilityState { + facilities: Facility[] | null; + error: string | null; + fetching: boolean; + hasFetched: boolean; + loading: Promise | null; +} + +const useFacilityStore = defineStore({ + id: "facility", + state: () => + ({ + facilities: null, + error: null, + fetching: false, + hasFetched: false, + }) as FacilityState, + getters: { + getFacility: (state) => (id: string) => { + if (!state.facilities) return null; + return state.facilities.find((facility) => facility.id === id) || null; + }, + }, + actions: { + async fetchFacilities(): Promise { + this.fetching = true; + try { + const { data } = await API.get("/v3/facility"); + this.facilities = data; + } catch (e) { + this.facilities = []; + } finally { + this.fetching = false; + this.hasFetched = true; + } + }, + }, +}); + +export default useFacilityStore; diff --git a/src/stores/user.ts b/src/stores/user.ts index fe3a184..92d7491 100644 --- a/src/stores/user.ts +++ b/src/stores/user.ts @@ -8,16 +8,19 @@ interface UserState { error: string | null; fetching: boolean; hasFetched: boolean; + hasFetchedRosters: boolean; loading: Promise | null; } -const useUserStore = defineStore("user", { +const useUserStore = defineStore({ + id: "user", state: () => ({ user: null, error: null, fetching: false, hasFetched: false, + hasFetchedRosters: false, }) as UserState, getters: { isLoggedIn: (state) => !!state.user, @@ -27,7 +30,7 @@ const useUserStore = defineStore("user", { }, }, actions: { - async fetchUser() { + async fetchUser(): Promise { this.fetching = true; try { const { data } = await API.get("/v3/user"); @@ -45,6 +48,32 @@ const useUserStore = defineStore("user", { this.hasFetched = true; } }, + async fetchRosters(): Promise { + if (!this.isLoggedIn) return; + try { + const { data } = await API.get(`/v3/user/${this.user?.cid}/roster`); + this.user!.rosters = data; + } catch (e) { + this.user!.rosters = []; + } finally { + this.hasFetchedRosters = true; + } + }, + async logout(): Promise { + this.fetching = true; + try { + await API.get("/v3/user/logout"); + this.user = null; + this.hasFetched = false; + this.hasFetchedRosters = false; + window.location.href = "https://vatusa.net"; + } catch (e) { + // TODO - throw error notification + console.log(e); + } finally { + this.fetching = false; + } + }, }, }); diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 3061158..b5667f1 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -49,11 +49,20 @@ export interface Roster { home: boolean; visiting: boolean; status: string; + roles: Role[]; created_at: string; deleted_at?: string; } +export interface Role { + role: string; + facility_id: string; + roster_id: number; + created_at: string; +} + export interface Facility { id: string; name: string; + url: string; } diff --git a/src/utils/facility.ts b/src/utils/facility.ts deleted file mode 100644 index 4777d1e..0000000 --- a/src/utils/facility.ts +++ /dev/null @@ -1,8 +0,0 @@ -import Facilities from "@/data/facilities"; -import type { Facility } from "@/types"; - -const getFacility = (id: string): Facility | undefined => { - return Facilities.find((facility) => facility.id === id); -}; - -export default getFacility; diff --git a/src/views/Facility.vue b/src/views/Facility.vue index ba85f46..7d2e317 100644 --- a/src/views/Facility.vue +++ b/src/views/Facility.vue @@ -4,16 +4,27 @@

Facilities you've joined

-
-

You haven't joined any facilities yet.

+
+ +
+
+

You haven't joined any facilities yet.

-
+
{{ roster.facility }} (LOA) - - {{ getFacility(roster.facility)?.name }} + - {{ facilityStore.getFacility(roster.facility)?.name }} + + +

Home

Visiting

@@ -24,7 +35,10 @@
Roles:
-

TA, AWM

+
+ No roles + {{ role.role }} +
Actions:
@@ -48,47 +62,26 @@ diff --git a/src/views/Profile.vue b/src/views/Profile.vue index bd5c595..8f0ec08 100644 --- a/src/views/Profile.vue +++ b/src/views/Profile.vue @@ -69,8 +69,8 @@ watch(currentHashTab, (newTab) => { // Initial check on component mount onMounted(() => { - console.log(currentHashTab.value); selectedTab.value = currentHashTab.value; + userStore.fetchRosters(); }); diff --git a/src/views/partials/Header.vue b/src/views/partials/Header.vue index c8f852f..17167bf 100644 --- a/src/views/partials/Header.vue +++ b/src/views/partials/Header.vue @@ -66,7 +66,7 @@

Help Center

- +

Sign Out