()
| 11 | } |
| 12 | |
| 13 | const ConversationList = () => { |
| 14 | const { t } = useTranslation(); |
| 15 | const layoutStore = useLayoutStore(); |
| 16 | const connectionStore = useConnectionStore(); |
| 17 | const conversationStore = useConversationStore(); |
| 18 | const [state, setState] = useState<State>({ |
| 19 | showUpdateConversationModal: false, |
| 20 | }); |
| 21 | const [updateConversationModalContext, setUpdateConversationModalContext] = useState<Conversation>(); |
| 22 | const currentConnectionCtx = connectionStore.currentConnectionCtx; |
| 23 | const conversationList = conversationStore.conversationList.filter( |
| 24 | (conversation) => |
| 25 | conversation.connectionId === currentConnectionCtx?.connection.id && |
| 26 | conversation.databaseName === currentConnectionCtx?.database?.name |
| 27 | ); |
| 28 | |
| 29 | const toggleUpdateConversationModal = (show = true) => { |
| 30 | setState({ |
| 31 | ...state, |
| 32 | showUpdateConversationModal: show, |
| 33 | }); |
| 34 | }; |
| 35 | |
| 36 | const handleCreateConversation = () => { |
| 37 | if (!currentConnectionCtx) { |
| 38 | conversationStore.createConversation(); |
| 39 | } else { |
| 40 | conversationStore.createConversation(currentConnectionCtx.connection.id, currentConnectionCtx.database?.name); |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | const handleConversationSelect = (conversation: Conversation) => { |
| 45 | conversationStore.setCurrentConversationId(conversation.id); |
| 46 | if (layoutStore.isMobileView) { |
| 47 | layoutStore.toggleSidebar(false); |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | const handleEditConversation = (conversation: Conversation) => { |
| 52 | setUpdateConversationModalContext(conversation); |
| 53 | setState({ |
| 54 | ...state, |
| 55 | showUpdateConversationModal: true, |
| 56 | }); |
| 57 | }; |
| 58 | |
| 59 | const handleDeleteConversation = (conversation: Conversation) => { |
| 60 | conversationStore.clearConversation((item) => item.id !== conversation.id); |
| 61 | if (conversationStore.currentConversationId === conversation.id) { |
| 62 | conversationStore.setCurrentConversationId(undefined); |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | return ( |
| 67 | <> |
| 68 | {conversationList.map((conversation) => ( |
| 69 | <div |
| 70 | key={conversation.id} |
nothing calls this directly
no test coverage detected