Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amcdnl committed Aug 13, 2024
1 parent 5f4f414 commit c19957d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 106 deletions.
6 changes: 3 additions & 3 deletions src/ChatInput/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export const ChatInput = forwardRef<ChatInputRef, ChatInputProps>(({
const inputRef = useRef<HTMLTextAreaElement | null>(null);

useEffect(() => {
if(inputRef && inputRef.current) {
inputRef.current.focus()
if(inputRef.current) {
inputRef.current.focus();
}
}, [activeSessionId, inputRef])
}, [activeSessionId, inputRef]);

useImperativeHandle(ref, () => ({
focus: () => {
Expand Down
103 changes: 0 additions & 103 deletions stories/Console.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1093,106 +1093,3 @@ export const ImageFiles = () => {
</div>
);
};

export const Working = () => {
const [activeId, setActiveId] = useState<string>();
const [sessions, setSessions] = useState<Session[]>([]);
const [loading, setLoading] = useState<boolean>(false);
const [count, setCount] = useState<number>(sessions.length + 1);

const handleNewSession = () => {
const newId = count.toLocaleString();
setSessions([
...sessions,
{
id: newId,
title: `New Session #${newId}`,
createdAt: new Date(),
updatedAt: new Date(),
conversations: []
}
]);
setActiveId(newId);
setCount(count + 1);
};

const handleDelete = (id: string) => {
const updated = sessions.filter(s => s.id !== id);
setSessions([...updated]);
};

const handleNewMessage = (message: string) => {
setLoading(true);
const curr = sessions.find(s => s.id === activeId);
if (curr) {
const newMessage: Conversation = {
id: `${curr.id}-${curr.conversations.length}`,
question: message,
response: 'this is an example response',
createdAt: new Date(),
updatedAt: new Date()
};
const updated = {
...curr,
conversations: [...curr.conversations, newMessage]
};
setSessions([...sessions.filter(s => s.id !== activeId), updated]);
} else {
const newId = '1';
const newSession: Session = {
id: newId,
title: message.length > 28 ? `${message.substring(0, 25)}...` : message,
createdAt: new Date(),
updatedAt: new Date(),
conversations: [
{
id: `${newId}-1`,
question: message,
response: 'this is an example response',
createdAt: new Date(),
updatedAt: new Date()
}
]
};
setSessions([newSession]);
setActiveId(newId);
}
setLoading(false);
};

return (
<div
className="dark:bg-gray-950 bg-white"
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
padding: 20,
margin: 20,
borderRadius: 5
}}
>
<Chat
sessions={sessions}
activeSessionId={activeId}
isLoading={loading}
onNewSession={handleNewSession}
onSelectSession={setActiveId}
onDeleteSession={handleDelete}
onSendMessage={handleNewMessage}
>
<SessionsList>
<NewSessionButton />
<SessionGroups />
</SessionsList>
<SessionMessagePanel>
<SessionMessagesHeader />
<SessionMessages />
<ChatInput />
</SessionMessagePanel>
</Chat>
</div>
);
};

0 comments on commit c19957d

Please sign in to comment.