fix types and api calls
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { PlanetInfo } from "./PlanetCard";
|
|
||||||
import * as THREE from "three";
|
import * as THREE from "three";
|
||||||
import * as BufferGeometryUtils from "three/examples/jsm/utils/BufferGeometryUtils.js";
|
import * as BufferGeometryUtils from "three/examples/jsm/utils/BufferGeometryUtils.js";
|
||||||
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
|
||||||
|
import { PlanetInfo } from "@/types";
|
||||||
|
|
||||||
const commandCenterIds = [2254, 2524, 2525, 2533, 2534, 2549, 2550, 2551];
|
const commandCenterIds = [2254, 2524, 2525, 2533, 2534, 2549, 2550, 2551];
|
||||||
|
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import { Stack, Typography, styled, useTheme } from "@mui/material";
|
import { Stack, Typography, styled, useTheme } from "@mui/material";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { AccessToken, Planet } from "@/types";
|
import { AccessToken, Planet, PlanetInfo, PlanetInfoUniverse } from "@/types";
|
||||||
import { Api } from "@/esi-api";
|
import { Api } from "@/esi-api";
|
||||||
import { forwardRef, useContext, useEffect, useState } from "react";
|
import { forwardRef, useEffect, useState } from "react";
|
||||||
import { DateTime } from "luxon";
|
import { DateTime } from "luxon";
|
||||||
import { EXTRACTOR_TYPE_IDS } from "@/const";
|
import { EXTRACTOR_TYPE_IDS } from "@/const";
|
||||||
import Countdown from "react-countdown";
|
import Countdown from "react-countdown";
|
||||||
@@ -25,64 +25,6 @@ const StackItem = styled(Stack)(({ theme }) => ({
|
|||||||
alignItems: "center",
|
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(
|
const Transition = forwardRef(function Transition(
|
||||||
props: TransitionProps & {
|
props: TransitionProps & {
|
||||||
children: React.ReactElement;
|
children: React.ReactElement;
|
||||||
@@ -131,7 +73,7 @@ export const PlanetCard = ({
|
|||||||
): Promise<PlanetInfo> => {
|
): Promise<PlanetInfo> => {
|
||||||
const api = new Api();
|
const api = new Api();
|
||||||
const planetInfo = (
|
const planetInfo = (
|
||||||
await api.characters.getCharactersCharacterIdPlanetsPlanetId(
|
await api.v3.getCharactersCharacterIdPlanetsPlanetId(
|
||||||
character.character.characterId,
|
character.character.characterId,
|
||||||
planet.planet_id,
|
planet.planet_id,
|
||||||
{
|
{
|
||||||
@@ -147,7 +89,7 @@ export const PlanetCard = ({
|
|||||||
): Promise<PlanetInfoUniverse> => {
|
): Promise<PlanetInfoUniverse> => {
|
||||||
const api = new Api();
|
const api = new Api();
|
||||||
const planetInfo = (
|
const planetInfo = (
|
||||||
await api.universe.getUniversePlanetsPlanetId(planet.planet_id)
|
await api.v1.getUniversePlanetsPlanetId(planet.planet_id)
|
||||||
).data;
|
).data;
|
||||||
return planetInfo;
|
return planetInfo;
|
||||||
};
|
};
|
||||||
|
@@ -16,7 +16,7 @@ const StackItem = styled(Stack)(({ theme }) => ({
|
|||||||
const getPlanets = async (character: AccessToken): Promise<Planet[]> => {
|
const getPlanets = async (character: AccessToken): Promise<Planet[]> => {
|
||||||
const api = new Api();
|
const api = new Api();
|
||||||
const planets = (
|
const planets = (
|
||||||
await api.characters.getCharactersCharacterIdPlanets(
|
await api.v1.getCharactersCharacterIdPlanets(
|
||||||
character.character.characterId,
|
character.character.characterId,
|
||||||
{
|
{
|
||||||
token: character.access_token,
|
token: character.access_token,
|
||||||
|
47
src/types.ts
47
src/types.ts
@@ -1,3 +1,5 @@
|
|||||||
|
import { Api } from "./esi-api";
|
||||||
|
|
||||||
export interface AccessToken {
|
export interface AccessToken {
|
||||||
access_token: string;
|
access_token: string;
|
||||||
expires_at: number;
|
expires_at: number;
|
||||||
@@ -17,25 +19,36 @@ export interface CharacterUpdate {
|
|||||||
account?: string;
|
account?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Planet {
|
type ArrayElement<ArrayType extends readonly unknown[]> =
|
||||||
last_update: string;
|
ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
|
||||||
num_pins: number;
|
|
||||||
owner_id: number;
|
export type Planet = ArrayElement<
|
||||||
planet_id: number;
|
EsiType<"v1", "getCharactersCharacterIdPlanets">
|
||||||
planet_type:
|
>;
|
||||||
| "temperate"
|
|
||||||
| "barren"
|
export type PlanetInfoUniverse = EsiType<"v1", "getUniversePlanetsPlanetId">;
|
||||||
| "oceanic"
|
|
||||||
| "ice"
|
export type PlanetInfo = EsiType<
|
||||||
| "gas"
|
"v3",
|
||||||
| "lava"
|
"getCharactersCharacterIdPlanetsPlanetId"
|
||||||
| "storm"
|
>;
|
||||||
| "plasma";
|
|
||||||
solar_system_id: number;
|
|
||||||
upgrade_level: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Env {
|
export interface Env {
|
||||||
EVE_SSO_CALLBACK_URL: string;
|
EVE_SSO_CALLBACK_URL: string;
|
||||||
EVE_SSO_CLIENT_ID: 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