Compare commits
7 Commits
9f2627faf8
...
feature/pr
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d57345634 | |||
| 0a82fca6d3 | |||
| 1e57e7c33e | |||
| c484948a5e | |||
| 4748b15cc4 | |||
| 9ccba70ede | |||
| 1868b3e248 |
@@ -1,5 +1,5 @@
|
|||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
import { Log, User, UserManager } from "oidc-client-ts";
|
import { Log, User, UserManager, WebStorageStateStore } from "oidc-client-ts";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { computed, ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
|
|
||||||
@@ -11,7 +11,9 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
client_id: import.meta.env.VITE_AUTH_CLIENT_ID,
|
client_id: import.meta.env.VITE_AUTH_CLIENT_ID,
|
||||||
client_secret: import.meta.env.VITE_AUTH_CLIENT_SECRET,
|
client_secret: import.meta.env.VITE_AUTH_CLIENT_SECRET,
|
||||||
redirect_uri: import.meta.env.VITE_AUTH_REDIRECT_URI,
|
redirect_uri: import.meta.env.VITE_AUTH_REDIRECT_URI,
|
||||||
scope: import.meta.env.VITE_AUTH_SCOPE
|
scope: import.meta.env.VITE_AUTH_SCOPE,
|
||||||
|
stateStore: new WebStorageStateStore({ store: window.localStorage }),
|
||||||
|
userStore: new WebStorageStateStore({ store: window.localStorage })
|
||||||
});
|
});
|
||||||
|
|
||||||
const user = ref<User>();
|
const user = ref<User>();
|
||||||
|
|||||||
@@ -18,10 +18,4 @@ const timeFormat = new Intl.NumberFormat("en-US", {
|
|||||||
minimumIntegerDigits: 2
|
minimumIntegerDigits: 2
|
||||||
});
|
});
|
||||||
|
|
||||||
export const formatEveDate = (date?: Date | null) => {
|
export const formatEveDate = (date?: Date | null) => !date ? '' : `${date.getUTCFullYear()}.${timeFormat.format(date.getUTCMonth() + 1)}.${timeFormat.format(date.getUTCDate())} ${timeFormat.format(date.getUTCHours())}:${timeFormat.format(date.getUTCMinutes())}`;
|
||||||
try {
|
|
||||||
return !date ? '' : `${date.getUTCFullYear()}.${timeFormat.format(date.getUTCMonth() + 1)}.${timeFormat.format(date.getUTCDate())} ${timeFormat.format(date.getUTCHours())}:${timeFormat.format(date.getUTCMinutes())}`;
|
|
||||||
} catch (e) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
import { describe, expect, it } from 'vitest'
|
import { describe, expect, test } from 'vitest'
|
||||||
import { RegionalMarketCache } from './RegionalMarketCache'
|
import { RegionalMarketCache } from './RegionalMarketCache'
|
||||||
|
|
||||||
describe('RegionalMarketCache', () => {
|
describe('RegionalMarketCache', () => {
|
||||||
it('should cache and retrieve values', async () => {
|
test('should cache and retrieve values', async () => {
|
||||||
const cache = new RegionalMarketCache<string>(1000)
|
const cache = new RegionalMarketCache<string>(1000)
|
||||||
|
|
||||||
cache.set(1, 1, 'test')
|
cache.set(1, 1, 'test')
|
||||||
expect(cache.get(1, 1)).toBe('test')
|
expect(cache.get(1, 1)).toBe('test')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should remove values', async () => {
|
test('should remove values', async () => {
|
||||||
const cache = new RegionalMarketCache<string>(1000)
|
const cache = new RegionalMarketCache<string>(1000)
|
||||||
|
|
||||||
cache.set(1, 1, 'test')
|
cache.set(1, 1, 'test')
|
||||||
@@ -17,7 +17,7 @@ describe('RegionalMarketCache', () => {
|
|||||||
expect(cache.get(1, 1)).toBeUndefined()
|
expect(cache.get(1, 1)).toBeUndefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should compute values if absent', async () => {
|
test('should compute values if absent', async () => {
|
||||||
const cache = new RegionalMarketCache<string>(1000)
|
const cache = new RegionalMarketCache<string>(1000)
|
||||||
const value = await cache.computeIfAbsent(1, 1, () => Promise.resolve('test'))
|
const value = await cache.computeIfAbsent(1, 1, () => Promise.resolve('test'))
|
||||||
|
|
||||||
@@ -25,9 +25,9 @@ describe('RegionalMarketCache', () => {
|
|||||||
expect(cache.get(1, 1)).toBe('test')
|
expect(cache.get(1, 1)).toBe('test')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should expire values', async () => {
|
test('should expire values', async () => {
|
||||||
const cache = new RegionalMarketCache<string>(1)
|
const cache = new RegionalMarketCache<string>(1)
|
||||||
|
|
||||||
cache.set(1, 1, 'test')
|
cache.set(1, 1, 'test')
|
||||||
await new Promise(resolve => setTimeout(resolve, 10))
|
await new Promise(resolve => setTimeout(resolve, 10))
|
||||||
expect(cache.get(1, 1)).toBeUndefined()
|
expect(cache.get(1, 1)).toBeUndefined()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { marbasAxiosInstance, MarbasObject } from "@/marbas";
|
import { marbasAxiosInstance, MarbasObject } from "@/marbas";
|
||||||
|
import { AxiosResponse } from "axios";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { computed, ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
@@ -15,6 +16,17 @@ export type MarbasAcquiredType = MarbasObject & {
|
|||||||
user: number;
|
user: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RawMarbasAcquiredType = Omit<MarbasAcquiredType, 'date'> & {
|
||||||
|
date: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type InsertableRawMarbasAcquiredType = Omit<MarbasAcquiredType, 'id' | 'user' | 'date'>;
|
||||||
|
|
||||||
|
const mapRawMarbasAcquiredType = (raw: RawMarbasAcquiredType): MarbasAcquiredType => ({
|
||||||
|
...raw,
|
||||||
|
date: raw.date ? new Date(raw.date) : new Date()
|
||||||
|
});
|
||||||
|
|
||||||
const endpoint = '/api/acquisitions/';
|
const endpoint = '/api/acquisitions/';
|
||||||
|
|
||||||
export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
|
export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
|
||||||
@@ -22,14 +34,13 @@ export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
|
|||||||
|
|
||||||
const types = computed(() => acquiredTypes.value.filter(item => item.remaining > 0));
|
const types = computed(() => acquiredTypes.value.filter(item => item.remaining > 0));
|
||||||
const addAcquiredType = async (type: number, quantity: number, price: number, source?: AcquiredTypeSource) => {
|
const addAcquiredType = async (type: number, quantity: number, price: number, source?: AcquiredTypeSource) => {
|
||||||
const newItem = (await marbasAxiosInstance.post<MarbasAcquiredType>(endpoint, {
|
const newItem = mapRawMarbasAcquiredType((await marbasAxiosInstance.post<RawMarbasAcquiredType, AxiosResponse<RawMarbasAcquiredType>, InsertableRawMarbasAcquiredType>(endpoint, {
|
||||||
type: type,
|
type: type,
|
||||||
quantity: quantity,
|
quantity: quantity,
|
||||||
remaining: quantity,
|
remaining: quantity,
|
||||||
price: price,
|
price: price,
|
||||||
date: new Date(),
|
|
||||||
source: source ?? 'misc',
|
source: source ?? 'misc',
|
||||||
})).data
|
})).data);
|
||||||
|
|
||||||
acquiredTypes.value = [...acquiredTypes.value, newItem];
|
acquiredTypes.value = [...acquiredTypes.value, newItem];
|
||||||
log.info(`Acquired type ${newItem.id} with quantity ${newItem.quantity} and price ${newItem.price}`, newItem);
|
log.info(`Acquired type ${newItem.id} with quantity ${newItem.quantity} and price ${newItem.price}`, newItem);
|
||||||
@@ -57,7 +68,7 @@ export const useAcquiredTypesStore = defineStore('market-acquisition', () => {
|
|||||||
log.info(`Acquired type ${item.id} remaining: ${item.remaining}`, item);
|
log.info(`Acquired type ${item.id} remaining: ${item.remaining}`, item);
|
||||||
};
|
};
|
||||||
|
|
||||||
marbasAxiosInstance.get<MarbasAcquiredType[]>(endpoint).then(res => acquiredTypes.value = res.data.map(item => ({ ...item, date: new Date(item.date) })));
|
marbasAxiosInstance.get<RawMarbasAcquiredType[]>(endpoint).then(res => acquiredTypes.value = res.data.map(mapRawMarbasAcquiredType));
|
||||||
|
|
||||||
return { acquiredTypes: types, addAcquiredType, removeAcquiredType };
|
return { acquiredTypes: types, addAcquiredType, removeAcquiredType };
|
||||||
});
|
});
|
||||||
@@ -16,8 +16,8 @@ export type EsiMarketOrderHistory = {
|
|||||||
const historyCache: RegionalMarketCache<EsiMarketOrderHistory[]> = new RegionalMarketCache(() => {
|
const historyCache: RegionalMarketCache<EsiMarketOrderHistory[]> = new RegionalMarketCache(() => {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
|
|
||||||
if (date.getUTCHours() < 11) {
|
if (date.getUTCHours() >= 11) {
|
||||||
date.setUTCDate(date.getUTCDate() - 1);
|
date.setUTCDate(date.getUTCDate() + 1);
|
||||||
}
|
}
|
||||||
date.setUTCHours(11, 0, 0, 0);
|
date.setUTCHours(11, 0, 0, 0);
|
||||||
return date;
|
return date;
|
||||||
|
|||||||
@@ -17,14 +17,12 @@ withDefaults(defineProps<Props>(), {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-if="id || name">
|
<div v-if="id || name" class="flex flex-row">
|
||||||
<img v-if="id" :src="`https://images.evetech.net/types/${id}/icon?size=32`" class="inline-block w-5 h-5 me-1" alt="" />
|
<img v-if="id" :src="`https://images.evetech.net/types/${id}/icon?size=32`" class="inline-block w-5 h-5 me-1 mt-1" alt="" />
|
||||||
<template v-if="name">
|
<template v-if="name">
|
||||||
{{ name }}
|
{{ name }}
|
||||||
<RouterLink v-if="id" :to="{ name: 'market-types', params: { type: id } }" custom #default="{ navigate }">
|
<RouterLink v-if="id" :to="{ name: 'market-types', params: { type: id } }" class="button btn-icon ms-1 me-1 mt-1" title="Show item info">
|
||||||
<button class="btn-icon me-1" title="Show item info" @click="navigate">
|
<InformationCircleIcon />
|
||||||
<InformationCircleIcon />
|
|
||||||
</button>
|
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
<ClipboardButton v-if="!hideCopy" :value="name" />
|
<ClipboardButton v-if="!hideCopy" :value="name" />
|
||||||
</template>
|
</template>
|
||||||
@@ -32,7 +30,7 @@ withDefaults(defineProps<Props>(), {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped lang="postcss">
|
<style scoped lang="postcss">
|
||||||
button:deep(>svg) {
|
button:deep(>svg), .button:deep(>svg) {
|
||||||
@apply relative top-0.5 !w-4 !h-4;
|
@apply !w-4 !h-4;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -57,9 +57,10 @@ watch(() => marketTrackingStore.types, async t => {
|
|||||||
const prices = await apraisalStore.getPrices(await getMarketTypes(typesToLoad));
|
const prices = await apraisalStore.getPrices(await getMarketTypes(typesToLoad));
|
||||||
|
|
||||||
items.value = [
|
items.value = [
|
||||||
...items.value,
|
...items.value
|
||||||
...(await Promise.all(typesToLoad.map(i => createResult(i, prices.find(p => p.type.id === i) as MarketTypePrice))))
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
typesToLoad.forEach(async i => items.value.push(await createResult(i, prices.find(p => p.type.id === i) as MarketTypePrice)));
|
||||||
}, { immediate: true });
|
}, { immediate: true });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
22
src/preferences/Preference.ts
Normal file
22
src/preferences/Preference.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
export class Preference<T> {
|
||||||
|
private key: string;
|
||||||
|
private description: string;
|
||||||
|
private value?: T;
|
||||||
|
private defaultValue?: T;
|
||||||
|
|
||||||
|
constructor(key: string, description: string, defaultValue?: T) {
|
||||||
|
this.key = key;
|
||||||
|
this.description = description;
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
this.value = this.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
private load() {
|
||||||
|
const value = localStorage.getItem(this.key);
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
return JSON.parse(value);
|
||||||
|
}
|
||||||
|
return this.defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
0
src/preferences/index.ts
Normal file
0
src/preferences/index.ts
Normal file
Reference in New Issue
Block a user