Skip to content

Commit

Permalink
feat: make unread accounts position: sticky
Browse files Browse the repository at this point in the history
This somewhat addresses the
"indicators on top and bottom
if there are unread accounts out of screen"
point in #3671.
  • Loading branch information
WofWca committed Jan 22, 2025
1 parent 7a968b6 commit b2663fe
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Added
- added experimental tauri version (`packages/target-tauri`) #4462
- always show accounts with unread messages, even when they're normally scrolled out of view

### Changed
- add some missing translations
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $z-index: (
chatlist-scope-floating-action-button: 1,
jump-down-button-scope-counter: 1,
account-list-sidebar-scope-account-badge: 1,
account-list-sidebar-scope-sticky-account: 1,

// Global Scope
// ============
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ export default function AccountItem({
)
}

const isSticky = unreadCount > 0

const ref = useRef<HTMLButtonElement>(null)
useLayoutEffect(() => {
if (!isSelected) {
Expand Down Expand Up @@ -210,8 +212,13 @@ export default function AccountItem({
// TODO refactor: maybe just use `ResizeObserver`,
// as we do with messages list:
// https://github.com/deltachat/deltachat-desktop/pull/4119
//
// Also watching `isSticky` because the selected account might stop
// being sticky when the user reads its messages,
// and it would get out of view, so we'd want to get it back in view.
//
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSelected, window.__screen])
}, [isSelected, isSticky, window.__screen])

const rovingTabindex = useRovingTabindex(ref)
// TODO `rovingTabindex.setAsActiveElement()` when the active account
Expand All @@ -237,6 +244,7 @@ export default function AccountItem({
className={classNames(styles.account, rovingTabindex.className, {
[styles.active]: isSelected,
[styles['context-menu-active']]: isContextMenuActive,
[styles.isSticky]: isSticky,
})}
onClick={() => onSelectAccount(accountId)}
onContextMenu={onContextMenu}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,27 @@
text-align: start; // To align the "active" indicator

height: var(--als-avatar-size);

margin-bottom: var(--als-avatar-margin);
margin-top: var(--als-avatar-margin);
scroll-margin-bottom: var(--als-avatar-margin);
scroll-margin-top: var(--als-avatar-margin);
// Adding extra `var(--als-avatar-size) + 2 * var(--als-avatar-margin)`
// to the margins so that
// if there is another `.isSticky` account, then that account does not
// cover the account that we want to scroll into view.
// And another extra `2 * var(--als-avatar-margin)` so that it's obvious that
// the other sticky account really is sticky, to make it obviously overlay
// on top of another account, and be positioned perfectly on top of it.
//
// TODO improvement: perhaps it makes sense to keep these at just
// `var(--als-avatar-margin)` in case there is no sticky account above.
// This should be achievable with CSS.
scroll-margin-bottom: calc(
5 * var(--als-avatar-margin) + var(--als-avatar-size)
);
scroll-margin-top: calc(
5 * var(--als-avatar-margin) + var(--als-avatar-size)
);

position: relative;
z-index: $z-index-new-local-scope;

Expand All @@ -90,6 +107,21 @@
}
}

&.isSticky {
position: sticky;
bottom: var(--als-avatar-margin);
top: var(--als-avatar-margin);
// Only needed when this account is scrolled _above_ the visible region.
z-index: map-get($z-index, account-list-sidebar-scope-sticky-account);

.avatar {
opacity: 1;
.content {
box-shadow: 0px 0px 4px 2px #00000040;
}
}
}

&.active,
&:hover,
&.context-menu-active {
Expand Down

0 comments on commit b2663fe

Please sign in to comment.