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

Improve layout and fix unknown locale of DisabledMessageInput #3537

Merged
merged 11 commits into from
Nov 17, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### Fixed
- fix: files search not case-insensitive
- fix: bug in emoji detection for jumbomoji #3508
- Improve layout and fix unknown locale of DisabledMessageInput #3537
- Fix: Do not show reply option in read-only groups #3536

<a id="1_41_2"></a>
Expand Down
11 changes: 6 additions & 5 deletions scss/composer/_composer.scss
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
.composer {
background-color: var(--composerBg);
border-left: 1px solid rgba(16, 22, 26, 0.1);

&.composer--disabled-message-input {
--composerHeight: 40px;

display: flex;
justify-content: center;
align-items: center;
text-align: center;
padding: calc((var(--composerHeight) - 16px) / 2);
height: var(--composerHeight);
padding: 3px;
color: #999;
overflow: hidden;

@media only screen and (max-width: 830px) {
padding: 0px 3px;
}
}

&.contact-request {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ const Composer = forwardRef<
</div>
)
} else if (isDisabled) {
return <DisabledMessageInput ref={ref} reason={disabledReason} />
Simon-Laux marked this conversation as resolved.
Show resolved Hide resolved
return <DisabledMessageInput reason={disabledReason} />
} else {
return (
<div className='composer' ref={ref}>
Expand Down
67 changes: 35 additions & 32 deletions src/renderer/components/composer/DisabledMessageInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, useMemo } from 'react'
import React, { useMemo } from 'react'

import { useTranslationFunction } from '../../contexts'
import { DisabledChatReasons } from './useIsChatDisabled'
Expand All @@ -7,40 +7,43 @@ type Props = {
reason?: DisabledChatReasons
}

const DisabledMessageInput = forwardRef<any, Props>(
({ reason }: Props, ref) => {
const tx = useTranslationFunction()

const reasonMessage = useMemo(() => {
switch (reason) {
case DisabledChatReasons.MAILING_LIST:
return tx('messaging_disabled_mailing_list')
case DisabledChatReasons.NOT_IN_GROUP:
return tx('messaging_disabled_not_in_group')
case DisabledChatReasons.DEADDROP:
return tx('messaging_disabled_deaddrop')
case DisabledChatReasons.UNKNOWN:
default:
return tx('messaging_disabled_unknown')
}
}, [reason, tx])

// If no reason was given we return no component
if (!reason) {
return null
const DisabledMessageInput = ({ reason }: Props) => {
const tx = useTranslationFunction()

const reasonMessage = useMemo(() => {
switch (reason) {
case DisabledChatReasons.MAILING_LIST:
return tx('messaging_disabled_mailing_list')
case DisabledChatReasons.NOT_IN_GROUP:
return tx('messaging_disabled_not_in_group')
case DisabledChatReasons.DEADDROP:
return tx('messaging_disabled_deaddrop')
case DisabledChatReasons.DEVICE_CHAT:
return tx('messaging_disabled_device_chat')
case DisabledChatReasons.UNKNOWN:
// Unknown cases are likely to be caused by a new case introduced by a new core update that is not yet handled here,
// but we don't want to crash the UI
return 'messaging_disabled_unknown'
default:
throw new Error('Invalid read-only chat status')
adzialocha marked this conversation as resolved.
Show resolved Hide resolved
}
}, [reason, tx])

// If we're in the device message chat we also do not want to show anything
if (reason === DisabledChatReasons.DEVICE_CHAT) {
return null
}
// If no reason was given we return no component
if (!reason) {
return null
}

return (
<div ref={ref} className='composer composer--disabled-message-input'>
{reasonMessage}
</div>
)
// If we're in the "device message" chat we also do not want to show anything
if (reason === DisabledChatReasons.DEVICE_CHAT) {
return null
}
)

return (
<div className='composer composer--disabled-message-input'>
{reasonMessage}
</div>
)
}

export default DisabledMessageInput
Loading