Skip to content

Commit ac9d089

Browse files
committed
show value sorted by in products list
1 parent bb4f25f commit ac9d089

3 files changed

Lines changed: 45 additions & 7 deletions

File tree

src/lib/lttstore/LTTProductCard.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { typed } from '$lib';
77
import { dev } from "$app/environment";
88
import { sha256 } from "$lib/utils.ts";
9+
import type { Snippet } from "svelte";
910
1011
let {
1112
product = typed<ShopifyProduct>(),
@@ -14,7 +15,8 @@
1415
purchasesPerHour = typed<number | undefined>(),
1516
goneIn = typed<boolean>(false),
1617
available = typed<boolean>(true),
17-
lazyLoadImage = typed<boolean>(false)
18+
lazyLoadImage = typed<boolean>(false),
19+
detail = typed<Snippet | undefined>()
1820
} = $props();
1921
2022
let goneInHours = $derived((stock?.total ?? -1) / (purchasesPerHour ?? -1));
@@ -75,6 +77,7 @@
7577
Could be gone in {Math.round(goneInHours)}h
7678
</div>
7779
{/if}
80+
{@render detail?.()}
7881
</a>
7982

8083
<style>

src/routes/(info)/lttstore/products/+page.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const load = (async ({platform, url}) => {
3434
const allProducts = retryD1(() =>
3535
// a bunch of stuff removed that isnt needed for the products page
3636
// ordered by available second to put items currently on lttstore above ones that arent
37-
db.prepare("select handle,shortTitle,id,available,json_remove(json_remove(json_remove(json_remove(product, '$.media'), '$.images'), '$.variants'), '$.description') as product from products order by " + sortColumn + " DESC, available DESC")
37+
db.prepare("select handle,shortTitle,id,available,purchasesPerDay,purchasesPerHour,metadataUpdate,stockChecked,lastRestock,json_remove(json_remove(json_remove(json_remove(product, '$.media'), '$.images'), '$.variants'), '$.description') as product from products order by " + sortColumn + " DESC, available DESC")
3838
.all<ProductsTableRow>()
3939
.then(r => r.results)
4040
);

src/routes/(info)/lttstore/products/+page.svelte

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<script lang="ts">
2-
import { run } from 'svelte/legacy';
3-
4-
52
import LTTProductCard from "$lib/lttstore/LTTProductCard.svelte";
63
import { page } from "$app/state";
74
import {flip} from "svelte/animate";
85
import { fade } from "svelte/transition"
96
import { goto, invalidateAll } from "$app/navigation";
107
import { Progress } from "@skeletonlabs/skeleton-svelte";
118
import { dev } from "$app/environment";
9+
import type { PageProps } from "./$types";
10+
import DateStamp from "$lib/DateStamp.svelte";
1211
13-
let { data } = $props();
12+
let { data }: PageProps = $props();
1413
1514
let loading = $state(false);
1615
async function reload() {
@@ -69,7 +68,43 @@
6968
</div>
7069
{#each data.allProducts as product, i (product.id)}
7170
<div class="inline-block" animate:flip={{ duration: 200 }}>
72-
<LTTProductCard product={JSON.parse(product.product)} shortTitle={product.shortTitle} available={product.available} lazyLoadImage={i > 30}/>
71+
<LTTProductCard
72+
product={JSON.parse(product.product)}
73+
shortTitle={product.shortTitle}
74+
available={product.available}
75+
lazyLoadImage={i > 30}
76+
>
77+
{#snippet detail()}
78+
<div class="opacity-80 text-xs">
79+
{#if data.sortColumn === "purchasesPerDay"}
80+
{product.purchasesPerDay?.toFixed(2) ?? "??"} spd
81+
{:else if data.sortColumn === "purchasesPerHour"}
82+
{product.purchasesPerHour?.toFixed(2) ?? "??"} sph
83+
{:else if data.sortColumn === "metadataUpdate"}
84+
Meta updated
85+
{#if product.metadataUpdate && product.metadataUpdate > 0}
86+
<DateStamp epochSeconds={product.metadataUpdate / 1e3} />
87+
{:else}
88+
N/A
89+
{/if}
90+
{:else if data.sortColumn === "stockChecked"}
91+
Stock checked
92+
{#if product.stockChecked && product.stockChecked > 0}
93+
<DateStamp epochSeconds={product.stockChecked / 1e3} />
94+
{:else}
95+
N/A
96+
{/if}
97+
{:else if data.sortColumn === "lastRestock"}
98+
Restocked
99+
{#if product.lastRestock && product.lastRestock > 0}
100+
<DateStamp epochSeconds={product.lastRestock / 1e3} />
101+
{:else}
102+
N/A
103+
{/if}
104+
{/if}
105+
</div>
106+
{/snippet}
107+
</LTTProductCard>
73108
</div>
74109
{:else}
75110
No products are being tracked yet!

0 commit comments

Comments
 (0)