From 10cf0470cb3453312b1800c11fd2a5d808d1a679 Mon Sep 17 00:00:00 2001 From: staticGuru Date: Sun, 8 Oct 2023 22:09:38 +0530 Subject: [PATCH] add the conversation Tile --- .../src/conversation/ConversationTile.tsx | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 frontend/src/conversation/ConversationTile.tsx diff --git a/frontend/src/conversation/ConversationTile.tsx b/frontend/src/conversation/ConversationTile.tsx new file mode 100644 index 0000000..e97d998 --- /dev/null +++ b/frontend/src/conversation/ConversationTile.tsx @@ -0,0 +1,84 @@ +import React, { useState } from 'react'; +import { useSelector } from 'react-redux'; +import Edit from '../assets/edit.svg'; +import Exit from '../assets/exit.svg'; +import Message from '../assets/message.svg'; + +import { selectConversationId } from '../preferences/preferenceSlice'; + +interface ConversationTileProps { + conversation: { name: string; id: string }; + selectConversation: (arg1: string) => void; + onDeleteConversation: (arg1: string) => void; + onSave: ({ name, id }: { name: string; id: string }) => void; +} + +export default function ConversationTile({ + conversation, + selectConversation, + onDeleteConversation, + onSave, +}: ConversationTileProps) { + const conversationId = useSelector(selectConversationId); + + const [isEdit, setIsEdit] = useState(false); + const [conversationName, setConversationsName] = useState(conversation.name); + + function handleEditConversation() { + setIsEdit(true); + } + return ( +
{ + selectConversation(conversation.id); + }} + className={`my-auto mx-4 mt-4 flex h-12 cursor-pointer items-center justify-between gap-4 rounded-3xl hover:bg-gray-100 ${ + conversationId === conversation.id ? 'bg-gray-100' : '' + }`} + > +
+ + {isEdit ? ( + setConversationsName(e.target.value)} + /> + ) : ( +

+ {conversationName.length > 45 + ? conversationName.substring(0, 45) + '...' + : conversationName} +

+ )} +
+ {conversationId === conversation.id ? ( + <> + Edit { + event.stopPropagation(); + isEdit + ? onSave({ id: conversationId, name: conversationName }) + : handleEditConversation(); + }} + /> + Exit { + event.stopPropagation(); + onDeleteConversation(conversation.id); + }} + /> + + ) : null} +
+ ); +}