Skip to content

Commit f38501b

Browse files
committed
refactor(Channels): add scroll to last channel
1 parent 218a369 commit f38501b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

frontend/src/components/Channels.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useDispatch, useSelector } from 'react-redux';
2-
import { useEffect } from 'react';
2+
import { useEffect, useRef } from 'react';
33
import { Nav, ButtonGroup, Dropdown } from 'react-bootstrap';
44
import { useTranslation } from 'react-i18next';
55
import filterWords from 'leo-profanity';
@@ -41,6 +41,14 @@ const Channels = () => {
4141
dispatch(setCurrentChannel(channel));
4242
};
4343

44+
const channelsEndRef = useRef(null);
45+
46+
useEffect(() => {
47+
if (channelsEndRef.current) {
48+
channelsEndRef.current.scrollIntoView({ behavior: 'auto' });
49+
}
50+
}, [channels, currentChannel]);
51+
4452
return (
4553
<Nav className="flex-column nav-fill px-2 mb-3 overflow-auto h-100 d-block">
4654
{channels.map((channel) => (
@@ -92,6 +100,7 @@ const Channels = () => {
92100
)}
93101
</li>
94102
))}
103+
<div ref={channelsEndRef} />
95104
</Nav>
96105
);
97106
};

0 commit comments

Comments
 (0)