diff --git a/src/lib/auth/index.server.ts b/src/lib/auth/index.server.ts index f7a7c50..78bad42 100644 --- a/src/lib/auth/index.server.ts +++ b/src/lib/auth/index.server.ts @@ -3,7 +3,7 @@ import bcrypt from 'bcrypt'; import sql from '$lib/db/db.server'; import { type Cookies, error } from '@sveltejs/kit'; import jwt from 'jsonwebtoken'; -import type { inquiryTokenPayload } from '$lib/types/inquiries.server'; +import type { inquiryTokenPayload } from '$lib/types/inquiries'; export function setJWTCookie(cookies: Cookies, user: User) { const payload = { diff --git a/src/lib/components/custom/claim-item-dialog.svelte b/src/lib/components/custom/claim-item-dialog.svelte index 3e0912b..8c7d0c0 100644 --- a/src/lib/components/custom/claim-item-dialog.svelte +++ b/src/lib/components/custom/claim-item-dialog.svelte @@ -5,7 +5,7 @@ import * as RadioGroup from '$lib/components/ui/radio-group'; import { Label } from '$lib/components/ui/label'; import * as Field from '$lib/components/ui/field'; - import type { Item } from '$lib/types/item.server'; + import type { Item } from '$lib/types/item'; import NoImagePlaceholder from './no-image-placeholder.svelte'; import LocationIcon from '@lucide/svelte/icons/map-pinned'; import { EMAIL_REGEX_STRING } from '$lib/consts'; diff --git a/src/lib/components/custom/edit-item-dialog.svelte b/src/lib/components/custom/edit-item-dialog.svelte index 67858c5..54b0967 100644 --- a/src/lib/components/custom/edit-item-dialog.svelte +++ b/src/lib/components/custom/edit-item-dialog.svelte @@ -10,7 +10,7 @@ import ImageUpload from '$lib/components/custom/image-upload/image-upload.svelte'; import { approveDenyItem, genDescription } from '$lib/db/items.remote'; import { EMAIL_REGEX_STRING } from '$lib/consts'; - import type { Item } from '$lib/types/item.server'; + import type { Item } from '$lib/types/item'; import { Textarea } from '$lib/components/ui/textarea'; import * as Card from '$lib/components/ui/card'; import { dateFormatOptions } from '$lib/shared'; @@ -28,7 +28,13 @@ async function onSelect(file: File) { isGenerating = true; - description = await genDescription(file); + + const buffer = await file.arrayBuffer(); + const base64 = btoa( + String.fromCharCode(...new Uint8Array(buffer)) + ); + + description = await genDescription(base64); isGenerating = false; } diff --git a/src/lib/components/custom/image-upload/image-upload.svelte b/src/lib/components/custom/image-upload/image-upload.svelte index 4aed224..b2a9303 100644 --- a/src/lib/components/custom/image-upload/image-upload.svelte +++ b/src/lib/components/custom/image-upload/image-upload.svelte @@ -3,17 +3,25 @@ import X from '@lucide/svelte/icons/x'; import { onDestroy } from 'svelte'; - export let name = 'image'; - export let required = false; - export let disabled = false; - export let onSelect: ((file: File) => void) | null = null; - export let canRemove = !required; + let { + name = 'image', + required = false, + disabled = false, + onSelect = null, + previewUrl = null + }: { + name?: string; + required?: boolean; + disabled?: boolean; + onSelect?: ((file: File) => void) | null; + previewUrl?: string | null; + } = $props(); + let inputEl = $state(null); + let dragging = $state(false); - let inputEl: HTMLInputElement | null = null; - export let previewUrl: string | null = null; - let dragging = false; - + // derived value instead of initializing from required + let canRemove = $derived(!required); function openFileDialog() { if (!disabled) { @@ -22,6 +30,7 @@ } function handleFiles(files: FileList | null) { + console.log('handleFiles'); if (!files || files.length === 0) return; const selected = files[0]; @@ -30,7 +39,6 @@ cleanupPreview(); previewUrl = URL.createObjectURL(selected); - // Trigger callback if (onSelect) onSelect(selected); } @@ -56,9 +64,7 @@ onDestroy(cleanupPreview); -
- @@ -76,10 +82,10 @@ class="dropzone" class:has-image={!!previewUrl} class:dragging={dragging} - on:click={openFileDialog} - on:dragover|preventDefault={() => !disabled && (dragging = true)} - on:dragleave={() => (dragging = false)} - on:drop={onDrop} + onclick={openFileDialog} + ondragover={(e) => {e.preventDefault(); dragging = !disabled;}} + ondragleave={() => (dragging = false)} + ondrop={onDrop} type="button" > {#if previewUrl} @@ -92,12 +98,20 @@ {:else}
-

Click or drag an image here {required ? '*' : ''}

+

+ Click or drag an image here + {required ? '*' : ''} +

{/if} + {#if previewUrl && canRemove} - @@ -110,10 +124,8 @@ width: 100%; max-height: 200px; min-height: 80px; - /*height: 200px;*/ border-radius: 12px; border: 2px dashed var(--border); - /*background: var(--bg, #fafafa);*/ cursor: pointer; display: flex; align-items: center; diff --git a/src/lib/components/custom/inquire-item-dialog.svelte b/src/lib/components/custom/inquire-item-dialog.svelte index 26c8534..19c15cd 100644 --- a/src/lib/components/custom/inquire-item-dialog.svelte +++ b/src/lib/components/custom/inquire-item-dialog.svelte @@ -5,7 +5,7 @@ import * as RadioGroup from '$lib/components/ui/radio-group'; import { Label } from '$lib/components/ui/label'; import * as Field from '$lib/components/ui/field'; - import type { Item } from '$lib/types/item.server'; + import type { Item } from '$lib/types/item'; import NoImagePlaceholder from './no-image-placeholder.svelte'; import LocationIcon from '@lucide/svelte/icons/map-pinned'; import { EMAIL_REGEX_STRING } from '$lib/consts'; diff --git a/src/lib/components/custom/item-listing.svelte b/src/lib/components/custom/item-listing.svelte index 33fe4d1..86fcd4f 100644 --- a/src/lib/components/custom/item-listing.svelte +++ b/src/lib/components/custom/item-listing.svelte @@ -1,6 +1,6 @@ + +
+
+ +
+ {#each data.messages as msg, index (msg.id)} +
+ +
+
+ {senderLabel(msg.sender)} +
+ + {#if index < data.messages.length - 1} +
+ {/if} +
+ + +
+

{msg.body}

+ {msg.createdAt.toLocaleString()} +
+
+ {/each} +
+
+ + +
+