Skip to content

Commit 76cc42a

Browse files
Update components with UI and functionality improvements
1 parent fdec4d5 commit 76cc42a

File tree

12 files changed

+195
-842
lines changed

12 files changed

+195
-842
lines changed

components/chat-history.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
AlertDialogTitle,
2222
AlertDialogTrigger,
2323
} from '@/components/ui/alert-dialog'
24-
import { ChatSession } from '@/lib/chat-persistence'
2524
import {
2625
MessageSquare,
2726
Search,
@@ -36,6 +35,7 @@ import {
3635
Clock
3736
} from 'lucide-react'
3837
import { formatDistanceToNow } from 'date-fns'
38+
import { ChatSession } from '@/lib/database.types'
3939

4040
interface ChatHistoryProps {
4141
sessions: ChatSession[]
@@ -71,26 +71,26 @@ export function ChatHistory({
7171

7272
const groupedSessions = {
7373
today: filteredSessions.filter(session => {
74-
const sessionDate = new Date(session.lastActivity)
74+
const sessionDate = new Date(session.last_activity)
7575
const today = new Date()
7676
return sessionDate.toDateString() === today.toDateString()
7777
}),
7878
yesterday: filteredSessions.filter(session => {
79-
const sessionDate = new Date(session.lastActivity)
79+
const sessionDate = new Date(session.last_activity)
8080
const yesterday = new Date()
8181
yesterday.setDate(yesterday.getDate() - 1)
8282
return sessionDate.toDateString() === yesterday.toDateString()
8383
}),
8484
lastWeek: filteredSessions.filter(session => {
85-
const sessionDate = new Date(session.lastActivity)
85+
const sessionDate = new Date(session.last_activity)
8686
const weekAgo = new Date()
8787
weekAgo.setDate(weekAgo.getDate() - 7)
8888
const yesterday = new Date()
8989
yesterday.setDate(yesterday.getDate() - 1)
9090
return sessionDate > weekAgo && sessionDate < yesterday
9191
}),
9292
older: filteredSessions.filter(session => {
93-
const sessionDate = new Date(session.lastActivity)
93+
const sessionDate = new Date(session.last_activity)
9494
const weekAgo = new Date()
9595
weekAgo.setDate(weekAgo.getDate() - 7)
9696
return sessionDate <= weekAgo
@@ -106,27 +106,27 @@ export function ChatHistory({
106106
}
107107

108108
const startEditing = (session: ChatSession) => {
109-
setEditingSession(session.sessionId)
109+
setEditingSession(session.session_id)
110110
setEditTitle(session.title || '')
111111
}
112112

113113
const handleDeleteConfirm = () => {
114114
if (deletingSession) {
115-
onSessionDelete(deletingSession.sessionId)
115+
onSessionDelete(deletingSession.session_id)
116116
setDeletingSession(null)
117117
}
118118
}
119119

120120
const SessionItem = ({ session }: { session: ChatSession }) => {
121-
const isActive = session.sessionId === currentSessionId
122-
const isEditing = editingSession === session.sessionId
121+
const isActive = session.session_id === currentSessionId
122+
const isEditing = editingSession === session.session_id
123123

124124
return (
125125
<div
126126
className={`group flex items-center gap-2 p-2 rounded-lg cursor-pointer transition-colors hover:bg-accent ${
127127
isActive ? 'bg-accent border border-border' : ''
128128
}`}
129-
onClick={() => !isEditing && onSessionSelect(session.sessionId)}
129+
onClick={() => !isEditing && onSessionSelect(session.session_id)}
130130
>
131131
<MessageSquare className="h-4 w-4 text-muted-foreground shrink-0" />
132132

@@ -135,10 +135,10 @@ export function ChatHistory({
135135
<Input
136136
value={editTitle}
137137
onChange={(e) => setEditTitle(e.target.value)}
138-
onBlur={() => handleSessionRename(session.sessionId)}
138+
onBlur={() => handleSessionRename(session.session_id)}
139139
onKeyDown={(e) => {
140140
if (e.key === 'Enter') {
141-
handleSessionRename(session.sessionId)
141+
handleSessionRename(session.session_id)
142142
} else if (e.key === 'Escape') {
143143
setEditingSession(null)
144144
setEditTitle('')
@@ -155,9 +155,9 @@ export function ChatHistory({
155155
</div>
156156
<div className="flex items-center gap-1 text-xs text-muted-foreground">
157157
<Hash className="h-3 w-3" />
158-
<span>{session.messageCount}</span>
158+
<span>{session.message_count}</span>
159159
<Clock className="h-3 w-3 ml-1" />
160-
<span>{formatDistanceToNow(new Date(session.lastActivity), { addSuffix: true })}</span>
160+
<span>{formatDistanceToNow(new Date(session.last_activity), { addSuffix: true })}</span>
161161
</div>
162162
{(session.model || session.template) && (
163163
<div className="flex items-center gap-1 text-xs text-muted-foreground mt-1">
@@ -210,7 +210,7 @@ export function ChatHistory({
210210
</h3>
211211
<div className="space-y-1">
212212
{sessions.map(session => (
213-
<SessionItem key={session.sessionId} session={session} />
213+
<SessionItem key={session.session_id} session={session} />
214214
))}
215215
</div>
216216
</div>

components/chat-settings.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from './ui/dropdown-menu'
88
import { Input } from './ui/input'
99
import { Label } from './ui/label'
10+
import { Switch } from './ui/switch'
1011
import {
1112
Tooltip,
1213
TooltipContent,
@@ -21,11 +22,15 @@ export function ChatSettings({
2122
baseURLConfigurable,
2223
languageModel,
2324
onLanguageModelChange,
25+
useMorphApply,
26+
onUseMorphApplyChange,
2427
}: {
2528
apiKeyConfigurable: boolean
2629
baseURLConfigurable: boolean
2730
languageModel: LLMModelConfig
2831
onLanguageModelChange: (model: LLMModelConfig) => void
32+
useMorphApply?: boolean
33+
onUseMorphApplyChange?: (value: boolean) => void
2934
}) {
3035
return (
3136
<DropdownMenu>
@@ -199,6 +204,26 @@ export function ChatSettings({
199204
/>
200205
</div>
201206
</div>
207+
{onUseMorphApplyChange && (
208+
<>
209+
<DropdownMenuSeparator />
210+
<div className="flex items-center justify-between px-2 py-2">
211+
<div className="flex flex-col gap-0.5">
212+
<Label htmlFor="morph-apply" className="text-sm font-medium">
213+
Morph Apply
214+
</Label>
215+
<span className="text-xs text-muted-foreground">
216+
Edit existing code instead of regenerating
217+
</span>
218+
</div>
219+
<Switch
220+
id="morph-apply"
221+
checked={useMorphApply}
222+
onCheckedChange={onUseMorphApplyChange}
223+
/>
224+
</div>
225+
</>
226+
)}
202227
</DropdownMenuContent>
203228
</DropdownMenu>
204229
)

components/chat.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Message } from '@/lib/messages'
22
import { FragmentSchema } from '@/lib/schema'
33
import { ExecutionResult } from '@/lib/types'
44
import { DeepPartial } from 'ai'
5-
import { LoaderIcon, Terminal } from 'lucide-react'
5+
import { LoaderIcon, Terminal, Sparkles } from 'lucide-react'
66
import { useEffect } from 'react'
77

88
export function Chat({
@@ -17,6 +17,7 @@ export function Chat({
1717
result: ExecutionResult | undefined
1818
}) => void
1919
}) {
20+
2021
useEffect(() => {
2122
const chatContainer = document.getElementById('chat-container')
2223
if (chatContainer) {
@@ -30,6 +31,11 @@ export function Chat({
3031
id="chat-container"
3132
className="flex flex-col pb-12 gap-2 overflow-y-auto max-h-full"
3233
>
34+
{messages.length === 0 && !isLoading && (
35+
<div className="flex items-center justify-center h-full text-muted-foreground text-lg font-serif">
36+
</div>
37+
)}
38+
3339
{messages.map((message: Message, index: number) => (
3440
<div
3541
className={`flex flex-col px-4 shadow-sm whitespace-pre-wrap ${message.role !== 'user' ? 'bg-accent dark:bg-white/5 border text-accent-foreground dark:text-muted-foreground py-4 rounded-2xl gap-4 w-full' : 'bg-gradient-to-b from-black/5 to-black/10 dark:from-black/30 dark:to-black/50 py-2 rounded-xl gap-2 w-fit'} font-serif text-primary`}

components/code-view.tsx

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,30 @@
1-
import { useEffect, useRef } from 'react'
2-
import 'prismjs'
3-
import { readonlyEditor } from 'prism-code-editor/setups'
4-
import 'prism-code-editor/themes/prism-tomorrow.css'
5-
import 'prism-code-editor/layout.css'
6-
import 'prism-code-editor/scrollbar.css'
1+
// import "prismjs/plugins/line-numbers/prism-line-numbers.js";
2+
// import "prismjs/plugins/line-numbers/prism-line-numbers.css";
73
import './code-theme.css'
4+
import Prism from 'prismjs'
85
import 'prismjs/components/prism-javascript'
96
import 'prismjs/components/prism-jsx'
107
import 'prismjs/components/prism-python'
118
import 'prismjs/components/prism-tsx'
129
import 'prismjs/components/prism-typescript'
10+
import { useEffect } from 'react'
1311

1412
export function CodeView({ code, lang }: { code: string; lang: string }) {
15-
const editorRef = useRef<HTMLDivElement>(null)
16-
const editor = useRef<any>(null)
17-
18-
useEffect(() => {
19-
if (typeof window !== 'undefined') {
20-
if (editorRef.current && !editor.current) {
21-
editor.current = readonlyEditor(editorRef.current, {
22-
language: lang,
23-
value: code,
24-
wordWrap: true,
25-
theme: 'prism-tomorrow',
26-
})
27-
}
28-
}
29-
}, [lang, code])
30-
3113
useEffect(() => {
32-
if (editor.current) {
33-
editor.current.setOptions({ value: code })
34-
}
14+
Prism.highlightAll()
3515
}, [code])
3616

3717
return (
38-
<div
39-
ref={editorRef}
18+
<pre
4019
className="p-4 pt-2"
4120
style={{
4221
fontSize: 12,
4322
backgroundColor: 'transparent',
4423
borderRadius: 0,
4524
margin: 0,
46-
height: '100%',
4725
}}
48-
/>
26+
>
27+
<code className={`language-${lang}`}>{code}</code>
28+
</pre>
4929
)
50-
}
30+
}

0 commit comments

Comments
 (0)