-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#30 update Reablocks, fix focus on session change #37
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ import { | |
SessionMessagePanel, | ||
SessionMessagesHeader, | ||
ChatContext, | ||
SessionMessage | ||
SessionMessage, | ||
Conversation | ||
} from '../src'; | ||
import { | ||
Card, | ||
|
@@ -853,7 +854,6 @@ const CustomMessageResponse: FC<any> = ({ response }) => ( | |
|
||
const CustomMessageFile: FC<any> = ({ name, type }) => ( | ||
<Chip size="small" className="rounded-full border border-gray-700"> | ||
<>{console.log('boop', name, type)}</> | ||
{name || type} | ||
</Chip> | ||
); | ||
|
@@ -1093,3 +1093,106 @@ export const ImageFiles = () => { | |
</div> | ||
); | ||
}; | ||
|
||
export const Working = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whats this story? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's a "working" version - i made it to test the input stuff, but decided it might be useful to have something that functions even as state variables There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok i removed it from the main - we can add it back just needs a better name |
||
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> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inputRef
is a ref so it will always be there - so i don't think you need theif(inputRef
part.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will it? it could be
null
but i guess you could simplify withinputRef?.current