From ee4f3715aba4a7b5c2b94561118d075e921e5c1a Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Sun, 8 Dec 2024 01:26:10 -0800 Subject: [PATCH] Add additional data when fetching teams Added TeamWithRoleSchema to extend TeamRoleSchema with team role/TL data. --- availabili.tf/src/client/index.ts | 1 + .../src/client/models/TeamWithRoleSchema.ts | 15 +++ .../src/client/models/ViewTeamsResponse.ts | 4 +- .../src/components/TeamsListSidebar.vue | 94 ++++++++++++++++--- availabili.tf/src/main.ts | 1 - availabili.tf/src/stores/teams.ts | 15 ++- backend-flask/models/team.py | 18 ++++ 7 files changed, 128 insertions(+), 20 deletions(-) create mode 100644 availabili.tf/src/client/models/TeamWithRoleSchema.ts diff --git a/availabili.tf/src/client/index.ts b/availabili.tf/src/client/index.ts index 49bd56f..53f0cf1 100644 --- a/availabili.tf/src/client/index.ts +++ b/availabili.tf/src/client/index.ts @@ -34,6 +34,7 @@ export type { TeamInviteSchemaList } from './models/TeamInviteSchemaList'; export type { TeamLogsTfIntegrationSchema } from './models/TeamLogsTfIntegrationSchema'; export { TeamRole } from './models/TeamRole'; export type { TeamSchema } from './models/TeamSchema'; +export type { TeamWithRoleSchema } from './models/TeamWithRoleSchema'; export type { UpdateEventJson } from './models/UpdateEventJson'; export type { ValidationError } from './models/ValidationError'; export type { ValidationErrorElement } from './models/ValidationErrorElement'; diff --git a/availabili.tf/src/client/models/TeamWithRoleSchema.ts b/availabili.tf/src/client/models/TeamWithRoleSchema.ts new file mode 100644 index 0000000..1e90489 --- /dev/null +++ b/availabili.tf/src/client/models/TeamWithRoleSchema.ts @@ -0,0 +1,15 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type TeamWithRoleSchema = { + createdAt: string; + id: number; + isTeamLeader: boolean; + minuteOffset: number; + playerCount: number; + role: string; + teamName: string; + tzTimezone: string; +}; + diff --git a/availabili.tf/src/client/models/ViewTeamsResponse.ts b/availabili.tf/src/client/models/ViewTeamsResponse.ts index 2977326..a250f79 100644 --- a/availabili.tf/src/client/models/ViewTeamsResponse.ts +++ b/availabili.tf/src/client/models/ViewTeamsResponse.ts @@ -2,8 +2,8 @@ /* istanbul ignore file */ /* tslint:disable */ /* eslint-disable */ -import type { TeamSchema } from './TeamSchema'; +import type { TeamWithRoleSchema } from './TeamWithRoleSchema'; export type ViewTeamsResponse = { - teams: Array; + teams: Array; }; diff --git a/availabili.tf/src/components/TeamsListSidebar.vue b/availabili.tf/src/components/TeamsListSidebar.vue index 934c663..b9a5f35 100644 --- a/availabili.tf/src/components/TeamsListSidebar.vue +++ b/availabili.tf/src/components/TeamsListSidebar.vue @@ -11,27 +11,54 @@ onMounted(() => { diff --git a/availabili.tf/src/main.ts b/availabili.tf/src/main.ts index 6ab1669..65126ef 100644 --- a/availabili.tf/src/main.ts +++ b/availabili.tf/src/main.ts @@ -6,7 +6,6 @@ import { createPinia } from "pinia"; import VueSelect from "vue-select"; import { TooltipDirective } from "vue3-tooltip"; import "vue3-tooltip/tooltip.css"; -import "vue-virtual-scroller/dist/vue-virtual-scroller.css"; import App from "./App.vue"; import router from "./router"; diff --git a/availabili.tf/src/stores/teams.ts b/availabili.tf/src/stores/teams.ts index b434c26..ab7eca7 100644 --- a/availabili.tf/src/stores/teams.ts +++ b/availabili.tf/src/stores/teams.ts @@ -2,7 +2,7 @@ import { defineStore } from "pinia"; import { reactive, type Reactive } from "vue"; import { useClientStore } from "./client"; import { useAuthStore } from "./auth"; -import { type TeamSchema, type RoleSchema, type ViewTeamMembersResponse, type CreateTeamJson } from "@/client"; +import { type TeamSchema, type RoleSchema, type ViewTeamMembersResponse, type CreateTeamJson, type TeamWithRoleSchema } from "@/client"; export type TeamMap = { [id: number]: TeamSchema }; @@ -11,8 +11,14 @@ export const useTeamsStore = defineStore("teams", () => { const clientStore = useClientStore(); const client = clientStore.client; - const teams: Reactive<{ [id: number]: TeamSchema }> = reactive({}); - const teamMembers: Reactive<{ [id: number]: ViewTeamMembersResponse[] }> = reactive({}); + const teams = reactive<{ [id: number]: TeamSchema }>({}); + const teamsWithRole = reactive<{ [id: number]: TeamWithRoleSchema }>({}); + const teamMembers = reactive<{ [id: number]: ViewTeamMembersResponse[] }>({}); + + const roleNames: { [key: string]: string } = { + "Player": "Player", + "CoachMentor": "Coach/Mentor", + }; async function fetchTeams() { const response = await clientStore.call( @@ -21,6 +27,7 @@ export const useTeamsStore = defineStore("teams", () => { ); response.teams.forEach((team) => { teams[team.id] = team; + teamsWithRole[team.id] = team; }); return response; } @@ -70,6 +77,8 @@ export const useTeamsStore = defineStore("teams", () => { return { teams, + teamsWithRole, + roleNames, teamMembers, fetchTeams, fetchTeam, diff --git a/backend-flask/models/team.py b/backend-flask/models/team.py index 6cf5042..73fbd9c 100644 --- a/backend-flask/models/team.py +++ b/backend-flask/models/team.py @@ -102,6 +102,24 @@ class TeamSchema(spec.BaseModel): created_at=team.created_at, ) +class TeamWithRoleSchema(TeamSchema): + role: str + is_team_leader: bool + player_count: int + + @classmethod + def from_player_team(cls, player_team: "PlayerTeam"): + return cls( + id=player_team.team.id, + team_name=player_team.team.team_name, + tz_timezone=player_team.team.tz_timezone, + minute_offset=player_team.team.minute_offset, + created_at=player_team.team.created_at, + role=player_team.team_role.name, + is_team_leader=player_team.is_team_leader, + player_count=len(player_team.team.players), + ) + from models.player_team import PlayerTeam from models.team_invite import TeamInvite from models.team_integration import (