From d92b455d206285a8763634006604cb70622cc1ee Mon Sep 17 00:00:00 2001
From: Carter <35710697+cmintey@users.noreply.github.com>
Date: Mon, 23 Oct 2023 16:28:50 -0500
Subject: [PATCH] Add the ability to sort by price (#65)
---
src/ambient.d.ts | 7 ++
.../wishlists/chips/BaseChip.svelte | 91 +++++++++++++++++++
.../wishlists/chips/ClaimFilter.svelte | 81 ++++-------------
.../components/wishlists/chips/SortBy.svelte | 27 ++++++
.../wishlists/[username]/+page.server.ts | 8 ++
src/routes/wishlists/[username]/+page.svelte | 12 ++-
6 files changed, 161 insertions(+), 65 deletions(-)
create mode 100644 src/lib/components/wishlists/chips/BaseChip.svelte
create mode 100644 src/lib/components/wishlists/chips/SortBy.svelte
diff --git a/src/ambient.d.ts b/src/ambient.d.ts
index 03e612e..ad13e28 100644
--- a/src/ambient.d.ts
+++ b/src/ambient.d.ts
@@ -55,3 +55,10 @@ type Config = {
};
smtp: SMTPConfig;
};
+
+type Option = {
+ value: string;
+ direction?: Direction;
+ displayValue: string;
+};
+type Direction = "asc" | "desc";
diff --git a/src/lib/components/wishlists/chips/BaseChip.svelte b/src/lib/components/wishlists/chips/BaseChip.svelte
new file mode 100644
index 0000000..845cbe9
--- /dev/null
+++ b/src/lib/components/wishlists/chips/BaseChip.svelte
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
diff --git a/src/lib/components/wishlists/chips/ClaimFilter.svelte b/src/lib/components/wishlists/chips/ClaimFilter.svelte
index 74bd38a..bd34650 100644
--- a/src/lib/components/wishlists/chips/ClaimFilter.svelte
+++ b/src/lib/components/wishlists/chips/ClaimFilter.svelte
@@ -1,67 +1,24 @@
-
-
-
-
-
-
+
diff --git a/src/lib/components/wishlists/chips/SortBy.svelte b/src/lib/components/wishlists/chips/SortBy.svelte
new file mode 100644
index 0000000..4339914
--- /dev/null
+++ b/src/lib/components/wishlists/chips/SortBy.svelte
@@ -0,0 +1,27 @@
+
+
+
diff --git a/src/routes/wishlists/[username]/+page.server.ts b/src/routes/wishlists/[username]/+page.server.ts
index 2e17fba..eabedc8 100644
--- a/src/routes/wishlists/[username]/+page.server.ts
+++ b/src/routes/wishlists/[username]/+page.server.ts
@@ -58,8 +58,16 @@ export const load: PageServerLoad = async ({ locals, params, depends, url }) =>
};
}
+ const orderBy: Prisma.ItemOrderByWithRelationInput = {};
+ const sort = url.searchParams.get("sort");
+ const direction = url.searchParams.get("dir");
+ if (sort === "price" && direction && (direction === "asc" || direction === "desc")) {
+ orderBy.price = direction;
+ }
+
const wishlistItems = await client.item.findMany({
where: search,
+ orderBy,
include: {
addedBy: {
select: {
diff --git a/src/routes/wishlists/[username]/+page.svelte b/src/routes/wishlists/[username]/+page.svelte
index acae9a1..b18ffa0 100644
--- a/src/routes/wishlists/[username]/+page.svelte
+++ b/src/routes/wishlists/[username]/+page.svelte
@@ -11,6 +11,7 @@
import { crossfade } from "svelte/transition";
import { isInstalled } from "$lib/stores/is-installed";
import empty from "$lib/assets/no_wishes.svg";
+ import SortBy from "$lib/components/wishlists/chips/SortBy.svelte";
export let data: PageData;
@@ -84,10 +85,15 @@
No wishes yet
{:else}
- {#if !data.listOwner.isMe}
-
- {/if}
+
+
+ {#if !data.listOwner.isMe}
+
+ {/if}
+
+
+
{#each data.items as item (item.id)}