From cd9748e59f1dd9ef31afb22195b8d5a1346ec5c3 Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 16 May 2022 00:09:44 -0500 Subject: start adding auctionprices page --- src/routes/auctionprices.svelte | 114 ++++++++++++++++++++++++++++++++++++++++ src/routes/index.svelte | 2 +- 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/routes/auctionprices.svelte (limited to 'src/routes') diff --git a/src/routes/auctionprices.svelte b/src/routes/auctionprices.svelte new file mode 100644 index 0000000..f464f7b --- /dev/null +++ b/src/routes/auctionprices.svelte @@ -0,0 +1,114 @@ + + + + + +
+ + + +
+

SkyBlock Auction Prices

+
+ +
+
+ {#each data as item (item._id)} + {@const binAuctions = item.auctions.filter(i => i.bin)} + {@const normalAuctions = item.auctions.filter(i => !i.bin)} +
+

{cleanId(item._id.toLowerCase())}

+
+ {#if binAuctions.length > 0} +

+ Lowest recent BIN: + {binAuctions.reduce((a, b) => (a.coins < b.coins ? a : b)).coins.toLocaleString()} coins + +

+ {/if} + {#if normalAuctions.length > 0} +

+ Lowest recent auction: + {normalAuctions + .reduce((a, b) => (a.coins < b.coins ? a : b)) + .coins.toLocaleString()} coins + +

+ {/if} +
+
+ +
+
+ {/each} + {#if data.length === 0} + No results + {/if} +
+
+ + diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 4c11a88..d22f854 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -49,7 +49,7 @@

Other SkyBlock tools

    -
  • Auction prices (coming soon)
  • +
  • Auction prices
  • Leaderboards
  • Bazaar (coming soon)
  • Fake chat generator
  • -- cgit From 8ba9c7090c88c04d43ca727b7ed012cf5a6b58c8 Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 16 May 2022 15:36:06 +0000 Subject: start adding really basic tooltip --- src/routes/auctionprices.svelte | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/routes') diff --git a/src/routes/auctionprices.svelte b/src/routes/auctionprices.svelte index f464f7b..4e7bfde 100644 --- a/src/routes/auctionprices.svelte +++ b/src/routes/auctionprices.svelte @@ -16,13 +16,23 @@ - +
    -- cgit From 52293d3ced2b3a3e883a4f1f8499cfa72c2745b1 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 17 May 2022 23:47:15 -0500 Subject: fix race condition in search --- src/routes/auctionprices.svelte | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/routes') diff --git a/src/routes/auctionprices.svelte b/src/routes/auctionprices.svelte index 33b6b86..b8ac429 100644 --- a/src/routes/auctionprices.svelte +++ b/src/routes/auctionprices.svelte @@ -43,9 +43,13 @@ } async function fetchItems(itemIds: string[]) { - let url = `${API_URL}auctionprices` + const url = `${API_URL}auctionprices` + const localQuery = query if (query.length > 0) url += `?items=${itemIds.join(',')}` - data = await fetch(url).then(r => r.json()) + const localData = await fetch(url).then(r => r.json()) + + // if the query hasn't changed, update the data + if (query === localQuery) data = localData } let pageHeight = 0 -- cgit From f908f2682841d3cb060553097d7f554a8211cf2f Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 17 May 2022 23:52:39 -0500 Subject: Update auctionprices.svelte --- src/routes/auctionprices.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/routes') diff --git a/src/routes/auctionprices.svelte b/src/routes/auctionprices.svelte index b8ac429..2f56b50 100644 --- a/src/routes/auctionprices.svelte +++ b/src/routes/auctionprices.svelte @@ -43,7 +43,7 @@ } async function fetchItems(itemIds: string[]) { - const url = `${API_URL}auctionprices` + let url = `${API_URL}auctionprices` const localQuery = query if (query.length > 0) url += `?items=${itemIds.join(',')}` const localData = await fetch(url).then(r => r.json()) -- cgit From 696c602bc917516ed5e28f416837ce7236caa911 Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 18 May 2022 00:11:58 -0500 Subject: infinite scrolling for auctions the code sucks but it works --- src/routes/auctionprices.svelte | 44 ++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'src/routes') diff --git a/src/routes/auctionprices.svelte b/src/routes/auctionprices.svelte index 2f56b50..a4b0bf8 100644 --- a/src/routes/auctionprices.svelte +++ b/src/routes/auctionprices.svelte @@ -20,8 +20,7 @@ import Header from '$lib/Header.svelte' import Head from '$lib/Head.svelte' import { cleanId, type PreviewedAuctionData } from '$lib/utils' - import type { ItemAuctionsSchema, ItemListData, ItemListItem } from '$lib/APITypes' - import Item from '$lib/minecraft/Item.svelte' + import type { ItemAuctionsSchema } from '$lib/APITypes' import AuctionPriceScatterplot from '$lib/AuctionPriceScatterplot.svelte' import AuctionPreviewTooltip from '$lib/AuctionPreviewTooltip.svelte' import { browser } from '$app/env' @@ -35,33 +34,54 @@ $: queryNormalized = query.toLowerCase() - $: allMatchingItemIds = Object.entries(auctionItems) - .filter(a => a[1].toLowerCase().includes(queryNormalized)) - .map(a => a[0]) + let allMatchingItemIds: string[] $: { - if (browser) fetchItems(allMatchingItemIds.slice(0, 100)) + pageNumber = 0 + allMatchingItemIds = Object.entries(auctionItems) + .filter(a => a[1].toLowerCase().includes(queryNormalized)) + .map(a => a[0]) + } + $: { + if (browser) fetchAndSetItems(allMatchingItemIds.slice(0, 100)) } - async function fetchItems(itemIds: string[]) { - let url = `${API_URL}auctionprices` + async function fetchAndSetItems(itemIds: string[]) { const localQuery = query - if (query.length > 0) url += `?items=${itemIds.join(',')}` - const localData = await fetch(url).then(r => r.json()) - + const localData = await fetchItems(query.length > 0 ? itemIds : null) // if the query hasn't changed, update the data if (query === localQuery) data = localData } + async function fetchItems(itemIds: null | string[]): Promise { + let url = `${API_URL}auctionprices` + if (itemIds !== null) url += `?items=${itemIds.join(',')}` + return await fetch(url).then(r => r.json()) + } let pageHeight = 0 $: { pageHeight = 0 } - function checkScroll() { + // 0 indexed + let pageNumber = 0 + let loadingPage = false + + async function checkScroll() { + if (loadingPage) return + let pageHeightTemp = window.scrollY + window.innerHeight if (pageHeightTemp <= pageHeight) return pageHeight = pageHeightTemp if (pageHeight >= document.body.scrollHeight - 1000) { + loadingPage = true + pageNumber++ + const itemIds = allMatchingItemIds.slice(pageNumber * 100, (pageNumber + 1) * 100) + if (itemIds.length > 0) { + const shownIds = data.map(d => d.id) + const items = (await fetchItems(itemIds)).filter(i => !shownIds.includes(i.id)) + data = [...data, ...items] + } + loadingPage = false } } -- cgit From 4fa747dd1f433113fad23826a447627ab634215f Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 18 May 2022 00:13:00 -0500 Subject: rename frequency to volume --- src/routes/auctionprices.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/routes') diff --git a/src/routes/auctionprices.svelte b/src/routes/auctionprices.svelte index a4b0bf8..853c7d6 100644 --- a/src/routes/auctionprices.svelte +++ b/src/routes/auctionprices.svelte @@ -123,7 +123,7 @@ {/if} {#if item.auctions.length >= 2}

    - Frequency: + Volume: {parseFloat( ( -- cgit From aeebc84c5bbecb29707e4ace0ce515cdde0bb27b Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 18 May 2022 17:59:23 +0000 Subject: fix item names with formatting codes --- src/routes/auctionprices.svelte | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/routes') diff --git a/src/routes/auctionprices.svelte b/src/routes/auctionprices.svelte index 853c7d6..95e062b 100644 --- a/src/routes/auctionprices.svelte +++ b/src/routes/auctionprices.svelte @@ -19,7 +19,7 @@ -- cgit