diff --git a/src/api/customDiscs/api.ts b/src/api/customDiscs/api.ts index ce4394b..a1a65ef 100644 --- a/src/api/customDiscs/api.ts +++ b/src/api/customDiscs/api.ts @@ -1,15 +1,34 @@ import { Config } from "@/config"; -import type { CustomDiscsOverview } from "./customDiscs"; +import type { CustomDiscsOverview, CustomDiscStats } from "./customDiscs"; import { itemsStore } from "@/store/items-state"; export async function retrieveCustomDiscs(): Promise { // Don't reload if data is recent - if (itemsStore.customDiscs != null) return itemsStore.customDiscs; + if (itemsStore.customDiscs != null && new Date().getTime() - itemsStore.customDiscsLastUpdated.getTime() < 30000) + return itemsStore.customDiscs; // Get custom discs let httpResponse = await fetch(`${Config.APIURL}/api/v2/customDiscs`, { method: "get" }); if (httpResponse.status !== 200) return { discs: [], unsoldDiscs: 0 }; itemsStore.customDiscs = (await httpResponse.json()).result as CustomDiscsOverview; + for (const disc of itemsStore.customDiscs.discs) { + itemsStore.customDiscLookup[disc.name] = disc; + } + itemsStore.customDiscsLastUpdated = new Date(); return itemsStore.customDiscs; } + +export async function retrieveCustomDiscStats(): Promise { + // Don't reload if data is recent + if (itemsStore.customDiscStats != null && new Date().getTime() - itemsStore.customDiscsStatsLastUpdated.getTime() < 30000) + return itemsStore.customDiscStats; + + // Get custom disc stats + let httpResponse = await fetch(`${Config.APIURL}/api/customDiscs/stats`, { method: "get" }); + if (httpResponse.status !== 200) return []; + + itemsStore.customDiscStats = (await httpResponse.json()).result.discs as CustomDiscStats[]; + itemsStore.customDiscsStatsLastUpdated = new Date(); + return itemsStore.customDiscStats; +} diff --git a/src/api/customDiscs/customDiscs.ts b/src/api/customDiscs/customDiscs.ts index 7c0e616..5397e04 100644 --- a/src/api/customDiscs/customDiscs.ts +++ b/src/api/customDiscs/customDiscs.ts @@ -6,4 +6,14 @@ export interface CustomDiscsOverview { export interface CustomDisc { name: string; displayName: string; + source: string; + version: string; +} + +export interface CustomDiscStats { + discName: string; + numSales: number; + minPrice: number; + maxPrice: number; + averagePrice: number; } diff --git a/src/components/CustomDiscStats.vue b/src/components/CustomDiscStats.vue new file mode 100644 index 0000000..44176f2 --- /dev/null +++ b/src/components/CustomDiscStats.vue @@ -0,0 +1,171 @@ + + + diff --git a/src/store/items-state.ts b/src/store/items-state.ts index 9d3549d..a0f975c 100644 --- a/src/store/items-state.ts +++ b/src/store/items-state.ts @@ -1,15 +1,23 @@ -import type { CustomDiscsOverview } from "@/api/customDiscs/customDiscs"; +import type { CustomDisc, CustomDiscsOverview, CustomDiscStats } from "@/api/customDiscs/customDiscs"; import type { VillagerTrade } from "@/api/villagerTrades/villagerTrades"; import { reactive } from "vue"; export interface ItemsOverview { - customDiscs: CustomDiscsOverview | null; + customDiscs: CustomDiscsOverview; + customDiscLookup: { [discName: string]: CustomDisc }; + customDiscsLastUpdated: Date; + customDiscStats: CustomDiscStats[]; + customDiscsStatsLastUpdated: Date; villagerTrades: VillagerTrade[]; villagerTradesLastUpdated: Date; } export const itemsStore = reactive({ - customDiscs: null, + customDiscs: { discs: [], unsoldDiscs: 0 }, + customDiscLookup: {}, + customDiscsLastUpdated: new Date(0), + customDiscStats: [], + customDiscsStatsLastUpdated: new Date(0), villagerTrades: [], villagerTradesLastUpdated: new Date(0), } as ItemsOverview); diff --git a/src/views/ItemTypeView.vue b/src/views/ItemTypeView.vue index 3229c28..0c1e430 100644 --- a/src/views/ItemTypeView.vue +++ b/src/views/ItemTypeView.vue @@ -24,6 +24,7 @@ import { itemsStore } from "@/store/items-state"; import { setPageTitle } from "@/router/pageTitle"; import { userStore } from "@/store/user-state"; import { normalisePrice, simpleNormalisedPrice } from "@/utilities/normalise-price"; +import CustomDiscStats from "@/components/CustomDiscStats.vue"; interface Props { itemType: string; @@ -260,12 +261,11 @@ function getWikiLink() {
- +
@@ -310,7 +310,8 @@ function getWikiLink() {

Villager Trade

- {{ villagerTrade.villager }}: {{ villagerTrade.price }} {{ villagerTrade.currency }} for {{ villagerTrade.quantity }} + {{ villagerTrade.villager }}: {{ villagerTrade.price }} {{ villagerTrade.currency }} for {{ + villagerTrade.quantity }} {{ villagerTrade.itemType }} {{ villagerTrade.extraInfo ? `(${villagerTrade.extraInfo})` : "" }}

@@ -319,6 +320,15 @@ function getWikiLink() {

+ +
+
+

Statistics

+
+ + +
+
@@ -329,31 +339,17 @@ function getWikiLink() {
- - + - + @@ -378,39 +374,24 @@ function getWikiLink() {
- - + - +
-