Skip to content

Commit

Permalink
Ext: Polish - Better loading state input bar + Desifn feedback (#8999)
Browse files Browse the repository at this point in the history
* Ext: Polish - Better loading state input bar + Desifn feedback

* Apply feedback
  • Loading branch information
PopDaph authored Nov 28, 2024
1 parent 66e190e commit 149b1a3
Show file tree
Hide file tree
Showing 16 changed files with 161 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function AssistantFavorites() {
<div className="h-full w-full pt-2 pb-12">
<Page.SectionHeader title="Favorites" />
{hasFavorites ? (
<div className="relative grid w-full grid-cols-1 sm:grid-cols-2 gap-2">
<div className="relative grid w-full grid-cols-2 gap-2">
{agentConfigurations.map(
({ sId, name, pictureUrl, lastAuthors, description }) => (
<AssistantPreview
Expand Down
4 changes: 3 additions & 1 deletion extension/app/src/components/assistants/AssistantPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ export function AssistantPicker({
onItemClick,
pickerButton,
size = "md",
isLoading,
}: {
owner: LightWorkspaceType;
assistants: LightAgentConfigurationType[];
onItemClick: (assistant: LightAgentConfigurationType) => void;
pickerButton?: React.ReactNode;
size?: "xs" | "sm" | "md";
isLoading?: boolean;
}) {
const [searchText, setSearchText] = useState("");
const [searchedAssistants, setSearchedAssistants] = useState<
Expand Down Expand Up @@ -56,6 +58,7 @@ export function AssistantPicker({
isSelect
size={size}
tooltip="Pick an assistant"
disabled={isLoading ?? false}
/>
)}
</DropdownMenuTrigger>
Expand All @@ -64,7 +67,6 @@ export function AssistantPicker({
ref={searchbarRef}
placeholder="Search"
name="input"
size="xs"
value={searchText}
onChange={setSearchText}
onKeyDown={(e) => {
Expand Down
8 changes: 1 addition & 7 deletions extension/app/src/components/conversation/AgentMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import {
isWebsearchActionType,
removeNulls,
} from "@dust-tt/client";
import type {
ConversationMessageEmojiSelectorProps,
ConversationMessageSizeType,
} from "@dust-tt/sparkle";
import type { ConversationMessageSizeType } from "@dust-tt/sparkle";
import {
ArrowPathIcon,
Button,
Expand Down Expand Up @@ -109,7 +106,6 @@ interface AgentMessageProps {
conversationId: string;
isLastMessage: boolean;
message: AgentMessagePublicType;
messageEmoji?: ConversationMessageEmojiSelectorProps;
owner: LightWorkspaceType;
size: ConversationMessageSizeType;
}
Expand All @@ -124,7 +120,6 @@ export function AgentMessage({
conversationId,
isLastMessage,
message,
messageEmoji,
owner,
size,
}: AgentMessageProps) {
Expand Down Expand Up @@ -500,7 +495,6 @@ export function AgentMessage({
name={`@${agentConfiguration.name}`}
buttons={buttons}
avatarBusy={agentMessageToRender.status === "created"}
messageEmoji={messageEmoji}
renderName={() => {
return (
<div className="flex flex-row items-center gap-2">
Expand Down
3 changes: 3 additions & 0 deletions extension/app/src/components/conversation/AttachFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import { useRef } from "react";
type AttachFileProps = {
fileUploaderService: FileUploaderService;
editorService: EditorService;
isLoading: boolean;
};

export const AttachFile = ({
fileUploaderService,
editorService,
isLoading,
}: AttachFileProps) => {
const fileInputRef = useRef<HTMLInputElement>(null);
return (
Expand All @@ -38,6 +40,7 @@ export const AttachFile = ({
onClick={async () => {
fileInputRef.current?.click();
}}
disabled={isLoading}
/>
</>
);
Expand Down
12 changes: 9 additions & 3 deletions extension/app/src/components/conversation/AttachFragment.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Button, CameraIcon, DocumentPlusIcon } from "@dust-tt/sparkle";
import { Button, DocumentPlusIcon, ImageIcon } from "@dust-tt/sparkle";
import { InputBarContext } from "@extension/components/input_bar/InputBarContext";
import type { FileUploaderService } from "@extension/hooks/useFileUploaderService";
import { useContext, useEffect } from "react";

type AttachFragmentProps = {
fileUploaderService: FileUploaderService;
isLoading: boolean;
};

export const AttachFragment = ({
fileUploaderService,
isLoading,
}: AttachFragmentProps) => {
const { attachPageBlinking, setAttachPageBlinking } =
useContext(InputBarContext);
Expand Down Expand Up @@ -38,11 +40,12 @@ export const AttachFragment = ({
includeCapture: false,
})
}
disabled={isLoading}
/>
</div>
<div className="block sm:hidden">
<Button
icon={CameraIcon}
icon={ImageIcon}
tooltip="Attach page screenshot"
variant="outline"
size="sm"
Expand All @@ -52,6 +55,7 @@ export const AttachFragment = ({
includeCapture: true,
})
}
disabled={isLoading}
/>
</div>
<div className="hidden sm:block">
Expand All @@ -68,11 +72,12 @@ export const AttachFragment = ({
includeCapture: false,
})
}
disabled={isLoading}
/>
</div>
<div className="hidden sm:block">
<Button
icon={CameraIcon}
icon={ImageIcon}
label="Add page screenshot"
tooltip="Attach page screenshot"
variant="outline"
Expand All @@ -83,6 +88,7 @@ export const AttachFragment = ({
includeCapture: true,
})
}
disabled={isLoading}
/>
</div>
</>
Expand Down
3 changes: 0 additions & 3 deletions extension/app/src/components/conversation/MessageItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const MessageItem = React.forwardRef<HTMLDivElement, MessageItemProps>(
return null;
}

const messageEmoji = undefined;

switch (type) {
case "user_message":
const citations = message.contenFragments
Expand Down Expand Up @@ -81,7 +79,6 @@ const MessageItem = React.forwardRef<HTMLDivElement, MessageItemProps>(
conversationId={conversationId}
isLastMessage={isLastMessage}
message={message}
messageEmoji={messageEmoji}
owner={owner}
size="compact"
/>
Expand Down
8 changes: 1 addition & 7 deletions extension/app/src/components/conversation/UserMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import type { LightWorkspaceType, UserMessageType } from "@dust-tt/client";
import type {
ConversationMessageEmojiSelectorProps,
ConversationMessageSizeType,
} from "@dust-tt/sparkle";
import type { ConversationMessageSizeType } from "@dust-tt/sparkle";
import { ConversationMessage, Markdown } from "@dust-tt/sparkle";
import { AgentSuggestion } from "@extension/components/conversation/AgentSuggestion";
import {
Expand All @@ -23,7 +20,6 @@ interface UserMessageProps {
conversationId: string;
isLastMessage: boolean;
message: UserMessageType;
messageEmoji?: ConversationMessageEmojiSelectorProps;
owner: LightWorkspaceType;
size: ConversationMessageSizeType;
}
Expand All @@ -33,7 +29,6 @@ export function UserMessage({
conversationId,
isLastMessage,
message,
messageEmoji,
owner,
size,
}: UserMessageProps) {
Expand All @@ -54,7 +49,6 @@ export function UserMessage({
<ConversationMessage
pictureUrl={message.user?.image || message.context.profilePictureUrl}
name={message.context.fullName}
messageEmoji={messageEmoji}
renderName={(name) => <div className="text-base font-medium">{name}</div>}
type="user"
citations={citations}
Expand Down
25 changes: 15 additions & 10 deletions extension/app/src/components/input_bar/InputBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ export function AssistantInputBar({
const handleSubmit: InputBarContainerProps["onEnterKeyDown"] = async (
isEmpty,
textAndMentions,
resetEditorText
resetEditorText,
setLoading
) => {
if (isEmpty) {
return;
Expand All @@ -204,7 +205,7 @@ export function AssistantInputBar({
kind: cf.kind,
}));

resetEditorText();
setLoading(true);

if (isTabIncluded) {
const files = await uploadContentTab({
Expand All @@ -228,7 +229,9 @@ export function AssistantInputBar({
}
}

onSubmit(text, mentions, newFiles);
await onSubmit(text, mentions, newFiles);
setLoading(false);
resetEditorText();
resetUpload();
};

Expand All @@ -238,15 +241,13 @@ export function AssistantInputBar({

return (
<div className="flex w-full flex-col">
{(isCapturing || isSubmitting) && (
{isCapturing && (
<div className="fixed absolute inset-0 z-50 overflow-hidden">
<div className="fixed flex inset-0 bg-structure-50/80 backdrop-blur-sm transition-opacity" />
<div className="fixed top-0 left-0 h-full w-full flex flex-col justify-center items-center gap-4">
{isCapturing && (
<span className="z-50">
<Page.Header title="Screen capture in progress..." />
</span>
)}
<span className="z-50">
<Page.Header title="Screen capture in progress..." />
</span>
<Spinner size="xl" />
</div>
</div>
Expand Down Expand Up @@ -276,7 +277,10 @@ export function AssistantInputBar({
)}
>
<div className="relative flex w-full flex-1 flex-col">
<InputBarCitations fileUploaderService={fileUploaderService} />
<InputBarCitations
fileUploaderService={fileUploaderService}
disabled={isSubmitting ?? false}
/>

<InputBarContainer
disableAutoFocus={disableAutoFocus}
Expand All @@ -289,6 +293,7 @@ export function AssistantInputBar({
isTabIncluded={isTabIncluded}
setIncludeTab={setIncludeTab}
fileUploaderService={fileUploaderService}
isSubmitting={isSubmitting ?? false}
/>
</div>
</div>
Expand Down
14 changes: 10 additions & 4 deletions extension/app/src/components/input_bar/InputBarCitations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import type { FileUploaderService } from "@extension/hooks/useFileUploaderServic

interface InputBarCitationsProps {
fileUploaderService: FileUploaderService;
disabled: boolean;
}

export function InputBarCitations({
fileUploaderService,
disabled,
}: InputBarCitationsProps) {
const processContentFragments = () => {
const nodes: React.ReactNode[] = [];
Expand All @@ -21,9 +23,13 @@ export function InputBarCitations({
size="xs"
type={isImage ? "image" : "document"}
imgSrc={blob.preview}
onClose={() => {
fileUploaderService.removeFile(blob.id);
}}
onClose={
disabled
? undefined
: () => {
fileUploaderService.removeFile(blob.id);
}
}
isLoading={blob.isUploading}
/>
);
Expand All @@ -37,7 +43,7 @@ export function InputBarCitations({
}

return (
<div className="mr-4 flex gap-2 overflow-auto border-b border-structure-300/50 pb-3">
<div className="flex gap-2 overflow-auto border-b border-structure-300/50 pb-3">
{processContentFragments()}
</div>
);
Expand Down
25 changes: 20 additions & 5 deletions extension/app/src/components/input_bar/InputBarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const InputBarContainer = ({
isTabIncluded,
setIncludeTab,
fileUploaderService,
isSubmitting,
}: InputBarContainerProps) => {
const suggestions = usePublicAssistantSuggestions(agentConfigurations);

Expand Down Expand Up @@ -76,18 +77,27 @@ export const InputBarContainer = ({

const onClick = async () => {
const jsonContent = editorService.getTextAndMentions();
onEnterKeyDown(editorService.isEmpty(), jsonContent, () => {
editorService.clearEditor();
});
onEnterKeyDown(
editorService.isEmpty(),
jsonContent,
() => {
editorService.clearEditor();
},
(loading) => {
editorService.setLoading(loading);
}
);
};

const SendAction = {
label: "Send",
onClick,
isLoading: isSubmitting,
};
const SendWithContentAction = {
label: "Add page text + Send",
onClick,
isLoading: isSubmitting,
};

return (
Expand All @@ -108,6 +118,7 @@ export const InputBarContainer = ({
<AttachFile
fileUploaderService={fileUploaderService}
editorService={editorService}
isLoading={isSubmitting}
/>
<AssistantPicker
owner={owner}
Expand All @@ -116,12 +127,16 @@ export const InputBarContainer = ({
editorService.insertMention({ id: c.sId, label: c.name });
}}
assistants={allAssistants}
isLoading={isSubmitting}
/>
</div>
</div>

<div className="flex items-center justify-end space-x-2 mt-2">
<AttachFragment fileUploaderService={fileUploaderService} />
<AttachFragment
fileUploaderService={fileUploaderService}
isLoading={isSubmitting}
/>
<SplitButton
size="sm"
actions={[SendAction, SendWithContentAction]}
Expand All @@ -130,7 +145,7 @@ export const InputBarContainer = ({
onActionChange={(action) => {
setIncludeTab(action === SendWithContentAction);
}}
disabled={editorService.isEmpty()}
disabled={isSubmitting || editorService.isEmpty()}
/>
</div>
</div>
Expand Down
Loading

0 comments on commit 149b1a3

Please sign in to comment.