Skip to content

Commit

Permalink
start to virtualize the chatview,
Browse files Browse the repository at this point in the history
somehow it doesn't work yet
  • Loading branch information
Simon-Laux committed May 30, 2020
1 parent d36c6cf commit 0d78bb2
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 460 deletions.
22 changes: 9 additions & 13 deletions src/renderer/components/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { SettingsContext } from '../../contexts'
import ComposerMessageInput from './ComposerMessageInput'
import { getLogger } from '../../../shared/logger'
import { EmojiAndStickerPicker } from './EmojiAndStickerPicker'
import { useChatStore } from '../../stores/chat'
import { EmojiData, BaseEmoji } from 'emoji-mart'
import { UI_SendMessage } from '../message/messageFunctions'
const { remote } = window.electron_functions

const log = getLogger('renderer/composer')
Expand Down Expand Up @@ -36,23 +36,19 @@ const Composer = forwardRef<
}
>((props, ref) => {
const { isDisabled, disabledReason, chatId, draft } = props
const chatStoreDispatch = useChatStore()[1]
const [showEmojiPicker, setShowEmojiPicker] = useState(false)

const messageInputRef = useRef<ComposerMessageInput>()
const emojiAndStickerRef = useRef<HTMLDivElement>()
const pickerButtonRef = useRef()

const sendMessage = () => {
const sendTextMessage = () => {
const message = messageInputRef.current.getText()
if (message.match(/^\s*$/)) {
log.debug(`Empty message: don't send it...`)
return
}
chatStoreDispatch({
type: 'SEND_MESSAGE',
payload: [chatId, message, null],
})
UI_SendMessage(chatId, { text: message })

messageInputRef.current.clearText()
messageInputRef.current.focus()
Expand All @@ -63,10 +59,7 @@ const Composer = forwardRef<
{ properties: ['openFile'] },
(filenames: string[]) => {
if (filenames && filenames[0]) {
chatStoreDispatch({
type: 'SEND_MESSAGE',
payload: [chatId, '', filenames[0]],
})
UI_SendMessage(chatId, { text: '', filename: filenames[0] })
}
}
)
Expand Down Expand Up @@ -135,7 +128,7 @@ const Composer = forwardRef<
<ComposerMessageInput
ref={messageInputRef}
enterKeySends={enterKeySends}
sendMessage={sendMessage}
sendMessage={sendTextMessage}
setComposerSize={props.setComposerSize}
chatId={chatId}
draft={draft}
Expand All @@ -158,7 +151,10 @@ const Composer = forwardRef<
setShowEmojiPicker={setShowEmojiPicker}
/>
)}
<div className='composer__send-button-wrapper' onClick={sendMessage}>
<div
className='composer__send-button-wrapper'
onClick={sendTextMessage}
>
<button aria-label={tx('menu_send')} />
</div>
</div>
Expand Down
5 changes: 2 additions & 3 deletions src/renderer/components/dialogs/DeadDrop.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { DeltaBackend } from '../../delta-remote'
import { Classes } from '@blueprintjs/core'
import { useChatStore } from '../../stores/chat'
import { selectChat } from '../../stores/chat'
import { DialogProps } from './DialogController'
import { DCContact, MessageType } from '../../../shared/shared-types'
import { SmallDialog } from './DeltaDialog'
Expand All @@ -15,7 +15,6 @@ export default function DeadDrop(props: {
onClose: DialogProps['onClose']
}) {
const { contact, msg, onClose } = props
const chatStoreDispatch = useChatStore()[1]

const never = () => {
DeltaBackend.call('contacts.blockContact', contact.id)
Expand All @@ -35,7 +34,7 @@ export default function DeadDrop(props: {
messageId,
contactId,
})
chatStoreDispatch({ type: 'SELECT_CHAT', payload: chatId })
selectChat(chatId)
onClose()
}

Expand Down
7 changes: 2 additions & 5 deletions src/renderer/components/map/MapComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Slider, Button, Collapse } from '@blueprintjs/core'
import PopupMessage from './PopupMessage'
import * as SessionStorage from '../helpers/SessionStorage'
import { SettingsContext } from '../../contexts'
import chatStore from '../../stores/chat'

import { state as LocationStoreState } from '../../stores/locations'

Expand All @@ -25,6 +24,7 @@ import {
JsonContact,
JsonLocations,
} from '../../../shared/shared-types'
import { UI_SendMessage } from '../message/messageFunctions'

type MapData = {
contact: JsonContact
Expand Down Expand Up @@ -426,10 +426,7 @@ export default class MapComponent extends React.Component<
return
}
const latLng = Object.assign({}, this.poiLocation)
chatStore.dispatch({
type: 'SEND_MESSAGE',
payload: [selectedChat.id, message, null, latLng],
})
UI_SendMessage(selectedChat.id, { text: message, location: latLng })

if (this.contextMenuPopup) {
this.contextMenuPopup.remove()
Expand Down
Loading

0 comments on commit 0d78bb2

Please sign in to comment.