-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unified Conversation Page Refactor (#5766)
* tmp * Tmp * Fix broken scroll * Add Assistant browser container * Partially working * Improve new conversation * It works * Id * Not needed * Polish * ✂️ * Fix conversation title top bar * ✨ * ✂️ * ✨ ✨ * 🙈 * ✨ * Fix new conversation input bar animation * ✂️ * 🔙 * Fix assistant details action * Fix Try assistant drawer * Fix layout + conversation title glitch * Address comments from review * Remove `.slice()`. * Reduce navigation bar duration * Delight
- Loading branch information
Showing
14 changed files
with
731 additions
and
596 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
front/components/assistant/conversation/AssistantBrowserContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Page } from "@dust-tt/sparkle"; | ||
import type { | ||
LightAgentConfigurationType, | ||
WorkspaceType, | ||
} from "@dust-tt/types"; | ||
import { useCallback } from "react"; | ||
|
||
import { AssistantBrowser } from "@app/components/assistant/AssistantBrowser"; | ||
import { useProgressiveAgentConfigurations } from "@app/lib/swr"; | ||
import { classNames } from "@app/lib/utils"; | ||
|
||
interface AssistantBrowserContainerProps { | ||
onAgentConfigurationClick: (agent: LightAgentConfigurationType) => void; | ||
owner: WorkspaceType; | ||
setAssistantToMention: (agent: LightAgentConfigurationType) => void; | ||
} | ||
|
||
export function AssistantBrowserContainer({ | ||
onAgentConfigurationClick, | ||
owner, | ||
setAssistantToMention, | ||
}: AssistantBrowserContainerProps) { | ||
const { agentConfigurations, isLoading, mutateAgentConfigurations } = | ||
useProgressiveAgentConfigurations({ | ||
workspaceId: owner.sId, | ||
}); | ||
|
||
const handleAssistantClick = useCallback( | ||
// On click, scroll to the input bar and set the selected assistant. | ||
async (agent: LightAgentConfigurationType) => { | ||
const scrollContainerElement = document.getElementById( | ||
"assistant-input-header" | ||
); | ||
|
||
if (!scrollContainerElement) { | ||
console.log("Unexpected: scrollContainerElement not found"); | ||
return; | ||
} | ||
const scrollDistance = scrollContainerElement.getBoundingClientRect().top; | ||
|
||
// If the input bar is already in view, set the mention directly. We leave | ||
// a little margin, -2 instead of 0, since the autoscroll below can | ||
// sometimes scroll a bit over 0, to -0.3 or -0.5, in which case if there | ||
// is a clic on a visible assistant we still want this condition to | ||
// trigger. | ||
if (scrollDistance > -2) { | ||
return onAgentConfigurationClick(agent); | ||
} | ||
|
||
// Otherwise, scroll to the input bar and set the ref (mention will be set via intersection observer). | ||
scrollContainerElement.scrollIntoView({ behavior: "smooth" }); | ||
|
||
setAssistantToMention(agent); | ||
}, | ||
[setAssistantToMention, onAgentConfigurationClick] | ||
); | ||
|
||
return ( | ||
<div | ||
id="assistants-lists-container" | ||
className={classNames( | ||
"duration-400 flex h-full w-full flex-col gap-3 pt-9 transition-opacity", | ||
isLoading ? "opacity-0" : "opacity-100" | ||
)} | ||
> | ||
<div id="assistants-list-header" className="px-4"> | ||
<Page.SectionHeader title="Chat with..." /> | ||
</div> | ||
<AssistantBrowser | ||
owner={owner} | ||
agents={agentConfigurations} | ||
loadingStatus={isLoading ? "loading" : "finished"} | ||
handleAssistantClick={handleAssistantClick} | ||
mutateAgentConfigurations={mutateAgentConfigurations} | ||
/> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.