Skip to content

Commit

Permalink
add new conversation icon in sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
anish-work committed Sep 3, 2024
1 parent 6112ecb commit 0ad2d37
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
22 changes: 21 additions & 1 deletion src/components/shared/Buttons/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ReactNode } from "react";

import { addInlineStyle } from "src/addStyles";
import style from "./buttons.scss?inline";
import IconButton from "./IconButton";
import clsx from "clsx";
addInlineStyle(style);

export interface ButtonProps
Expand All @@ -10,13 +12,17 @@ export interface ButtonProps
children?: ReactNode;
className?: string;
variant?: "filled" | "contained" | "outlined" | "text" | "text-alt";
RightIconComponent?: React.FC<{ size: number }>;
showIconOnHover?: boolean;
}

const Button = ({
// size = "medium",
variant = "text",
className = "",
onClick,
RightIconComponent,
showIconOnHover,
...rest
}: ButtonProps) => {
const variantClasses = `button-${variant?.toLowerCase()}`;
Expand All @@ -25,9 +31,23 @@ const Button = ({
<button
{...rest}
onMouseDown={onClick}
className={variantClasses + " " + className}
className={variantClasses + " pos-relative " + className}
>
{rest.children}
{RightIconComponent && (
<div
className={clsx("pos-absolute", showIconOnHover && "icon-hover")}
style={{
top: "50%",
right: 0,
transform: "translateY(-50%)",
}}
>
<IconButton className="text-muted" disabled>
<RightIconComponent size={18} />
</IconButton>
</div>
)}
</button>
);
};
Expand Down
7 changes: 7 additions & 0 deletions src/components/shared/Buttons/buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ button {
color: $almost-black;
width: fit-content;
}

button:disabled {
color: $muted !important;
fill: $light;
cursor: unset;
}
button .icon-hover {
opacity: 0;
}
button:hover .icon-hover {
opacity: 1;
}

// Variant - FILED
.button-filled {
Expand Down
17 changes: 6 additions & 11 deletions src/components/shared/Layout/SideNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import Button from "../Buttons/Button";
import clsx from "clsx";
import { Conversation } from "src/contexts/ConversationLayer";
import React from "react";
import { CHAT_INPUT_ID } from "src/widgets/copilot/components/ChatInput";
import IconClose from "src/assets/SvgIcons/IconClose";
import IconCollapse from "src/assets/SvgIcons/IconCollapse";
import IconExpand from "src/assets/SvgIcons/IconExpand";
import IconPencilEdit from "src/assets/SvgIcons/PencilEdit";

// eslint-disable-next-line react-refresh/only-export-components
export const toggleSidebarStyles = (isSidebarOpen: boolean) => {
Expand Down Expand Up @@ -173,15 +173,10 @@ const SideNavbar = () => {
<div className="overflow-y-auto pos-relative h-100">
<div className="d-flex flex-col gp-8">
<Button
className="w-100 d-flex"
onClick={() => {
handleNewConversation();
const shadowRoot = document.querySelector(
(config?.target || "") as string
)?.firstElementChild?.shadowRoot;
const ele = shadowRoot?.getElementById(CHAT_INPUT_ID);
ele?.focus();
}}
className="w-100 d-flex pos-relative"
onClick={handleNewConversation}
RightIconComponent={IconPencilEdit}
showIconOnHover
>
<div
className="bot-avatar bg-primary gmr-12"
Expand All @@ -198,7 +193,7 @@ const SideNavbar = () => {
}}
/>
</div>
<p className="font_16_600">{branding?.name}</p>
<p className="font_16_600 text-left">{branding?.name}</p>
</Button>
</div>

Expand Down
10 changes: 8 additions & 2 deletions src/contexts/MessagesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useConversations, {
updateLocalUser,
USER_ID_LS_KEY,
} from "./ConversationLayer";
import { CHAT_INPUT_ID } from "src/widgets/copilot/components/ChatInput";

interface IncomingMsg {
input_text?: string;
Expand All @@ -36,6 +37,7 @@ export const MessagesContext: any = createContext({});
const MessagesContextProvider = (props: any) => {
const currentUserId = localStorage.getItem(USER_ID_LS_KEY) || "";
const config = useSystemContext()?.config;
const layoutController = useSystemContext()?.layoutController;
const { conversations, handleAddConversation } = useConversations(
currentUserId,
config?.integration_id as string
Expand Down Expand Up @@ -226,6 +228,10 @@ const MessagesContextProvider = (props: any) => {
handleAddConversation(Object.assign({}, currentConversation.current));
}
if (isReceiving || isSending) cancelApiCall();
if (layoutController?.isMobile && layoutController?.isSidebarOpen)
layoutController?.toggleSidebar();
const ele = gooeyShadowRoot?.getElementById(CHAT_INPUT_ID);
ele?.focus();
setIsReceiving(false);
setIsSendingMessage(false);
purgeMessages();
Expand Down Expand Up @@ -305,7 +311,7 @@ const MessagesContextProvider = (props: any) => {
currentConversation.current?.id === conversation.id
)
return setMessagesLoading(false);
setPreventAutoplay(true)
setPreventAutoplay(true);
setMessagesLoading(true);
const messages = await conversation.getMessages();
preLoadData(messages);
Expand All @@ -319,7 +325,7 @@ const MessagesContextProvider = (props: any) => {

useEffect(() => {
// Load the latest conversation from DB
setPreventAutoplay(true)
setPreventAutoplay(true);
if (!config?.enableConversations && conversations.length)
setActiveConversation(conversations[0]);
else setMessagesLoading(false);
Expand Down

0 comments on commit 0ad2d37

Please sign in to comment.