Dominic Elm
commited on
feat: rework ux for deleting chats (#46)
Browse files- packages/bolt/app/components/sidebar/HistoryItem.tsx +14 -30
- packages/bolt/app/components/sidebar/Menu.client.tsx +64 -11
- packages/bolt/app/components/sidebar/date-binning.ts +3 -3
- packages/bolt/app/components/ui/Dialog.tsx +133 -0
- packages/bolt/app/lib/persistence/db.ts +8 -8
- packages/bolt/app/lib/persistence/useChatHistory.ts +5 -5
- packages/bolt/app/styles/variables.scss +24 -0
- packages/bolt/package.json +1 -0
- packages/bolt/uno.config.ts +17 -0
- pnpm-lock.yaml +38 -0
packages/bolt/app/components/sidebar/HistoryItem.tsx
CHANGED
@@ -1,26 +1,16 @@
|
|
1 |
-
import
|
2 |
-
import {
|
3 |
-
import {
|
4 |
-
import { logger } from '~/utils/logger';
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
const [hovering, setHovering] = useState(false);
|
9 |
const hoverRef = useRef<HTMLDivElement>(null);
|
10 |
|
11 |
-
const deleteItem = useCallback((event: React.UIEvent) => {
|
12 |
-
event.preventDefault();
|
13 |
-
|
14 |
-
if (db) {
|
15 |
-
deleteId(db, item.id)
|
16 |
-
.then(() => loadEntries())
|
17 |
-
.catch((error) => {
|
18 |
-
toast.error('Failed to delete conversation');
|
19 |
-
logger.error(error);
|
20 |
-
});
|
21 |
-
}
|
22 |
-
}, []);
|
23 |
-
|
24 |
useEffect(() => {
|
25 |
let timeout: NodeJS.Timeout | undefined;
|
26 |
|
@@ -34,11 +24,6 @@ export function HistoryItem({ item, loadEntries }: { item: ChatHistory; loadEntr
|
|
34 |
|
35 |
function mouseLeave() {
|
36 |
setHovering(false);
|
37 |
-
|
38 |
-
// wait for animation to finish before unsetting
|
39 |
-
timeout = setTimeout(() => {
|
40 |
-
setRequestingDelete(false);
|
41 |
-
}, 200);
|
42 |
}
|
43 |
|
44 |
hoverRef.current?.addEventListener('mouseenter', mouseEnter);
|
@@ -59,18 +44,17 @@ export function HistoryItem({ item, loadEntries }: { item: ChatHistory; loadEntr
|
|
59 |
{item.description}
|
60 |
<div className="absolute right-0 z-1 top-0 bottom-0 bg-gradient-to-l from-bolt-elements-background-depth-2 group-hover:from-bolt-elements-background-depth-3 to-transparent w-10 flex justify-end group-hover:w-15 group-hover:from-45%">
|
61 |
{hovering && (
|
62 |
-
<div className="flex items-center p-1 text-bolt-elements-textSecondary hover:text-bolt-elements-
|
63 |
-
|
64 |
-
<button className="i-ph:check scale-110" onClick={deleteItem} />
|
65 |
-
) : (
|
66 |
<button
|
67 |
className="i-ph:trash scale-110"
|
68 |
onClick={(event) => {
|
|
|
69 |
event.preventDefault();
|
70 |
-
|
71 |
}}
|
72 |
/>
|
73 |
-
|
74 |
</div>
|
75 |
)}
|
76 |
</div>
|
|
|
1 |
+
import * as Dialog from '@radix-ui/react-dialog';
|
2 |
+
import { useEffect, useRef, useState } from 'react';
|
3 |
+
import { type ChatHistoryItem } from '~/lib/persistence';
|
|
|
4 |
|
5 |
+
interface HistoryItemProps {
|
6 |
+
item: ChatHistoryItem;
|
7 |
+
onDelete?: (event: React.UIEvent) => void;
|
8 |
+
}
|
9 |
+
|
10 |
+
export function HistoryItem({ item, onDelete }: HistoryItemProps) {
|
11 |
const [hovering, setHovering] = useState(false);
|
12 |
const hoverRef = useRef<HTMLDivElement>(null);
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
useEffect(() => {
|
15 |
let timeout: NodeJS.Timeout | undefined;
|
16 |
|
|
|
24 |
|
25 |
function mouseLeave() {
|
26 |
setHovering(false);
|
|
|
|
|
|
|
|
|
|
|
27 |
}
|
28 |
|
29 |
hoverRef.current?.addEventListener('mouseenter', mouseEnter);
|
|
|
44 |
{item.description}
|
45 |
<div className="absolute right-0 z-1 top-0 bottom-0 bg-gradient-to-l from-bolt-elements-background-depth-2 group-hover:from-bolt-elements-background-depth-3 to-transparent w-10 flex justify-end group-hover:w-15 group-hover:from-45%">
|
46 |
{hovering && (
|
47 |
+
<div className="flex items-center p-1 text-bolt-elements-textSecondary hover:text-bolt-elements-item-contentDanger">
|
48 |
+
<Dialog.Trigger asChild>
|
|
|
|
|
49 |
<button
|
50 |
className="i-ph:trash scale-110"
|
51 |
onClick={(event) => {
|
52 |
+
// we prevent the default so we don't trigger the anchor above
|
53 |
event.preventDefault();
|
54 |
+
onDelete?.(event);
|
55 |
}}
|
56 |
/>
|
57 |
+
</Dialog.Trigger>
|
58 |
</div>
|
59 |
)}
|
60 |
</div>
|
packages/bolt/app/components/sidebar/Menu.client.tsx
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
import { motion, type Variants } from 'framer-motion';
|
2 |
import { useCallback, useEffect, useRef, useState } from 'react';
|
3 |
import { toast } from 'react-toastify';
|
|
|
4 |
import { IconButton } from '~/components/ui/IconButton';
|
5 |
import { ThemeSwitch } from '~/components/ui/ThemeSwitch';
|
6 |
-
import { db, getAll, type
|
7 |
import { cubicEasingFn } from '~/utils/easings';
|
|
|
8 |
import { HistoryItem } from './HistoryItem';
|
9 |
import { binDates } from './date-binning';
|
10 |
|
@@ -29,10 +31,13 @@ const menuVariants = {
|
|
29 |
},
|
30 |
} satisfies Variants;
|
31 |
|
|
|
|
|
32 |
export function Menu() {
|
33 |
const menuRef = useRef<HTMLDivElement>(null);
|
34 |
-
const [list, setList] = useState<
|
35 |
const [open, setOpen] = useState(false);
|
|
|
36 |
|
37 |
const loadEntries = useCallback(() => {
|
38 |
if (db) {
|
@@ -43,6 +48,23 @@ export function Menu() {
|
|
43 |
}
|
44 |
}, []);
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
useEffect(() => {
|
47 |
if (open) {
|
48 |
loadEntries();
|
@@ -92,16 +114,47 @@ export function Menu() {
|
|
92 |
<div className="text-bolt-elements-textPrimary font-medium pl-6 pr-5 my-2">Your Chats</div>
|
93 |
<div className="flex-1 overflow-scroll pl-4 pr-5 pb-5">
|
94 |
{list.length === 0 && <div className="pl-2 text-bolt-elements-textTertiary">No previous conversations</div>}
|
95 |
-
{
|
96 |
-
|
97 |
-
<div className="
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
99 |
</div>
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
</div>
|
106 |
<div className="flex items-center border-t border-bolt-elements-borderColor p-4">
|
107 |
<a href="/logout">
|
|
|
1 |
import { motion, type Variants } from 'framer-motion';
|
2 |
import { useCallback, useEffect, useRef, useState } from 'react';
|
3 |
import { toast } from 'react-toastify';
|
4 |
+
import { Dialog, DialogButton, DialogDescription, DialogRoot, DialogTitle } from '~/components/ui/Dialog';
|
5 |
import { IconButton } from '~/components/ui/IconButton';
|
6 |
import { ThemeSwitch } from '~/components/ui/ThemeSwitch';
|
7 |
+
import { db, deleteId, getAll, type ChatHistoryItem } from '~/lib/persistence';
|
8 |
import { cubicEasingFn } from '~/utils/easings';
|
9 |
+
import { logger } from '~/utils/logger';
|
10 |
import { HistoryItem } from './HistoryItem';
|
11 |
import { binDates } from './date-binning';
|
12 |
|
|
|
31 |
},
|
32 |
} satisfies Variants;
|
33 |
|
34 |
+
type DialogContent = { type: 'delete'; item: ChatHistoryItem } | null;
|
35 |
+
|
36 |
export function Menu() {
|
37 |
const menuRef = useRef<HTMLDivElement>(null);
|
38 |
+
const [list, setList] = useState<ChatHistoryItem[]>([]);
|
39 |
const [open, setOpen] = useState(false);
|
40 |
+
const [dialogContent, setDialogContent] = useState<DialogContent>(null);
|
41 |
|
42 |
const loadEntries = useCallback(() => {
|
43 |
if (db) {
|
|
|
48 |
}
|
49 |
}, []);
|
50 |
|
51 |
+
const deleteItem = useCallback((event: React.UIEvent, item: ChatHistoryItem) => {
|
52 |
+
event.preventDefault();
|
53 |
+
|
54 |
+
if (db) {
|
55 |
+
deleteId(db, item.id)
|
56 |
+
.then(() => loadEntries())
|
57 |
+
.catch((error) => {
|
58 |
+
toast.error('Failed to delete conversation');
|
59 |
+
logger.error(error);
|
60 |
+
});
|
61 |
+
}
|
62 |
+
}, []);
|
63 |
+
|
64 |
+
const closeDialog = () => {
|
65 |
+
setDialogContent(null);
|
66 |
+
};
|
67 |
+
|
68 |
useEffect(() => {
|
69 |
if (open) {
|
70 |
loadEntries();
|
|
|
114 |
<div className="text-bolt-elements-textPrimary font-medium pl-6 pr-5 my-2">Your Chats</div>
|
115 |
<div className="flex-1 overflow-scroll pl-4 pr-5 pb-5">
|
116 |
{list.length === 0 && <div className="pl-2 text-bolt-elements-textTertiary">No previous conversations</div>}
|
117 |
+
<DialogRoot open={dialogContent !== null}>
|
118 |
+
{binDates(list).map(({ category, items }) => (
|
119 |
+
<div key={category} className="mt-4 first:mt-0 space-y-1">
|
120 |
+
<div className="text-bolt-elements-textTertiary sticky top-0 z-1 bg-bolt-elements-background-depth-2 pl-2 pt-2 pb-1">
|
121 |
+
{category}
|
122 |
+
</div>
|
123 |
+
{items.map((item) => (
|
124 |
+
<HistoryItem key={item.id} item={item} onDelete={() => setDialogContent({ type: 'delete', item })} />
|
125 |
+
))}
|
126 |
</div>
|
127 |
+
))}
|
128 |
+
<Dialog onBackdrop={closeDialog} onClose={closeDialog}>
|
129 |
+
{dialogContent?.type === 'delete' && (
|
130 |
+
<>
|
131 |
+
<DialogTitle>Delete Chat?</DialogTitle>
|
132 |
+
<DialogDescription asChild>
|
133 |
+
<div>
|
134 |
+
<p>
|
135 |
+
You are about to delete <strong>{dialogContent.item.description}</strong>.
|
136 |
+
</p>
|
137 |
+
<p className="mt-1">Are you sure you want to delete this chat?</p>
|
138 |
+
</div>
|
139 |
+
</DialogDescription>
|
140 |
+
<div className="px-5 pb-4 bg-bolt-elements-background-depth-2 flex gap-2 justify-end">
|
141 |
+
<DialogButton type="secondary" onClick={closeDialog}>
|
142 |
+
Cancel
|
143 |
+
</DialogButton>
|
144 |
+
<DialogButton
|
145 |
+
type="danger"
|
146 |
+
onClick={(event) => {
|
147 |
+
deleteItem(event, dialogContent.item);
|
148 |
+
closeDialog();
|
149 |
+
}}
|
150 |
+
>
|
151 |
+
Delete
|
152 |
+
</DialogButton>
|
153 |
+
</div>
|
154 |
+
</>
|
155 |
+
)}
|
156 |
+
</Dialog>
|
157 |
+
</DialogRoot>
|
158 |
</div>
|
159 |
<div className="flex items-center border-t border-bolt-elements-borderColor p-4">
|
160 |
<a href="/logout">
|
packages/bolt/app/components/sidebar/date-binning.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import { format, isAfter, isThisWeek, isThisYear, isToday, isYesterday, subDays } from 'date-fns';
|
2 |
-
import type {
|
3 |
|
4 |
-
type Bin = { category: string; items:
|
5 |
|
6 |
-
export function binDates(_list:
|
7 |
const list = _list.toSorted((a, b) => Date.parse(b.timestamp) - Date.parse(a.timestamp));
|
8 |
|
9 |
const binLookup: Record<string, Bin> = {};
|
|
|
1 |
import { format, isAfter, isThisWeek, isThisYear, isToday, isYesterday, subDays } from 'date-fns';
|
2 |
+
import type { ChatHistoryItem } from '~/lib/persistence';
|
3 |
|
4 |
+
type Bin = { category: string; items: ChatHistoryItem[] };
|
5 |
|
6 |
+
export function binDates(_list: ChatHistoryItem[]) {
|
7 |
const list = _list.toSorted((a, b) => Date.parse(b.timestamp) - Date.parse(a.timestamp));
|
8 |
|
9 |
const binLookup: Record<string, Bin> = {};
|
packages/bolt/app/components/ui/Dialog.tsx
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import * as RadixDialog from '@radix-ui/react-dialog';
|
2 |
+
import { motion, type Variants } from 'framer-motion';
|
3 |
+
import React, { memo, type ReactNode } from 'react';
|
4 |
+
import { classNames } from '~/utils/classNames';
|
5 |
+
import { cubicEasingFn } from '~/utils/easings';
|
6 |
+
import { IconButton } from './IconButton';
|
7 |
+
|
8 |
+
export { Close as DialogClose, Root as DialogRoot } from '@radix-ui/react-dialog';
|
9 |
+
|
10 |
+
const transition = {
|
11 |
+
duration: 0.15,
|
12 |
+
ease: cubicEasingFn,
|
13 |
+
};
|
14 |
+
|
15 |
+
export const dialogBackdropVariants = {
|
16 |
+
closed: {
|
17 |
+
opacity: 0,
|
18 |
+
transition,
|
19 |
+
},
|
20 |
+
open: {
|
21 |
+
opacity: 1,
|
22 |
+
transition,
|
23 |
+
},
|
24 |
+
} satisfies Variants;
|
25 |
+
|
26 |
+
export const dialogVariants = {
|
27 |
+
closed: {
|
28 |
+
x: '-50%',
|
29 |
+
y: '-40%',
|
30 |
+
scale: 0.96,
|
31 |
+
opacity: 0,
|
32 |
+
transition,
|
33 |
+
},
|
34 |
+
open: {
|
35 |
+
x: '-50%',
|
36 |
+
y: '-50%',
|
37 |
+
scale: 1,
|
38 |
+
opacity: 1,
|
39 |
+
transition,
|
40 |
+
},
|
41 |
+
} satisfies Variants;
|
42 |
+
|
43 |
+
interface DialogButtonProps {
|
44 |
+
type: 'primary' | 'secondary' | 'danger';
|
45 |
+
children: ReactNode;
|
46 |
+
onClick?: (event: React.UIEvent) => void;
|
47 |
+
}
|
48 |
+
|
49 |
+
export const DialogButton = memo(({ type, children, onClick }: DialogButtonProps) => {
|
50 |
+
return (
|
51 |
+
<button
|
52 |
+
className={classNames(
|
53 |
+
'inline-flex h-[35px] items-center justify-center rounded-lg px-4 text-sm leading-none focus:outline-none',
|
54 |
+
{
|
55 |
+
'bg-bolt-elements-button-primary-background text-bolt-elements-button-primary-text hover:bg-bolt-elements-button-primary-backgroundHover':
|
56 |
+
type === 'primary',
|
57 |
+
'bg-bolt-elements-button-secondary-background text-bolt-elements-button-secondary-text hover:bg-bolt-elements-button-secondary-backgroundHover':
|
58 |
+
type === 'secondary',
|
59 |
+
'bg-bolt-elements-button-danger-background text-bolt-elements-button-danger-text hover:bg-bolt-elements-button-danger-backgroundHover':
|
60 |
+
type === 'danger',
|
61 |
+
},
|
62 |
+
)}
|
63 |
+
onClick={onClick}
|
64 |
+
>
|
65 |
+
{children}
|
66 |
+
</button>
|
67 |
+
);
|
68 |
+
});
|
69 |
+
|
70 |
+
export const DialogTitle = memo(({ className, children, ...props }: RadixDialog.DialogTitleProps) => {
|
71 |
+
return (
|
72 |
+
<RadixDialog.Title
|
73 |
+
className={classNames(
|
74 |
+
'px-5 py-4 flex items-center justify-between border-b border-bolt-elements-borderColor text-lg font-semibold leading-6 text-bolt-elements-textPrimary',
|
75 |
+
className,
|
76 |
+
)}
|
77 |
+
{...props}
|
78 |
+
>
|
79 |
+
{children}
|
80 |
+
</RadixDialog.Title>
|
81 |
+
);
|
82 |
+
});
|
83 |
+
|
84 |
+
export const DialogDescription = memo(({ className, children, ...props }: RadixDialog.DialogDescriptionProps) => {
|
85 |
+
return (
|
86 |
+
<RadixDialog.Description
|
87 |
+
className={classNames('px-5 py-4 text-bolt-elements-textPrimary text-md', className)}
|
88 |
+
{...props}
|
89 |
+
>
|
90 |
+
{children}
|
91 |
+
</RadixDialog.Description>
|
92 |
+
);
|
93 |
+
});
|
94 |
+
|
95 |
+
interface DialogProps {
|
96 |
+
children: ReactNode | ReactNode[];
|
97 |
+
className?: string;
|
98 |
+
onBackdrop?: (event: React.UIEvent) => void;
|
99 |
+
onClose?: (event: React.UIEvent) => void;
|
100 |
+
}
|
101 |
+
|
102 |
+
export const Dialog = memo(({ className, children, onBackdrop, onClose }: DialogProps) => {
|
103 |
+
return (
|
104 |
+
<RadixDialog.Portal>
|
105 |
+
<RadixDialog.Overlay onClick={onBackdrop} asChild>
|
106 |
+
<motion.div
|
107 |
+
className="bg-black/50 fixed inset-0 z-max"
|
108 |
+
initial="closed"
|
109 |
+
animate="open"
|
110 |
+
exit="closed"
|
111 |
+
variants={dialogBackdropVariants}
|
112 |
+
/>
|
113 |
+
</RadixDialog.Overlay>
|
114 |
+
<RadixDialog.Content asChild>
|
115 |
+
<motion.div
|
116 |
+
className={classNames(
|
117 |
+
'fixed top-[50%] left-[50%] z-max max-h-[85vh] w-[90vw] max-w-[450px] translate-x-[-50%] translate-y-[-50%] border border-bolt-elements-borderColor rounded-lg bg-bolt-elements-background-depth-2 shadow-lg focus:outline-none overflow-hidden',
|
118 |
+
className,
|
119 |
+
)}
|
120 |
+
initial="closed"
|
121 |
+
animate="open"
|
122 |
+
exit="closed"
|
123 |
+
variants={dialogVariants}
|
124 |
+
>
|
125 |
+
{children}
|
126 |
+
<RadixDialog.Close asChild onClick={onClose}>
|
127 |
+
<IconButton icon="i-ph:x" className="absolute top-[10px] right-[10px]" />
|
128 |
+
</RadixDialog.Close>
|
129 |
+
</motion.div>
|
130 |
+
</RadixDialog.Content>
|
131 |
+
</RadixDialog.Portal>
|
132 |
+
);
|
133 |
+
});
|
packages/bolt/app/lib/persistence/db.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import type { Message } from 'ai';
|
2 |
-
import type { ChatHistory } from './useChatHistory';
|
3 |
import { createScopedLogger } from '~/utils/logger';
|
|
|
4 |
|
5 |
const logger = createScopedLogger('ChatHistory');
|
6 |
|
@@ -30,13 +30,13 @@ export async function openDatabase(): Promise<IDBDatabase | undefined> {
|
|
30 |
});
|
31 |
}
|
32 |
|
33 |
-
export async function getAll(db: IDBDatabase): Promise<
|
34 |
return new Promise((resolve, reject) => {
|
35 |
const transaction = db.transaction('chats', 'readonly');
|
36 |
const store = transaction.objectStore('chats');
|
37 |
const request = store.getAll();
|
38 |
|
39 |
-
request.onsuccess = () => resolve(request.result as
|
40 |
request.onerror = () => reject(request.error);
|
41 |
});
|
42 |
}
|
@@ -65,29 +65,29 @@ export async function setMessages(
|
|
65 |
});
|
66 |
}
|
67 |
|
68 |
-
export async function getMessages(db: IDBDatabase, id: string): Promise<
|
69 |
return (await getMessagesById(db, id)) || (await getMessagesByUrlId(db, id));
|
70 |
}
|
71 |
|
72 |
-
export async function getMessagesByUrlId(db: IDBDatabase, id: string): Promise<
|
73 |
return new Promise((resolve, reject) => {
|
74 |
const transaction = db.transaction('chats', 'readonly');
|
75 |
const store = transaction.objectStore('chats');
|
76 |
const index = store.index('urlId');
|
77 |
const request = index.get(id);
|
78 |
|
79 |
-
request.onsuccess = () => resolve(request.result as
|
80 |
request.onerror = () => reject(request.error);
|
81 |
});
|
82 |
}
|
83 |
|
84 |
-
export async function getMessagesById(db: IDBDatabase, id: string): Promise<
|
85 |
return new Promise((resolve, reject) => {
|
86 |
const transaction = db.transaction('chats', 'readonly');
|
87 |
const store = transaction.objectStore('chats');
|
88 |
const request = store.get(id);
|
89 |
|
90 |
-
request.onsuccess = () => resolve(request.result as
|
91 |
request.onerror = () => reject(request.error);
|
92 |
});
|
93 |
}
|
|
|
1 |
import type { Message } from 'ai';
|
|
|
2 |
import { createScopedLogger } from '~/utils/logger';
|
3 |
+
import type { ChatHistoryItem } from './useChatHistory';
|
4 |
|
5 |
const logger = createScopedLogger('ChatHistory');
|
6 |
|
|
|
30 |
});
|
31 |
}
|
32 |
|
33 |
+
export async function getAll(db: IDBDatabase): Promise<ChatHistoryItem[]> {
|
34 |
return new Promise((resolve, reject) => {
|
35 |
const transaction = db.transaction('chats', 'readonly');
|
36 |
const store = transaction.objectStore('chats');
|
37 |
const request = store.getAll();
|
38 |
|
39 |
+
request.onsuccess = () => resolve(request.result as ChatHistoryItem[]);
|
40 |
request.onerror = () => reject(request.error);
|
41 |
});
|
42 |
}
|
|
|
65 |
});
|
66 |
}
|
67 |
|
68 |
+
export async function getMessages(db: IDBDatabase, id: string): Promise<ChatHistoryItem> {
|
69 |
return (await getMessagesById(db, id)) || (await getMessagesByUrlId(db, id));
|
70 |
}
|
71 |
|
72 |
+
export async function getMessagesByUrlId(db: IDBDatabase, id: string): Promise<ChatHistoryItem> {
|
73 |
return new Promise((resolve, reject) => {
|
74 |
const transaction = db.transaction('chats', 'readonly');
|
75 |
const store = transaction.objectStore('chats');
|
76 |
const index = store.index('urlId');
|
77 |
const request = index.get(id);
|
78 |
|
79 |
+
request.onsuccess = () => resolve(request.result as ChatHistoryItem);
|
80 |
request.onerror = () => reject(request.error);
|
81 |
});
|
82 |
}
|
83 |
|
84 |
+
export async function getMessagesById(db: IDBDatabase, id: string): Promise<ChatHistoryItem> {
|
85 |
return new Promise((resolve, reject) => {
|
86 |
const transaction = db.transaction('chats', 'readonly');
|
87 |
const store = transaction.objectStore('chats');
|
88 |
const request = store.get(id);
|
89 |
|
90 |
+
request.onsuccess = () => resolve(request.result as ChatHistoryItem);
|
91 |
request.onerror = () => reject(request.error);
|
92 |
});
|
93 |
}
|
packages/bolt/app/lib/persistence/useChatHistory.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
-
import {
|
2 |
-
import { useState, useEffect } from 'react';
|
3 |
import type { Message } from 'ai';
|
4 |
-
import {
|
5 |
import { toast } from 'react-toastify';
|
|
|
6 |
import { workbenchStore } from '~/lib/stores/workbench';
|
7 |
-
import {
|
8 |
|
9 |
-
export interface
|
10 |
id: string;
|
11 |
urlId?: string;
|
12 |
description?: string;
|
|
|
1 |
+
import { useLoaderData, useNavigate } from '@remix-run/react';
|
|
|
2 |
import type { Message } from 'ai';
|
3 |
+
import { useEffect, useState } from 'react';
|
4 |
import { toast } from 'react-toastify';
|
5 |
+
import { AnalyticsAction, sendAnalyticsEvent } from '~/lib/analytics';
|
6 |
import { workbenchStore } from '~/lib/stores/workbench';
|
7 |
+
import { getMessages, getNextId, getUrlId, openDatabase, setMessages } from './db';
|
8 |
|
9 |
+
export interface ChatHistoryItem {
|
10 |
id: string;
|
11 |
urlId?: string;
|
12 |
description?: string;
|
packages/bolt/app/styles/variables.scss
CHANGED
@@ -16,6 +16,18 @@
|
|
16 |
--bolt-elements-code-background: theme('colors.gray.100');
|
17 |
--bolt-elements-code-text: theme('colors.gray.950');
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
--bolt-elements-item-contentDefault: theme('colors.alpha.gray.50');
|
20 |
--bolt-elements-item-contentActive: theme('colors.gray.950');
|
21 |
--bolt-elements-item-contentAccent: theme('colors.accent.700');
|
@@ -110,6 +122,18 @@
|
|
110 |
--bolt-elements-code-background: theme('colors.gray.800');
|
111 |
--bolt-elements-code-text: theme('colors.white');
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
--bolt-elements-item-contentDefault: theme('colors.alpha.white.50');
|
114 |
--bolt-elements-item-contentActive: theme('colors.white');
|
115 |
--bolt-elements-item-contentAccent: theme('colors.accent.500');
|
|
|
16 |
--bolt-elements-code-background: theme('colors.gray.100');
|
17 |
--bolt-elements-code-text: theme('colors.gray.950');
|
18 |
|
19 |
+
--bolt-elements-button-primary-background: theme('colors.alpha.accent.10');
|
20 |
+
--bolt-elements-button-primary-backgroundHover: theme('colors.alpha.accent.20');
|
21 |
+
--bolt-elements-button-primary-text: theme('colors.accent.500');
|
22 |
+
|
23 |
+
--bolt-elements-button-secondary-background: theme('colors.alpha.gray.5');
|
24 |
+
--bolt-elements-button-secondary-backgroundHover: theme('colors.alpha.gray.10');
|
25 |
+
--bolt-elements-button-secondary-text: theme('colors.gray.950');
|
26 |
+
|
27 |
+
--bolt-elements-button-danger-background: theme('colors.alpha.red.10');
|
28 |
+
--bolt-elements-button-danger-backgroundHover: theme('colors.alpha.red.20');
|
29 |
+
--bolt-elements-button-danger-text: theme('colors.red.500');
|
30 |
+
|
31 |
--bolt-elements-item-contentDefault: theme('colors.alpha.gray.50');
|
32 |
--bolt-elements-item-contentActive: theme('colors.gray.950');
|
33 |
--bolt-elements-item-contentAccent: theme('colors.accent.700');
|
|
|
122 |
--bolt-elements-code-background: theme('colors.gray.800');
|
123 |
--bolt-elements-code-text: theme('colors.white');
|
124 |
|
125 |
+
--bolt-elements-button-primary-background: theme('colors.alpha.accent.10');
|
126 |
+
--bolt-elements-button-primary-backgroundHover: theme('colors.alpha.accent.20');
|
127 |
+
--bolt-elements-button-primary-text: theme('colors.accent.500');
|
128 |
+
|
129 |
+
--bolt-elements-button-secondary-background: theme('colors.alpha.white.5');
|
130 |
+
--bolt-elements-button-secondary-backgroundHover: theme('colors.alpha.white.10');
|
131 |
+
--bolt-elements-button-secondary-text: theme('colors.white');
|
132 |
+
|
133 |
+
--bolt-elements-button-danger-background: theme('colors.alpha.red.10');
|
134 |
+
--bolt-elements-button-danger-backgroundHover: theme('colors.alpha.red.20');
|
135 |
+
--bolt-elements-button-danger-text: theme('colors.red.500');
|
136 |
+
|
137 |
--bolt-elements-item-contentDefault: theme('colors.alpha.white.50');
|
138 |
--bolt-elements-item-contentActive: theme('colors.white');
|
139 |
--bolt-elements-item-contentAccent: theme('colors.accent.500');
|
packages/bolt/package.json
CHANGED
@@ -36,6 +36,7 @@
|
|
36 |
"@iconify-json/svg-spinners": "^1.1.2",
|
37 |
"@lezer/highlight": "^1.2.0",
|
38 |
"@nanostores/react": "^0.7.2",
|
|
|
39 |
"@radix-ui/react-dropdown-menu": "^2.1.1",
|
40 |
"@remix-run/cloudflare": "^2.10.2",
|
41 |
"@remix-run/cloudflare-pages": "^2.10.2",
|
|
|
36 |
"@iconify-json/svg-spinners": "^1.1.2",
|
37 |
"@lezer/highlight": "^1.2.0",
|
38 |
"@nanostores/react": "^0.7.2",
|
39 |
+
"@radix-ui/react-dialog": "^1.1.1",
|
40 |
"@radix-ui/react-dropdown-menu": "^2.1.1",
|
41 |
"@remix-run/cloudflare": "^2.10.2",
|
42 |
"@remix-run/cloudflare-pages": "^2.10.2",
|
packages/bolt/uno.config.ts
CHANGED
@@ -133,6 +133,23 @@ export default defineConfig({
|
|
133 |
background: 'var(--bolt-elements-code-background)',
|
134 |
text: 'var(--bolt-elements-code-text)',
|
135 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
item: {
|
137 |
contentDefault: 'var(--bolt-elements-item-contentDefault)',
|
138 |
contentActive: 'var(--bolt-elements-item-contentActive)',
|
|
|
133 |
background: 'var(--bolt-elements-code-background)',
|
134 |
text: 'var(--bolt-elements-code-text)',
|
135 |
},
|
136 |
+
button: {
|
137 |
+
primary: {
|
138 |
+
background: 'var(--bolt-elements-button-primary-background)',
|
139 |
+
backgroundHover: 'var(--bolt-elements-button-primary-backgroundHover)',
|
140 |
+
text: 'var(--bolt-elements-button-primary-text)',
|
141 |
+
},
|
142 |
+
secondary: {
|
143 |
+
background: 'var(--bolt-elements-button-secondary-background)',
|
144 |
+
backgroundHover: 'var(--bolt-elements-button-secondary-backgroundHover)',
|
145 |
+
text: 'var(--bolt-elements-button-secondary-text)',
|
146 |
+
},
|
147 |
+
danger: {
|
148 |
+
background: 'var(--bolt-elements-button-danger-background)',
|
149 |
+
backgroundHover: 'var(--bolt-elements-button-danger-backgroundHover)',
|
150 |
+
text: 'var(--bolt-elements-button-danger-text)',
|
151 |
+
},
|
152 |
+
},
|
153 |
item: {
|
154 |
contentDefault: 'var(--bolt-elements-item-contentDefault)',
|
155 |
contentActive: 'var(--bolt-elements-item-contentActive)',
|
pnpm-lock.yaml
CHANGED
@@ -95,6 +95,9 @@ importers:
|
|
95 |
'@nanostores/react':
|
96 |
specifier: ^0.7.2
|
97 |
version: 0.7.2([email protected])([email protected])
|
|
|
|
|
|
|
98 |
'@radix-ui/react-dropdown-menu':
|
99 |
specifier: ^2.1.1
|
100 |
version: 2.1.1(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])
|
@@ -1296,6 +1299,19 @@ packages:
|
|
1296 |
'@types/react':
|
1297 |
optional: true
|
1298 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1299 |
'@radix-ui/[email protected]':
|
1300 |
resolution: {integrity: sha512-BUuBvgThEiAXh2DWu93XsT+a3aWrGqolGlqqw5VU1kG7p/ZH2cuDlM1sRLNnY3QcBS69UIz2mcKhMxDsdewhjg==}
|
1301 |
peerDependencies:
|
@@ -6597,6 +6613,28 @@ snapshots:
|
|
6597 |
optionalDependencies:
|
6598 |
'@types/react': 18.3.3
|
6599 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6600 |
'@radix-ui/[email protected](@types/[email protected])([email protected])':
|
6601 |
dependencies:
|
6602 |
react: 18.3.1
|
|
|
95 |
'@nanostores/react':
|
96 |
specifier: ^0.7.2
|
97 |
version: 0.7.2([email protected])([email protected])
|
98 |
+
'@radix-ui/react-dialog':
|
99 |
+
specifier: ^1.1.1
|
100 |
+
version: 1.1.1(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])
|
101 |
'@radix-ui/react-dropdown-menu':
|
102 |
specifier: ^2.1.1
|
103 |
version: 2.1.1(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])
|
|
|
1299 |
'@types/react':
|
1300 |
optional: true
|
1301 |
|
1302 |
+
'@radix-ui/[email protected]':
|
1303 |
+
resolution: {integrity: sha512-zysS+iU4YP3STKNS6USvFVqI4qqx8EpiwmT5TuCApVEBca+eRCbONi4EgzfNSuVnOXvC5UPHHMjs8RXO6DH9Bg==}
|
1304 |
+
peerDependencies:
|
1305 |
+
'@types/react': '*'
|
1306 |
+
'@types/react-dom': '*'
|
1307 |
+
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
|
1308 |
+
react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
|
1309 |
+
peerDependenciesMeta:
|
1310 |
+
'@types/react':
|
1311 |
+
optional: true
|
1312 |
+
'@types/react-dom':
|
1313 |
+
optional: true
|
1314 |
+
|
1315 |
'@radix-ui/[email protected]':
|
1316 |
resolution: {integrity: sha512-BUuBvgThEiAXh2DWu93XsT+a3aWrGqolGlqqw5VU1kG7p/ZH2cuDlM1sRLNnY3QcBS69UIz2mcKhMxDsdewhjg==}
|
1317 |
peerDependencies:
|
|
|
6613 |
optionalDependencies:
|
6614 |
'@types/react': 18.3.3
|
6615 |
|
6616 |
+
'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':
|
6617 |
+
dependencies:
|
6618 |
+
'@radix-ui/primitive': 1.1.0
|
6619 |
+
'@radix-ui/react-compose-refs': 1.1.0(@types/[email protected])([email protected])
|
6620 |
+
'@radix-ui/react-context': 1.1.0(@types/[email protected])([email protected])
|
6621 |
+
'@radix-ui/react-dismissable-layer': 1.1.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])
|
6622 |
+
'@radix-ui/react-focus-guards': 1.1.0(@types/[email protected])([email protected])
|
6623 |
+
'@radix-ui/react-focus-scope': 1.1.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])
|
6624 |
+
'@radix-ui/react-id': 1.1.0(@types/[email protected])([email protected])
|
6625 |
+
'@radix-ui/react-portal': 1.1.1(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])
|
6626 |
+
'@radix-ui/react-presence': 1.1.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])
|
6627 |
+
'@radix-ui/react-primitive': 2.0.0(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])
|
6628 |
+
'@radix-ui/react-slot': 1.1.0(@types/[email protected])([email protected])
|
6629 |
+
'@radix-ui/react-use-controllable-state': 1.1.0(@types/[email protected])([email protected])
|
6630 |
+
aria-hidden: 1.2.4
|
6631 |
+
react: 18.3.1
|
6632 |
+
react-dom: 18.3.1([email protected])
|
6633 |
+
react-remove-scroll: 2.5.7(@types/[email protected])([email protected])
|
6634 |
+
optionalDependencies:
|
6635 |
+
'@types/react': 18.3.3
|
6636 |
+
'@types/react-dom': 18.3.0
|
6637 |
+
|
6638 |
'@radix-ui/[email protected](@types/[email protected])([email protected])':
|
6639 |
dependencies:
|
6640 |
react: 18.3.1
|