scroll into view

This commit is contained in:
Bernt Christian Egeland 2021-08-23 18:37:42 +02:00
parent 4895a533cc
commit 0eefea6d0b
2 changed files with 5 additions and 9 deletions

View File

@ -15,20 +15,17 @@ export default function Event({ eventId, close, scrollRef }) {
const apiHost = useApiHost(); const apiHost = useApiHost();
const { data, status } = useEvent(eventId); const { data, status } = useEvent(eventId);
const [showDialog, setShowDialog] = useState(false); const [showDialog, setShowDialog] = useState(false);
const [shouldScroll, setShouldScroll] = useState(true);
const [deleteStatus, setDeleteStatus] = useState(FetchStatus.NONE); const [deleteStatus, setDeleteStatus] = useState(FetchStatus.NONE);
const setDeleteEvent = useDelete(); const setDeleteEvent = useDelete();
useEffect(() => { useEffect(() => {
// Call Events.js scroll when this event has been mounted. // Scroll event into view when component has been mounted.
// scrollIntoView(eventId); if (shouldScroll && scrollRef && scrollRef[eventId]) {
scrollToElement();
}, [data]);
const scrollToElement = useCallback(() => {
if (scrollRef && scrollRef[eventId]) {
scrollRef[eventId].scrollIntoView(); scrollRef[eventId].scrollIntoView();
setShouldScroll(false);
} }
}, [scrollRef]); }, [data, scrollRef, eventId, shouldScroll]);
const handleClickDelete = () => { const handleClickDelete = () => {
setShowDialog(true); setShowDialog(true);

View File

@ -80,7 +80,6 @@ export default function Events({ path: pathname, limit = API_LIMIT } = {}) {
} }
if (data && Array.isArray(data) && data.length + deleted < limit) { if (data && Array.isArray(data) && data.length + deleted < limit) {
console.log('reached end');
dispatch({ type: 'REACHED_END', meta: { searchString } }); dispatch({ type: 'REACHED_END', meta: { searchString } });
} }
}, [data, limit, searchString, searchStrings, deleted]); }, [data, limit, searchString, searchStrings, deleted]);