Skip to content

Commit b54989e

Browse files
committed
refactor: Better structure for components
Moves chat-related components into dedicated subdirectories for improved organization and maintainability.
1 parent d6ec058 commit b54989e

17 files changed

+421
-261
lines changed

tools/server/webui/src/lib/components/app/chat/ChatAttachmentFilePreview.svelte renamed to tools/server/webui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentFilePreview.svelte

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
import { X } from '@lucide/svelte';
44
55
interface Props {
6+
class?: string;
67
id: string;
8+
onClick?: () => void;
9+
onRemove?: (id: string) => void;
710
name: string;
8-
type: string;
9-
size?: number;
1011
readonly?: boolean;
11-
onRemove?: (id: string) => void;
12-
class?: string;
12+
size?: number;
1313
textContent?: string;
14-
onClick?: () => void;
14+
type: string;
1515
}
1616
1717
let {
18+
class: className = '',
1819
id,
20+
onClick,
21+
onRemove,
1922
name,
20-
type,
21-
size,
2223
readonly = false,
23-
onRemove,
24-
class: className = '',
24+
size,
2525
textContent,
26-
onClick
26+
type,
2727
}: Props = $props();
2828
2929
function formatFileSize(bytes: number): string {
@@ -39,13 +39,13 @@
3939
}
4040
4141
function getPreviewText(content: string): string {
42-
// Get first 150 characters for preview
4342
return content.length > 150 ? content.substring(0, 150) : content;
4443
}
4544
</script>
4645

4746
{#if type === 'text/plain' || type === 'text'}
4847
{#if readonly}
48+
<!-- Readonly mode (ChatMessage) -->
4949
<button
5050
class="bg-muted border-border cursor-pointer rounded-lg border p-3 transition-shadow hover:shadow-md {className} w-full max-w-2xl"
5151
onclick={onClick}
@@ -55,16 +55,19 @@
5555
<div class="flex items-start gap-3">
5656
<div class="flex min-w-0 flex-1 flex-col items-start text-left">
5757
<span class="text-foreground w-full truncate text-sm font-medium">{name}</span>
58+
5859
{#if size}
5960
<span class="text-muted-foreground text-xs">{formatFileSize(size)}</span>
6061
{/if}
62+
6163
{#if textContent && type === 'text'}
6264
<div class="relative mt-2 w-full">
6365
<div
6466
class="text-muted-foreground overflow-hidden whitespace-pre-wrap break-words font-mono text-xs leading-relaxed"
6567
>
6668
{getPreviewText(textContent)}
6769
</div>
70+
6871
{#if textContent.length > 150}
6972
<div
7073
class="from-muted pointer-events-none absolute bottom-0 left-0 right-0 h-6 bg-gradient-to-t to-transparent"
@@ -78,7 +81,6 @@
7881
{:else}
7982
<!-- Non-readonly mode (ChatForm) -->
8083
<div class="bg-muted border-border relative rounded-lg border p-3 {className} w-64">
81-
<!-- Remove button in top-right corner -->
8284
<Button
8385
type="button"
8486
variant="ghost"
@@ -90,9 +92,7 @@
9092
<X class="h-3 w-3" />
9193
</Button>
9294

93-
<!-- Content -->
9495
<div class="pr-8">
95-
<!-- Add right padding to avoid overlap with X button -->
9696
<span class="text-foreground mb-3 block truncate text-sm font-medium">{name}</span>
9797

9898
{#if textContent}
@@ -103,6 +103,7 @@
103103
>
104104
{getPreviewText(textContent)}
105105
</div>
106+
106107
{#if textContent.length > 150}
107108
<div
108109
class="from-muted pointer-events-none absolute bottom-0 left-0 right-0 h-4 bg-gradient-to-t to-transparent"
@@ -120,6 +121,7 @@
120121
>
121122
{getFileTypeLabel(type)}
122123
</div>
124+
123125
<div class="flex flex-col">
124126
<span class="text-foreground max-w-36 truncate text-sm font-medium md:max-w-72"
125127
>{name}</span
@@ -128,6 +130,7 @@
128130
<span class="text-muted-foreground text-xs">{formatFileSize(size)}</span>
129131
{/if}
130132
</div>
133+
131134
{#if !readonly}
132135
<Button
133136
type="button"

tools/server/webui/src/lib/components/app/chat/ChatAttachmentImagePreview.svelte renamed to tools/server/webui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentImagePreview.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
class="{height} {width} cursor-pointer object-cover {imageClass}"
5555
/>
5656
{/if}
57+
5758
{#if !readonly}
5859
<div
5960
class="absolute right-1 top-1 flex items-center justify-center opacity-0 transition-opacity hover:opacity-100"

tools/server/webui/src/lib/components/app/chat/ChatForm.svelte

Lines changed: 0 additions & 237 deletions
This file was deleted.

0 commit comments

Comments
 (0)