bug on chat solved
This commit is contained in:
parent
600f6aedda
commit
ba49cf5931
5 changed files with 95 additions and 51 deletions
|
|
@ -1,53 +1,77 @@
|
||||||
import { useContext } from "react";
|
import { useContext, useEffect, useRef } from "react";
|
||||||
import { alertContext } from "../../contexts/alertContext";
|
import { alertContext } from "../../contexts/alertContext";
|
||||||
import {
|
import { XMarkIcon } from "@heroicons/react/24/solid";
|
||||||
XMarkIcon,
|
|
||||||
} from "@heroicons/react/24/solid";
|
|
||||||
import { TrashIcon } from "@heroicons/react/24/outline";
|
import { TrashIcon } from "@heroicons/react/24/outline";
|
||||||
import SingleAlert from "./components/singleAlertComponent";
|
import SingleAlert from "./components/singleAlertComponent";
|
||||||
import { AlertDropdownType } from "../../types/alerts";
|
import { AlertDropdownType } from "../../types/alerts";
|
||||||
import { PopUpContext } from "../../contexts/popUpContext";
|
import { PopUpContext } from "../../contexts/popUpContext";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default function AlertDropdown({}: AlertDropdownType) {
|
export default function AlertDropdown({}: AlertDropdownType) {
|
||||||
|
const { closePopUp } = useContext(PopUpContext);
|
||||||
|
const componentRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function handleClickOutside(event: MouseEvent) {
|
||||||
|
if (
|
||||||
|
componentRef.current &&
|
||||||
|
!componentRef.current.contains(event.target as Node)
|
||||||
|
) {
|
||||||
|
console.log(event)
|
||||||
|
closePopUp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind the event listener
|
||||||
|
document.addEventListener("mousedown", handleClickOutside);
|
||||||
|
|
||||||
|
// Cleanup the event listener when the component is unmounted
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("mousedown", handleClickOutside);
|
||||||
|
};
|
||||||
|
}, [componentRef]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
notificationList,
|
notificationList,
|
||||||
clearNotificationList,
|
clearNotificationList,
|
||||||
removeFromNotificationList,
|
removeFromNotificationList,
|
||||||
} = useContext(alertContext);
|
} = useContext(alertContext);
|
||||||
const {closePopUp} = useContext(PopUpContext)
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="z-10 py-3 pb-4 rounded-md bg-white ring-1 ring-black ring-opacity-5 shadow-lg focus:outline-none overflow-hidden w-[16rem] h-[28rem] flex flex-col">
|
<div
|
||||||
|
ref={componentRef}
|
||||||
|
className="z-10 py-3 pb-4 rounded-md bg-white ring-1 ring-black ring-opacity-5 shadow-lg focus:outline-none overflow-hidden w-[16rem] h-[28rem] flex flex-col"
|
||||||
|
>
|
||||||
<div className="flex pl-3 flex-row justify-between text-md font-medium text-gray-800">
|
<div className="flex pl-3 flex-row justify-between text-md font-medium text-gray-800">
|
||||||
Notifications
|
Notifications
|
||||||
<div className="flex gap-2 pr-3 ">
|
<div className="flex gap-2 pr-3 ">
|
||||||
<button
|
<button
|
||||||
className="hover:text-red-500"
|
className="hover:text-red-500"
|
||||||
onClick={() => {closePopUp(); setTimeout(clearNotificationList, 100)}}
|
onClick={() => {
|
||||||
|
closePopUp();
|
||||||
|
setTimeout(clearNotificationList, 100);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<TrashIcon className="w-[1.1rem] h-[1.1rem]" />
|
<TrashIcon className="w-[1.1rem] h-[1.1rem]" />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button className="hover:text-red-500" onClick={closePopUp}>
|
||||||
className="hover:text-red-500"
|
|
||||||
onClick={closePopUp}
|
|
||||||
>
|
|
||||||
<XMarkIcon className="h-5 w-5" />
|
<XMarkIcon className="h-5 w-5" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-2 flex flex-col overflow-y-scroll w-full h-full scrollbar-hide">
|
<div className="mt-2 flex flex-col overflow-y-scroll w-full h-full scrollbar-hide">
|
||||||
{notificationList.length !== 0 ?
|
{notificationList.length !== 0 ? (
|
||||||
notificationList.map((alertItem, index) => (
|
notificationList.map((alertItem, index) => (
|
||||||
<SingleAlert key={alertItem.id} dropItem={alertItem} removeAlert={removeFromNotificationList} />
|
<SingleAlert
|
||||||
|
key={alertItem.id}
|
||||||
|
dropItem={alertItem}
|
||||||
|
removeAlert={removeFromNotificationList}
|
||||||
|
/>
|
||||||
))
|
))
|
||||||
:
|
) : (
|
||||||
<div className="h-full w-full pb-16 text-gray-500 flex justify-center items-center">
|
<div className="h-full w-full pb-16 text-gray-500 flex justify-center items-center">
|
||||||
No new notifications
|
No new notifications
|
||||||
</div>
|
</div>
|
||||||
}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,8 @@ import ChatMessage from "./chatMessage";
|
||||||
const _ = require("lodash");
|
const _ = require("lodash");
|
||||||
|
|
||||||
export default function Chat({ flow, reactFlowInstance }: ChatType) {
|
export default function Chat({ flow, reactFlowInstance }: ChatType) {
|
||||||
const { updateFlow } = useContext(TabsContext);
|
const { updateFlow,lockChat,setLockChat,flows,tabIndex } = useContext(TabsContext);
|
||||||
const [saveChat, setSaveChat] = useState(false);
|
const [saveChat, setSaveChat] = useState(false);
|
||||||
const [lockChat, setLockChat] = useState(false);
|
|
||||||
const [open, setOpen] = useState(true);
|
const [open, setOpen] = useState(true);
|
||||||
const [chatValue, setChatValue] = useState("");
|
const [chatValue, setChatValue] = useState("");
|
||||||
const [chatHistory, setChatHistory] = useState(flow.chat);
|
const [chatHistory, setChatHistory] = useState(flow.chat);
|
||||||
|
|
@ -26,10 +25,15 @@ export default function Chat({ flow, reactFlowInstance }: ChatType) {
|
||||||
const addChatHistory = (
|
const addChatHistory = (
|
||||||
message: string,
|
message: string,
|
||||||
isSend: boolean,
|
isSend: boolean,
|
||||||
thought?: string
|
thought?: string,
|
||||||
) => {
|
) => {
|
||||||
|
let tabsChange = false;
|
||||||
setChatHistory((old) => {
|
setChatHistory((old) => {
|
||||||
let newChat = _.cloneDeep(old);
|
let newChat = _.cloneDeep(old);
|
||||||
|
if(flow.chat !==old){
|
||||||
|
tabsChange = true
|
||||||
|
return old
|
||||||
|
}
|
||||||
if (thought) {
|
if (thought) {
|
||||||
newChat.push({ message, isSend, thought });
|
newChat.push({ message, isSend, thought });
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -37,6 +41,15 @@ export default function Chat({ flow, reactFlowInstance }: ChatType) {
|
||||||
}
|
}
|
||||||
return newChat;
|
return newChat;
|
||||||
});
|
});
|
||||||
|
if(tabsChange){
|
||||||
|
console.log(flow.chat)
|
||||||
|
if(thought){
|
||||||
|
updateFlow({..._.cloneDeep(flow),chat:[...flow.chat,{isSend,message,thought}]})
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
updateFlow({..._.cloneDeep(flow),chat:[...flow.chat,{isSend,message}]})
|
||||||
|
}
|
||||||
|
}
|
||||||
setSaveChat((chat) => !chat);
|
setSaveChat((chat) => !chat);
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -99,7 +112,7 @@ export default function Chat({ flow, reactFlowInstance }: ChatType) {
|
||||||
} else {
|
} else {
|
||||||
setErrorData({
|
setErrorData({
|
||||||
title: "Error sending message",
|
title: "Error sending message",
|
||||||
list: ["There are required fields not filled yet."],
|
list: [ "Oops! Looks like you missed some required information. Please fill in all the required fields before continuing."],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ const TabsContextInitialValue: TabsContextType = {
|
||||||
incrementNodeId: () => 0,
|
incrementNodeId: () => 0,
|
||||||
downloadFlow: () => {},
|
downloadFlow: () => {},
|
||||||
uploadFlow: () => {},
|
uploadFlow: () => {},
|
||||||
|
lockChat: false,
|
||||||
|
setLockChat:(prevState:boolean)=>{}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TabsContext = createContext<TabsContextType>(
|
export const TabsContext = createContext<TabsContextType>(
|
||||||
|
|
@ -25,6 +27,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
const [tabIndex, setTabIndex] = useState(0);
|
const [tabIndex, setTabIndex] = useState(0);
|
||||||
const [flows, setFlows] = useState<Array<FlowType>>([]);
|
const [flows, setFlows] = useState<Array<FlowType>>([]);
|
||||||
const [id, setId] = useState(0);
|
const [id, setId] = useState(0);
|
||||||
|
const [lockChat, setLockChat] = useState(false);
|
||||||
|
|
||||||
const newNodeId = useRef(0);
|
const newNodeId = useRef(0);
|
||||||
function incrementNodeId() {
|
function incrementNodeId() {
|
||||||
|
|
@ -166,6 +169,8 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
return (
|
return (
|
||||||
<TabsContext.Provider
|
<TabsContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
lockChat,
|
||||||
|
setLockChat,
|
||||||
tabIndex,
|
tabIndex,
|
||||||
setTabIndex,
|
setTabIndex,
|
||||||
flows,
|
flows,
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,5 @@ export type sendAllProps={
|
||||||
edges: Edge[];
|
edges: Edge[];
|
||||||
viewport: Viewport;
|
viewport: Viewport;
|
||||||
message:string;
|
message:string;
|
||||||
chatHistory:{message:string,isSend:boolean}[]
|
chatHistory:{message:string,isSend:boolean}[],
|
||||||
};
|
};
|
||||||
|
|
@ -10,4 +10,6 @@ export type TabsContextType = {
|
||||||
incrementNodeId: () => number;
|
incrementNodeId: () => number;
|
||||||
downloadFlow: () => void;
|
downloadFlow: () => void;
|
||||||
uploadFlow: () => void;
|
uploadFlow: () => void;
|
||||||
|
lockChat:boolean,
|
||||||
|
setLockChat:(prevState:boolean)=>void
|
||||||
};
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue