-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* backend changes for new display order * update frontend alter display order * handle errors * emit events * fix issues * hide reorder button for non-owners * bit of cleanup * fix lint issue
- Loading branch information
Showing
17 changed files
with
380 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240825030505_add_display_order/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "items" ADD COLUMN "displayOrder" INTEGER; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/lib/components/wishlists/ItemCard/ReorderButtons.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script context="module" lang="ts"> | ||
export type ItemVoidFunction = (itemId: number) => void; | ||
</script> | ||
|
||
<script lang="ts"> | ||
import { dragHandle } from "svelte-dnd-action"; | ||
import type { FullItem } from "./ItemCard.svelte"; | ||
export let item: FullItem; | ||
export let onIncreasePriority: ItemVoidFunction | undefined = undefined; | ||
export let onDecreasePriority: ItemVoidFunction | undefined = undefined; | ||
</script> | ||
|
||
<div class="w-max space-x-4"> | ||
<button | ||
class="variant-outline-primary btn btn-icon btn-icon-sm md:btn-icon" | ||
aria-label="lower priority for {item.name}" | ||
on:click|stopPropagation={() => onDecreasePriority && onDecreasePriority(item.id)} | ||
> | ||
<iconify-icon icon="ion:arrow-down"></iconify-icon> | ||
</button> | ||
<button | ||
class="variant-outline-primary btn md:btn-lg" | ||
aria-label="drag-handle for {item.name}" | ||
on:click|stopPropagation={() => {}} | ||
use:dragHandle | ||
> | ||
<iconify-icon icon="ion:reorder-two"></iconify-icon> | ||
</button> | ||
<button | ||
class="variant-outline-primary btn btn-icon btn-icon-sm md:btn-icon" | ||
aria-label="increase priority for {item.name}" | ||
on:click|stopPropagation={() => onIncreasePriority && onIncreasePriority(item.id)} | ||
> | ||
<iconify-icon icon="ion:arrow-up"></iconify-icon> | ||
</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script lang="ts"> | ||
export let reordering: boolean; | ||
export let onFinalize: VoidFunction; | ||
</script> | ||
|
||
<div> | ||
{#if reordering} | ||
<button class="variant-ghost-secondary chip" on:click={onFinalize}>Finish</button> | ||
{:else} | ||
<button class="variant-filled-primary chip" on:click={() => (reordering = true)}>Reorder</button> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { Prisma } from "@prisma/client"; | ||
|
||
export const patchItem = (body: Record<string, unknown>) => { | ||
const data: Prisma.ItemUpdateInput & { id?: number } = { | ||
id: body.id as number | ||
}; | ||
let deleteOldImage = false; | ||
|
||
if (body.name && typeof body.name === "string") data.name = body.name; | ||
if (body.price && typeof body.price === "string") data.price = body.price; | ||
if (body.url && typeof body.url === "string") data.url = body.url; | ||
if (body.note && typeof body.note === "string") data.note = body.note; | ||
if (body.displayOrder !== null && typeof body.displayOrder === "number") | ||
data.displayOrder = body.displayOrder as number; | ||
if (body.image_url && typeof body.image_url === "string") { | ||
data.imageUrl = body.image_url; | ||
deleteOldImage = true; | ||
} | ||
if (body.pledgedById && typeof body.pledgedById === "string") { | ||
if (body.pledgedById === "0") { | ||
data.pledgedBy = { | ||
disconnect: true | ||
}; | ||
} else { | ||
data.pledgedBy = { | ||
connect: { | ||
id: body.pledgedById | ||
} | ||
}; | ||
} | ||
} | ||
if (body.publicPledgedById && typeof body.publicPledgedById === "string") { | ||
if (body.publicPledgedById === "0") { | ||
data.publicPledgedBy = { | ||
disconnect: true | ||
}; | ||
} else { | ||
data.publicPledgedBy = { | ||
connect: { | ||
id: body.publicPledgedById | ||
} | ||
}; | ||
} | ||
} | ||
if (Object.keys(body).includes("approved") && typeof body.approved === "boolean") data.approved = body.approved; | ||
if (Object.keys(body).includes("purchased") && typeof body.purchased === "boolean") data.purchased = body.purchased; | ||
|
||
return { | ||
data, | ||
deleteOldImage | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.