diff --git a/src/app/components/PlanetaryInteraction/PinsCanvas3D.tsx b/src/app/components/PlanetaryInteraction/PinsCanvas3D.tsx index 36d0ff4..5ab86d6 100644 --- a/src/app/components/PlanetaryInteraction/PinsCanvas3D.tsx +++ b/src/app/components/PlanetaryInteraction/PinsCanvas3D.tsx @@ -1,8 +1,8 @@ import { useEffect, useRef } from "react"; -import { PlanetInfo } from "./PlanetCard"; import * as THREE from "three"; import * as BufferGeometryUtils from "three/examples/jsm/utils/BufferGeometryUtils.js"; import { OrbitControls } from "three/examples/jsm/controls/OrbitControls"; +import { PlanetInfo } from "@/types"; const commandCenterIds = [2254, 2524, 2525, 2533, 2534, 2549, 2550, 2551]; diff --git a/src/app/components/PlanetaryInteraction/PlanetCard.tsx b/src/app/components/PlanetaryInteraction/PlanetCard.tsx index c57c244..0453908 100644 --- a/src/app/components/PlanetaryInteraction/PlanetCard.tsx +++ b/src/app/components/PlanetaryInteraction/PlanetCard.tsx @@ -1,8 +1,8 @@ import { Stack, Typography, styled, useTheme } from "@mui/material"; import Image from "next/image"; -import { AccessToken, Planet } from "@/types"; +import { AccessToken, Planet, PlanetInfo, PlanetInfoUniverse } from "@/types"; import { Api } from "@/esi-api"; -import { forwardRef, useContext, useEffect, useState } from "react"; +import { forwardRef, useEffect, useState } from "react"; import { DateTime } from "luxon"; import { EXTRACTOR_TYPE_IDS } from "@/const"; import Countdown from "react-countdown"; @@ -25,64 +25,6 @@ const StackItem = styled(Stack)(({ theme }) => ({ alignItems: "center", })); -export interface Pin { - contents?: { - amount: number; - type_id: number; - }[]; - expiry_time?: string; - extractor_details?: { - cycle_time?: number; - head_radius?: number; - heads: { - head_id: number; - latitude: number; - longitude: number; - }[]; - product_type_id?: number; - qty_per_cycle?: number; - }; - factory_details?: { - schematic_id: number; - }; - install_time?: string; - last_cycle_start?: string; - latitude: number; - longitude: number; - pin_id: number; - schematic_id?: number; - type_id: number; -} - -export interface PlanetInfo { - links: { - destination_pin_id: number; - link_level: number; - source_pin_id: number; - }[]; - pins: Pin[]; - routes: { - content_type_id: number; - destination_pin_id: number; - quantity: number; - route_id: number; - source_pin_id: number; - waypoints?: number[]; - }[]; -} - -export interface PlanetInfoUniverse { - name: string; - planet_id: number; - position: { - x: number; - y: number; - z: number; - }; - system_id: number; - type_id: number; -} - const Transition = forwardRef(function Transition( props: TransitionProps & { children: React.ReactElement; @@ -131,7 +73,7 @@ export const PlanetCard = ({ ): Promise => { const api = new Api(); const planetInfo = ( - await api.characters.getCharactersCharacterIdPlanetsPlanetId( + await api.v3.getCharactersCharacterIdPlanetsPlanetId( character.character.characterId, planet.planet_id, { @@ -147,7 +89,7 @@ export const PlanetCard = ({ ): Promise => { const api = new Api(); const planetInfo = ( - await api.universe.getUniversePlanetsPlanetId(planet.planet_id) + await api.v1.getUniversePlanetsPlanetId(planet.planet_id) ).data; return planetInfo; }; diff --git a/src/app/components/PlanetaryInteraction/PlanetaryInteractionRow.tsx b/src/app/components/PlanetaryInteraction/PlanetaryInteractionRow.tsx index 4798cd6..99f5c66 100644 --- a/src/app/components/PlanetaryInteraction/PlanetaryInteractionRow.tsx +++ b/src/app/components/PlanetaryInteraction/PlanetaryInteractionRow.tsx @@ -16,7 +16,7 @@ const StackItem = styled(Stack)(({ theme }) => ({ const getPlanets = async (character: AccessToken): Promise => { const api = new Api(); const planets = ( - await api.characters.getCharactersCharacterIdPlanets( + await api.v1.getCharactersCharacterIdPlanets( character.character.characterId, { token: character.access_token, diff --git a/src/types.ts b/src/types.ts index 90bb348..3264a4f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,3 +1,5 @@ +import { Api } from "./esi-api"; + export interface AccessToken { access_token: string; expires_at: number; @@ -17,25 +19,36 @@ export interface CharacterUpdate { account?: string; } -export interface Planet { - last_update: string; - num_pins: number; - owner_id: number; - planet_id: number; - planet_type: - | "temperate" - | "barren" - | "oceanic" - | "ice" - | "gas" - | "lava" - | "storm" - | "plasma"; - solar_system_id: number; - upgrade_level: number; -} +type ArrayElement = + ArrayType extends readonly (infer ElementType)[] ? ElementType : never; + +export type Planet = ArrayElement< + EsiType<"v1", "getCharactersCharacterIdPlanets"> +>; + +export type PlanetInfoUniverse = EsiType<"v1", "getUniversePlanetsPlanetId">; + +export type PlanetInfo = EsiType< + "v3", + "getCharactersCharacterIdPlanetsPlanetId" +>; export interface Env { EVE_SSO_CALLBACK_URL: string; EVE_SSO_CLIENT_ID: string; } + +type EsiApiVersionType = keyof InstanceType>; +type EsiApiPathType = keyof InstanceType< + typeof Api +>[V]; +type EsiApiResponseType< + V extends EsiApiVersionType, + T extends EsiApiPathType +> = Awaited>[V][T]>>; +export type EsiType< + V extends EsiApiVersionType, + T extends EsiApiPathType +> = EsiApiResponseType extends { data: any } + ? EsiApiResponseType["data"] + : never;