aboutsummaryrefslogtreecommitdiff
path: root/src/lib/AuctionPreviewTooltip.svelte
blob: 417f8b34c01b1ed5538bf02ea91f88f6160ef2fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<script lang="ts">
	import { API_URL } from './api'

	import Loader from './layout/Loader.svelte'
	import type { PreviewedAuctionData } from './utils'

	export let preview: PreviewedAuctionData | null
	let lastPreview: PreviewedAuctionData | null

	$: lastPreview = preview ?? lastPreview

	function onClick(e) {
		// commented out because it doesn't work: sometimes e.target is null when we click a point
		// if (!e.target.closest('.item-auction-history')) {
		// 	preview = null
		// 	lastPreview = null
		// }
	}
</script>

<svelte:body on:click={onClick} />

{#if lastPreview}
	{@const date = new Date(lastPreview.auction.ts * 1000)}
	<div
		id="auction-preview-tooltip"
		class:hidden={preview === null}
		style="left: {lastPreview.pageX}px; top: {lastPreview.pageY}px"
	>
		<p><b>{lastPreview.auction.coins.toLocaleString()}</b> coins</p>
		<time>{date.toLocaleString()}</time>
	</div>
{/if}

<style>
	#auction-preview-tooltip {
		position: absolute;
		border: 1px solid rgba(255, 255, 255, 0.1);
		background: rgba(0, 0, 0, 0.1);
		padding: 0.5em;
		transition: left 200ms, top 200ms;
		pointer-events: none;
	}

	p {
		margin: 0;
	}

	time {
		color: var(--theme-darker-text);
	}
</style>