Skip to content

Commit

Permalink
new message id on edits
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlu1248 committed Jun 20, 2024
1 parent e72a2dc commit 50ee8d5
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions sweep_chat/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,11 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
}, [messagesId, messages.length])

useEffect(() => {
console.log(defaultMessageId)
if (defaultMessageId) {
console.log('loading message', messagesId)
if (messagesId) {
;(async () => {
const response = await authorizedFetch(
`/backend/messages/load/${defaultMessageId}`,
`/backend/messages/load/${messagesId}`,
{
method: 'GET',
}
Expand Down Expand Up @@ -957,7 +957,7 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
}
})()
}
}, [defaultMessageId])
}, [messagesId])

useEffect(() => {
if (messagesContainerRef.current) {
Expand Down Expand Up @@ -1034,6 +1034,7 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
currentRepoName: string,
currentMessages: Message[],
currentSnippets: Snippet[],
currentMessagesId: string,
currentUserMentionedPullRequest: PullRequest | null = null,
currentUserMentionedPullRequests: PullRequest[] | null = null,
currentCommitToPR: boolean = false,
Expand All @@ -1056,7 +1057,7 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
repo_name: currentRepoName || repoName,
messages: currentMessages || messages,
snippets: currentSnippets || snippets,
message_id: messagesId || '',
message_id: currentMessagesId || '',
original_code_suggestions:
currentOriginalCodeSuggestions || originalSuggestedChanges,
code_suggestions: currentSuggestedChanges || originalSuggestedChanges,
Expand All @@ -1073,7 +1074,7 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
const saveData = await saveResponse.json()
if (saveData.status == 'success') {
const { message_id } = saveData
if (!messagesId && message_id) {
if (!currentMessagesId && message_id) {
setMessagesId(message_id)
const updatedUrl = `/c/${message_id}`
window.history.pushState({}, '', updatedUrl)
Expand All @@ -1089,6 +1090,7 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
repoName,
messages,
snippets,
currentMessagesId,
userMentionedPullRequest,
userMentionedPullRequests,
commitToPR,
Expand All @@ -1103,6 +1105,7 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
repoName,
messages,
snippets,
currentMessagesId,
userMentionedPullRequest,
userMentionedPullRequests,
commitToPR,
Expand All @@ -1120,12 +1123,12 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
) // can tune these timeouts

useEffect(() => {
console.log('pr', pullRequest)
if (messages.length > 0 && snippets.length > 0) {
debouncedSave(
repoName,
messages,
snippets,
messagesId,
userMentionedPullRequest,
userMentionedPullRequests,
commitToPR,
Expand All @@ -1140,6 +1143,7 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
repoName,
messages,
snippets,
messagesId,
userMentionedPullRequest,
userMentionedPullRequests,
commitToPR,
Expand Down Expand Up @@ -1274,7 +1278,6 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
}))
setSuggestedChanges(currentCodeSuggestions)
}
console.log(isStream.current)
if (!isStream.current) {
currentCodeSuggestions = currentCodeSuggestions.map((suggestion) =>
suggestion.state == 'done'
Expand All @@ -1286,7 +1289,6 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
state: 'error',
}
)
console.log(currentCodeSuggestions)
setSuggestedChanges(currentCodeSuggestions)
}
} catch (e: any) {
Expand Down Expand Up @@ -1748,7 +1750,7 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
)}
<div
className={`mb-4 w-full flex items-center ${
repoNameValid || defaultMessageId ? '' : 'grow'
repoNameValid || messagesId ? '' : 'grow'
}`}
>
<AutoComplete
Expand Down Expand Up @@ -1921,7 +1923,7 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
<div
ref={messagesContainerRef}
className="w-full border flex-grow mb-4 p-4 max-h-[90%] overflow-y-auto rounded-xl"
hidden={!repoNameValid && !defaultMessageId}
hidden={!repoNameValid && !messagesId}
>
{messages.length > 0
? messages.map((message, index) => (
Expand Down Expand Up @@ -1970,6 +1972,8 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
setMessages(newMessages)
setIsCreatingPullRequest(false)
if (index == 0) {
window.history.pushState({}, "", "/")
setMessagesId("")
setOriginalSuggestedChanges([])
setSuggestedChanges([])
setIsProcessingSuggestedChanges(false)
Expand Down Expand Up @@ -2333,7 +2337,7 @@ function App({ defaultMessageId = '' }: { defaultMessageId?: string }) {
</div>
)}
</div>
{(repoNameValid || defaultMessageId) && (
{(repoNameValid || messagesId) && (
<div className={`flex w-full`}>
{isStream.current ? (
<Button
Expand Down

0 comments on commit 50ee8d5

Please sign in to comment.