Skip to content

Commit 0855461

Browse files
committed
chore: simplify sponsored message style and scroll handler
1 parent 9785f82 commit 0855461

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

src/components/middle/FloatingActionButtons.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ const FloatingActionButtons: FC<OwnProps & StateProps> = ({
7575
}
7676
}, [chatId, fetchUnreadMentions, hasUnreadMentions]);
7777

78+
const animateScrollToLastMessage = (container?: HTMLDivElement | null) => {
79+
if (!container) return;
80+
const lastMessageElement = getLastMessageElement(container);
81+
82+
if (!lastMessageElement) return;
83+
animateScroll(container, lastMessageElement, 'end', sponsoredMessage ? FOCUS_SPONSORED_MARGIN : FOCUS_MARGIN);
84+
};
85+
7886
const handleClick = useLastCallback(() => {
7987
if (!isShown) return;
8088

@@ -83,21 +91,13 @@ const FloatingActionButtons: FC<OwnProps & StateProps> = ({
8391
if (messageListType === 'pinned') {
8492
const container = elementRef.current?.parentElement?.querySelector<HTMLDivElement>('.MessageList.type-pinned');
8593

86-
if (!container) return;
87-
const lastMessageElement = getLastMessageElement(container);
88-
89-
if (!lastMessageElement) return;
90-
animateScroll(container, lastMessageElement, 'end', sponsoredMessage ? FOCUS_SPONSORED_MARGIN : FOCUS_MARGIN);
94+
animateScrollToLastMessage(container);
9195
}
9296

9397
if (messageListType === 'scheduled') {
9498
const container = elementRef.current?.parentElement?.querySelector<HTMLDivElement>('.MessageList.type-scheduled');
9599

96-
if (!container) return;
97-
const lastMessageElement = getLastMessageElement(container);
98-
99-
if (!lastMessageElement) return;
100-
animateScroll(container, lastMessageElement, 'end', FOCUS_MARGIN);
100+
animateScrollToLastMessage(container);
101101
}
102102
});
103103

src/components/middle/MessageList.scss

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,34 @@
7676
}
7777
}
7878

79+
@mixin last-element-margin {
80+
margin-bottom: 5.625rem;
81+
82+
@media (max-width: 600px) {
83+
margin-bottom: 4.25rem;
84+
}
85+
}
86+
7987
&.select-mode-active,
8088
&.type-pinned {
8189
margin-bottom: 0;
8290

8391
&:not(.with-sponsored-message, .is-channel, .is-group-chat),
8492
&.select-mode-active:not(.with-sponsored-message) {
8593
.last-in-list {
86-
margin-bottom: 5.625rem;
87-
88-
@media (max-width: 600px) {
89-
margin-bottom: 4.25rem;
90-
}
94+
@include last-element-margin;
9195

9296
&.ActionMessage {
9397
padding-bottom: 0.125rem;
9498
}
9599
}
96100
}
101+
102+
&.select-mode-active {
103+
.SponsoredMessage {
104+
@include last-element-margin;
105+
}
106+
}
97107
}
98108

99109
@media (max-width: 600px) {

src/components/middle/message/SponsoredMessage.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@
55
margin-top: -0.5rem;
66
margin-bottom: 0.5rem;
77

8-
&.select-mode {
9-
margin-bottom: 5.625rem;
10-
11-
@media (max-width: 600px) {
12-
margin-bottom: 4.25rem;
13-
}
14-
}
15-
168
&::before {
179
display: none;
1810
}

0 commit comments

Comments
 (0)