()
| 55 | }; |
| 56 | |
| 57 | const ConversationTabsView = () => { |
| 58 | const { t } = useTranslation(); |
| 59 | const layoutStore = useLayoutStore(); |
| 60 | const connectionStore = useConnectionStore(); |
| 61 | const conversationStore = useConversationStore(); |
| 62 | const [updateConversationModalContext, setUpdateConversationModalContext] = useState<Conversation | undefined>(undefined); |
| 63 | const currentConnectionCtx = connectionStore.currentConnectionCtx; |
| 64 | const conversationList = conversationStore.conversationList.filter( |
| 65 | (conversation) => |
| 66 | conversation.connectionId === currentConnectionCtx?.connection.id && |
| 67 | conversation.databaseName === currentConnectionCtx?.database?.name |
| 68 | ); |
| 69 | |
| 70 | const handleCreateConversation = () => { |
| 71 | if (!currentConnectionCtx) { |
| 72 | conversationStore.createConversation(); |
| 73 | } else { |
| 74 | conversationStore.createConversation(currentConnectionCtx.connection.id, currentConnectionCtx.database?.name); |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | const handleConversationClick = (conversation: Conversation) => { |
| 79 | conversationStore.setCurrentConversationId(conversation.id); |
| 80 | if (layoutStore.isMobileView) { |
| 81 | layoutStore.toggleSidebar(false); |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | const handleEditConversation = (conversation: Conversation) => { |
| 86 | setUpdateConversationModalContext(conversation); |
| 87 | }; |
| 88 | |
| 89 | const handleDeleteConversation = (conversation: Conversation) => { |
| 90 | conversationStore.clearConversation((item) => item.id !== conversation.id); |
| 91 | if (conversationStore.currentConversationId === conversation.id) { |
| 92 | conversationStore.setCurrentConversationId(undefined); |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | return ( |
| 97 | <> |
| 98 | <div className="w-full flex flex-row justify-start items-center flex-nowrap px-4 mt-1"> |
| 99 | <div className="w-auto flex flex-row justify-start items-center overflow-x-auto py-1 gap-x-2"> |
| 100 | {conversationList.map((conversation) => { |
| 101 | return ( |
| 102 | <ConversationTab |
| 103 | key={conversation.id} |
| 104 | conversation={conversation} |
| 105 | selected={conversation.id === conversationStore.currentConversationId} |
| 106 | onClick={handleConversationClick} |
| 107 | onEdit={handleEditConversation} |
| 108 | onDelete={handleDeleteConversation} |
| 109 | /> |
| 110 | ); |
| 111 | })} |
| 112 | </div> |
| 113 | <div className={`shrink-0 my-2 ${conversationList.length > 0 && "ml-2"}`}> |
| 114 | <button |
nothing calls this directly
no outgoing calls
no test coverage detected