fix types and api calls
This commit is contained in:
@@ -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];
|
||||
|
||||
|
@@ -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<PlanetInfo> => {
|
||||
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<PlanetInfoUniverse> => {
|
||||
const api = new Api();
|
||||
const planetInfo = (
|
||||
await api.universe.getUniversePlanetsPlanetId(planet.planet_id)
|
||||
await api.v1.getUniversePlanetsPlanetId(planet.planet_id)
|
||||
).data;
|
||||
return planetInfo;
|
||||
};
|
||||
|
@@ -16,7 +16,7 @@ const StackItem = styled(Stack)(({ theme }) => ({
|
||||
const getPlanets = async (character: AccessToken): Promise<Planet[]> => {
|
||||
const api = new Api();
|
||||
const planets = (
|
||||
await api.characters.getCharactersCharacterIdPlanets(
|
||||
await api.v1.getCharactersCharacterIdPlanets(
|
||||
character.character.characterId,
|
||||
{
|
||||
token: character.access_token,
|
||||
|
47
src/types.ts
47
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 unknown[]> =
|
||||
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<typeof Api<unknown>>;
|
||||
type EsiApiPathType<V extends EsiApiVersionType> = keyof InstanceType<
|
||||
typeof Api<unknown>
|
||||
>[V];
|
||||
type EsiApiResponseType<
|
||||
V extends EsiApiVersionType,
|
||||
T extends EsiApiPathType<V>
|
||||
> = Awaited<ReturnType<InstanceType<typeof Api<unknown>>[V][T]>>;
|
||||
export type EsiType<
|
||||
V extends EsiApiVersionType,
|
||||
T extends EsiApiPathType<V>
|
||||
> = EsiApiResponseType<V, T> extends { data: any }
|
||||
? EsiApiResponseType<V, T>["data"]
|
||||
: never;
|
||||
|
Reference in New Issue
Block a user