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

Show an unread badge when there are unread notifs from other accounts #3398

Closed
wants to merge 10 commits into from
44 changes: 35 additions & 9 deletions scss/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,48 @@
}
}

@keyframes unread-badge-bg-anim {
.unread-badge {
border-radius: 50%;
position: relative;
background-color: var(--unreadBadgeColor1);
animation-duration: 1.5s;
animation-iteration-count: infinite;
animation-direction: alternate;
}

@keyframes unread-badge-big-anim {
from {
background-color: var(--unreadBadgeColor1);
color: white;
}
to {
background-color: white;
color: var(--unreadBadgeColor1);
}
}
div.unread-badge-big {
@extend .unread-badge;
width: 24px;
height: 24px;
color: white;
display: flex;
justify-content: center;
align-items: center;
animation-name: unread-badge-big-anim;
animation-timing-function: ease-in;
}

@keyframes unread-badge-small-anim {
from {
background-color: var(--unreadBadgeColor1);
}
to {
background-color: var(--unreadBadgeColor2);
}
}
div.unread-badge {
div.unread-badge-small {
@extend .unread-badge;
width: 14px;
height: 14px;
border-radius: 50%;
position: relative;
animation-duration: 1.5s;
animation-name: unread-badge-bg-anim;
animation-iteration-count: infinite;
animation-direction: alternate;
background-color: var(--unreadBadgeColor1);
animation-name: unread-badge-small-anim;
}
38 changes: 26 additions & 12 deletions src/renderer/components/OtherAccountsUnreadBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import React, { useEffect, useState } from 'react'
import { BackendRemote, onDCEvent } from '../backend-com'
import { selectedAccountId } from '../ScreenController'
import { runtime } from '../runtime'
import { useSettingsStore } from '../stores/settings'
import { DesktopSettingsType } from '../../shared/shared-types'

// Tip of the Day: Keep as many ice creams as you can in your fridge
// for the ice cream outage days. FREE ICE CREAM FOR EVERY1! --Farooq

type ComponentProps = {
top: string
left: string
style: any
big?: boolean
}

export default function OtherAccountsUnreadBadge(props: ComponentProps) {
export default function OtherAccountsUnreadBadge({
style,
big,
}: ComponentProps) {
const [
haveOtherAccountsUnread,
setHaveOtherAccountsUnread,
] = useState<boolean>(false)
otherAccountsUnreadCount,
setOtherAccountsUnreadCount,
] = useState<number>(0)

const settings = useSettingsStore()[0]

Expand All @@ -29,28 +30,41 @@
if (updating) return
updating = true
BackendRemote.rpc.getAllAccountIds().then(accountIds => {
try {
selectedAccountId()
} catch {
return
}
accountIds = accountIds.filter(id => id !== selectedAccountId())
for (const accountId of accountIds) {
BackendRemote.rpc.getFreshMsgs(accountId).then(ids => {
if (ids.length > 0) setHaveOtherAccountsUnread(true)
setOtherAccountsUnreadCount(otherAccountsUnreadCount + ids.length)
})
}
})
updating = false
}
update()

BackendRemote.rpc
.getAllAccountIds()
.then(accountIds =>
accountIds.map(id => onDCEvent(id, 'IncomingMsg', update))
)

update()
return update
}, [settings])

Check warning on line 56 in src/renderer/components/OtherAccountsUnreadBadge.tsx

View workflow job for this annotation

GitHub Actions / Code Validation

React Hook useEffect has a missing dependency: 'otherAccountsUnreadCount'. Either include it or remove the dependency array. You can also do a functional update 'setOtherAccountsUnreadCount(o => ...)' if you only need 'otherAccountsUnreadCount' in the 'setOtherAccountsUnreadCount' call
farooqkz marked this conversation as resolved.
Show resolved Hide resolved

if (settings && settings.desktopSettings.syncAllAccounts && haveOtherAccountsUnread) {
return <div className='unread-badge' style={{ ...props }} />
if (settings?.desktopSettings.syncAllAccounts && otherAccountsUnreadCount) {
if (big) {
return (
<div className='unread-badge-big' style={{ ...style }}>
{otherAccountsUnreadCount}
</div>
)
} else {
return <div className='unread-badge-small' style={{ ...style }} />
}
} else {
return null
}
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ const Sidebar = React.memo(
</div>
<div key='logout' className='sidebar-item' onClick={onLogout}>
{tx('switch_account')}
<OtherAccountsUnreadBadge top='-38px' left='-14px' />
<OtherAccountsUnreadBadge
style={{ top: '-38px', left: '110px' }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer having these offsets in they (s)css unless the are either for prototyping or dynamic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that the parent component has to determine the offsets according to its use. The offsets are different for the hamburger menu icon and in the sidebar.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use global offsets if you can, in this case it does not make much sense to use global offsets. Also they can be styled in the scss file of the component they are used in/with.

big
/>
</div>
<div className='footer'>
<Link href='https://delta.chat' label={'Delta Chat Desktop'} />
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/components/screens/MainScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ export default function MainScreen() {
id='hamburger-menu-button'
>
<Icon icon='menu' aria-label={tx('main_menu')} iconSize={20} />
<OtherAccountsUnreadBadge top='-26px' left='14px' />
<OtherAccountsUnreadBadge
style={{ top: '-26px', left: '14px' }}
/>
</div>
{queryStr.length === 0 && showArchivedChats && (
<>
Expand Down
Loading