Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactionsDialog: drop email, make rows clickable #4071

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Added

### Changed
- do not display email adresses in reactions dialog #4066
- click on a row in reactions dialog opens contact profile #4066

### Fixed

Expand Down
6 changes: 4 additions & 2 deletions src/renderer/components/ContactName/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import styles from './styles.module.scss'

type Props = {
displayName: string
address: string
address?: string
isVerified?: boolean
}

Expand All @@ -17,7 +17,9 @@ export default function ContactName(props: Props) {
<span className={styles.contactNameTruncated}>{props.displayName}</span>
{props.isVerified && <InlineVerifiedIcon />}
</div>
<div className={styles.contactNameAddress}>{props.address}</div>
{!!props.address && (
<div className={styles.contactNameAddress}>{props.address}</div>
)}
</div>
)
}
31 changes: 24 additions & 7 deletions src/renderer/components/dialogs/ReactionsDialog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect, useState } from 'react'
import classNames from 'classnames'

import Dialog, {
DialogBody,
Expand All @@ -19,8 +20,11 @@ import styles from './styles.module.scss'
import type { DialogProps } from '../../../contexts/DialogContext'
import type { T } from '@deltachat/jsonrpc-client'

import useOpenViewProfileDialog from '../../../hooks/dialog/useOpenViewProfileDialog'

export type Props = {
reactionsByContact: T.Reactions['reactionsByContact']
onClose?: () => void
}

type ContactWithReaction = T.Contact & {
Expand All @@ -38,7 +42,10 @@ export default function ReactionsDialog({
<DialogHeader title={tx('reactions')} />
<DialogBody>
<DialogContent>
<ReactionsDialogList reactionsByContact={reactionsByContact} />
<ReactionsDialogList
reactionsByContact={reactionsByContact}
onClose={onClose}
/>
</DialogContent>
</DialogBody>
<DialogFooter>
Expand All @@ -50,9 +57,10 @@ export default function ReactionsDialog({
)
}

function ReactionsDialogList({ reactionsByContact }: Props) {
function ReactionsDialogList({ reactionsByContact, onClose }: Props) {
const accountId = selectedAccountId()
const [contacts, setContacts] = useState<ContactWithReaction[]>([])
const openViewProfileDialog = useOpenViewProfileDialog({ onAction: onClose })

useEffect(() => {
const resolveContacts = async () => {
Expand Down Expand Up @@ -84,16 +92,25 @@ function ReactionsDialogList({ reactionsByContact }: Props) {
return (
<ul className={styles.reactionsDialogList}>
{contacts.map(contact => {
const notFromSelf = accountId !== contact.id
return (
<li key={contact.id} className={styles.reactionsDialogListItem}>
<li
key={contact.id}
className={classNames(styles.reactionsDialogListItem, {
[styles.reactionsDialogListClickable]: notFromSelf,
})}
onClick={() => {
if (notFromSelf) {
openViewProfileDialog(accountId, contact.id)
}
}}
role='button'
>
<div className={styles.reactionsDialogAvatar}>
<AvatarFromContact contact={contact} />
</div>
<div className={styles.reactionsDialogContactName}>
<ContactName
displayName={contact.displayName}
address={contact.address}
/>
<ContactName displayName={contact.displayName} />
maxphilippov marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div className={styles.reactionsDialogEmoji}>{contact.emoji}</div>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
align-items: center;
display: flex;
justify-content: space-between;
border-radius: 10px;
}

.reactionsDialogListClickable {
cursor: pointer;
&:hover {
background-color: var(--chatListItemBgHover);
}
}

.reactionsDialogAvatar {
Expand Down
12 changes: 10 additions & 2 deletions src/renderer/components/dialogs/ViewProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ export default function ViewProfile(
props: {
contact: T.Contact
onBack?: () => void
onAction?: () => void
} & DialogProps
) {
const { onClose, onBack } = props
const { onClose, onBack, onAction } = props

const accountId = selectedAccountId()
const tx = useTranslationFunction()
Expand Down Expand Up @@ -110,7 +111,11 @@ export default function ViewProfile(
onClickBack={onBack}
/>
<DialogBody className={styles.viewProfileDialogBody}>
<ViewProfileInner contact={contact} onClose={onClose} />
<ViewProfileInner
contact={contact}
onClose={onClose}
onAction={onAction}
/>
</DialogBody>
</Dialog>
)
Expand All @@ -119,9 +124,11 @@ export default function ViewProfile(
export function ViewProfileInner({
contact,
onClose,
onAction,
}: {
contact: T.Contact
onClose: () => void
onAction?: () => void
}) {
const accountId = selectedAccountId()
const tx = useTranslationFunction()
Expand All @@ -142,6 +149,7 @@ export function ViewProfileInner({

const onChatClick = (chatId: number) => {
selectChat(accountId, chatId)
onAction && onAction()
onClose()
}
const onSendMessage = async () => {
Expand Down
8 changes: 5 additions & 3 deletions src/renderer/hooks/dialog/useOpenViewProfileDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import ViewProfile from '../../components/dialogs/ViewProfile'
import useDialog from './useDialog'
import { BackendRemote } from '../../backend-com'

export default function useOpenViewProfileDialog() {
export default function useOpenViewProfileDialog(props?: {
onAction?: () => void
}) {
const { openDialog } = useDialog()

return useCallback(
async (accountId: number, contactId: number) => {
const contact = await BackendRemote.rpc.getContact(accountId, contactId)
openDialog(ViewProfile, { contact })
openDialog(ViewProfile, { contact, onAction: props?.onAction })
},
[openDialog]
[openDialog, props?.onAction]
)
}
Loading