feat(#41): Resolve corporation names in CorporationLabel
This commit is contained in:
@@ -4,7 +4,7 @@ import {computed} from "vue";
|
||||
import {computedAsync} from "@vueuse/core";
|
||||
import {ActivitySourceResponse, ActivitySourceResponseTypeEnum} from "@/generated/mammon";
|
||||
import {CharacterLabel, useCharactersStore} from "@/characters";
|
||||
import {CorporationLabel} from "@/corporations";
|
||||
import {CorporationLabel, useCorporationsStore} from "@/corporations";
|
||||
import {LedgerLabel, useLedgersStore} from "@/ledger";
|
||||
|
||||
interface Props {
|
||||
@@ -17,6 +17,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
});
|
||||
|
||||
const charactersStore = useCharactersStore();
|
||||
const corporationsStore = useCorporationsStore();
|
||||
const ledgersStore = useLedgersStore();
|
||||
|
||||
const character = computedAsync(async () => {
|
||||
@@ -26,6 +27,13 @@ const character = computedAsync(async () => {
|
||||
return undefined;
|
||||
}, undefined);
|
||||
|
||||
const corporation = computedAsync(async () => {
|
||||
if (props.source.type === ActivitySourceResponseTypeEnum.Corporation && props.source.corporationId) {
|
||||
return await corporationsStore.findById(props.source.corporationId);
|
||||
}
|
||||
return undefined;
|
||||
}, undefined);
|
||||
|
||||
const ledger = computed(() =>
|
||||
props.source.type === ActivitySourceResponseTypeEnum.Ledger && props.source.ledgerId
|
||||
? ledgersStore.findById(props.source.ledgerId)
|
||||
@@ -34,6 +42,6 @@ const ledger = computed(() =>
|
||||
|
||||
<template>
|
||||
<CharacterLabel v-if="source.type === ActivitySourceResponseTypeEnum.Character && character" :character="character" :size="size" />
|
||||
<CorporationLabel v-else-if="source.type === ActivitySourceResponseTypeEnum.Corporation && source.corporationId" :corporation-id="source.corporationId" :division="source.division" :size="size" />
|
||||
<CorporationLabel v-else-if="source.type === ActivitySourceResponseTypeEnum.Corporation && source.corporationId" :corporation-id="source.corporationId" :corporation="corporation" :division="source.division" :size="size" />
|
||||
<LedgerLabel v-else-if="ledger" :ledger="ledger" link />
|
||||
</template>
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
import {Corporation} from "./corporations.ts";
|
||||
|
||||
interface Props {
|
||||
corporationId: number;
|
||||
corporation?: Corporation | null;
|
||||
division?: number | null;
|
||||
size?: number;
|
||||
}
|
||||
@@ -14,6 +17,6 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
<template>
|
||||
<div class="flex">
|
||||
<img class="me-2" :src="`https://images.evetech.net/corporations/${corporationId}/logo?size=${size}`" />
|
||||
<span>Corporation<template v-if="division"> · Division {{ division }}</template></span>
|
||||
<span>{{ corporation?.name ?? 'Corporation' }}<template v-if="division"> · Division {{ division }}</template></span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import {corporationApi} from "@/mammon";
|
||||
import {defineStore} from "pinia";
|
||||
import {ref} from "vue";
|
||||
import {CorporationResponse} from "@/generated/mammon";
|
||||
|
||||
export type Corporation = CorporationResponse
|
||||
|
||||
export const useCorporationsStore = defineStore('corporations', () => {
|
||||
const corporations = ref<Record<number, Corporation | null>>({});
|
||||
const inFlight = new Map<number, Promise<Corporation | undefined>>();
|
||||
|
||||
const findById = async (corporationId: number): Promise<Corporation | undefined> => {
|
||||
const cached = corporations.value[corporationId];
|
||||
|
||||
if (cached !== undefined) {
|
||||
return cached ?? undefined;
|
||||
}
|
||||
|
||||
let request = inFlight.get(corporationId);
|
||||
|
||||
if (!request) {
|
||||
request = corporationApi.findCorporation(corporationId)
|
||||
.then(response => {
|
||||
corporations.value[corporationId] = response.data;
|
||||
return response.data;
|
||||
})
|
||||
.catch(() => {
|
||||
corporations.value[corporationId] = null;
|
||||
return undefined;
|
||||
})
|
||||
.finally(() => inFlight.delete(corporationId));
|
||||
inFlight.set(corporationId, request);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
return {corporations, findById};
|
||||
})
|
||||
@@ -1 +1,3 @@
|
||||
export * from './corporations.ts'
|
||||
|
||||
export {default as CorporationLabel} from './CorporationLabel.vue';
|
||||
|
||||
@@ -168,6 +168,27 @@ export interface CombinedLedgerResponse extends LedgerResponse {
|
||||
*/
|
||||
'memberLedgerIds': Array<string>;
|
||||
}
|
||||
/**
|
||||
* An EVE Online corporation.
|
||||
*/
|
||||
export interface CorporationResponse {
|
||||
/**
|
||||
* EVE corporation id.
|
||||
*/
|
||||
'corporationId': number;
|
||||
/**
|
||||
* Corporation name.
|
||||
*/
|
||||
'name': string;
|
||||
/**
|
||||
* Corporation ticker.
|
||||
*/
|
||||
'ticker': string;
|
||||
/**
|
||||
* EVE alliance id, null when the corporation is not in an alliance.
|
||||
*/
|
||||
'allianceId': number;
|
||||
}
|
||||
/**
|
||||
* Request to create a new combined ledger aggregating the given member ledgers.
|
||||
*/
|
||||
@@ -1574,6 +1595,178 @@ export class CharacterApi extends BaseAPI {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* CorporationApi - axios parameter creator
|
||||
*/
|
||||
export const CorporationApiAxiosParamCreator = function (configuration?: Configuration) {
|
||||
return {
|
||||
/**
|
||||
*
|
||||
* @summary Resolve public information (name, ticker, alliance) for a corporation id
|
||||
* @param {number} corporationId Corporation id to resolve, e.g. 98000001
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
findCorporation: async (corporationId: number, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
// verify required parameter 'corporationId' is not null or undefined
|
||||
assertParamExists('findCorporation', 'corporationId', corporationId)
|
||||
const localVarPath = `/corporations/{corporationId}`
|
||||
.replace('{corporationId}', encodeURIComponent(String(corporationId)));
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
localVarHeaderParameter['Accept'] = '*/*';
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Resolve public information for several corporation ids at once, silently omitting ids ESI cannot resolve
|
||||
* @param {Array<number>} ids Corporation ids to resolve, e.g. ids=98000001,98000002
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
findCorporations: async (ids: Array<number>, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
// verify required parameter 'ids' is not null or undefined
|
||||
assertParamExists('findCorporations', 'ids', ids)
|
||||
const localVarPath = `/corporations`;
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
if (ids) {
|
||||
localVarQueryParameter['ids'] = ids;
|
||||
}
|
||||
|
||||
localVarHeaderParameter['Accept'] = '*/*';
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* CorporationApi - functional programming interface
|
||||
*/
|
||||
export const CorporationApiFp = function(configuration?: Configuration) {
|
||||
const localVarAxiosParamCreator = CorporationApiAxiosParamCreator(configuration)
|
||||
return {
|
||||
/**
|
||||
*
|
||||
* @summary Resolve public information (name, ticker, alliance) for a corporation id
|
||||
* @param {number} corporationId Corporation id to resolve, e.g. 98000001
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async findCorporation(corporationId: number, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<CorporationResponse>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.findCorporation(corporationId, options);
|
||||
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
||||
const localVarOperationServerBasePath = operationServerMap['CorporationApi.findCorporation']?.[localVarOperationServerIndex]?.url;
|
||||
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Resolve public information for several corporation ids at once, silently omitting ids ESI cannot resolve
|
||||
* @param {Array<number>} ids Corporation ids to resolve, e.g. ids=98000001,98000002
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async findCorporations(ids: Array<number>, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<CorporationResponse>>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.findCorporations(ids, options);
|
||||
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
|
||||
const localVarOperationServerBasePath = operationServerMap['CorporationApi.findCorporations']?.[localVarOperationServerIndex]?.url;
|
||||
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* CorporationApi - factory interface
|
||||
*/
|
||||
export const CorporationApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
|
||||
const localVarFp = CorporationApiFp(configuration)
|
||||
return {
|
||||
/**
|
||||
*
|
||||
* @summary Resolve public information (name, ticker, alliance) for a corporation id
|
||||
* @param {number} corporationId Corporation id to resolve, e.g. 98000001
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
findCorporation(corporationId: number, options?: RawAxiosRequestConfig): AxiosPromise<CorporationResponse> {
|
||||
return localVarFp.findCorporation(corporationId, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Resolve public information for several corporation ids at once, silently omitting ids ESI cannot resolve
|
||||
* @param {Array<number>} ids Corporation ids to resolve, e.g. ids=98000001,98000002
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
findCorporations(ids: Array<number>, options?: RawAxiosRequestConfig): AxiosPromise<Array<CorporationResponse>> {
|
||||
return localVarFp.findCorporations(ids, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* CorporationApi - object-oriented interface
|
||||
*/
|
||||
export class CorporationApi extends BaseAPI {
|
||||
/**
|
||||
*
|
||||
* @summary Resolve public information (name, ticker, alliance) for a corporation id
|
||||
* @param {number} corporationId Corporation id to resolve, e.g. 98000001
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
public findCorporation(corporationId: number, options?: RawAxiosRequestConfig) {
|
||||
return CorporationApiFp(this.configuration).findCorporation(corporationId, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary Resolve public information for several corporation ids at once, silently omitting ids ESI cannot resolve
|
||||
* @param {Array<number>} ids Corporation ids to resolve, e.g. ids=98000001,98000002
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
public findCorporations(ids: Array<number>, options?: RawAxiosRequestConfig) {
|
||||
return CorporationApiFp(this.configuration).findCorporations(ids, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* LedgerApi - axios parameter creator
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
ActivityApi,
|
||||
AuthApi,
|
||||
CharacterApi,
|
||||
CorporationApi,
|
||||
LedgerApi,
|
||||
LocationApi,
|
||||
MarketApi,
|
||||
@@ -108,6 +109,7 @@ export const postLogout = (): Promise<void> =>
|
||||
export const ledgerApi = new LedgerApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
export const transactionApi = new TransactionApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
export const characterApi = new CharacterApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
export const corporationApi = new CorporationApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
export const ruleBookApi = new RuleBookApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
export const ruleScriptApi = new RuleScriptApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
export const activityApi = new ActivityApi(undefined, mammonUrl, mammonAxiosInstance);
|
||||
|
||||
Reference in New Issue
Block a user