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

fix: edge case where post hiding might not work for a few posts #1795

Merged
merged 3 commits into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions src/features/feed/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export default function Feed<I>({
const { setScrolledPastSearch } = useContext(FeedSearchContext);

const startRangeRef = useRef(0);
const scrollingRef = useRef(false);

const infiniteScrolling = useAppSelector(
(state) => state.settings.general.posts.infiniteScrolling,
Expand Down Expand Up @@ -267,32 +266,32 @@ export default function Feed<I>({
const onScroll = useRangeChange(
virtuaHandle,
function onRangeChange(start, end) {
if (start < 0 || end < 0 || (!start && !end)) return; // no items rendered

// if scrolled down
const startOffset = header ? 1 : 0; // header counts as item to VList
if (
scrollingRef.current &&
start > startOffset &&
start > startRangeRef.current
) {
// emit what was removed
onRemovedFromTop?.(
filteredItems.slice(
startRangeRef.current - startOffset,
start - startOffset,
),
);
}

startRangeRef.current = start;
updateReadPosts(start, end);

if (end + 10 > filteredItems.length && !loadFailed && infiniteScrolling) {
fetchMore();
}
},
);

function updateReadPosts(start: number, end: number) {
if (start < 0 || end < 0 || (!start && !end)) return; // no items rendered

// if scrolled down
const startOffset = header ? 1 : 0; // header counts as item to VList
if (start > startOffset && start > startRangeRef.current) {
// emit what was removed
onRemovedFromTop?.(
filteredItems.slice(
startRangeRef.current - startOffset,
start - startOffset,
),
);
}

startRangeRef.current = start;
}

const fetchMoreEvent = useEffectEvent(fetchMore);

useEffect(() => {
Expand Down Expand Up @@ -361,13 +360,9 @@ export default function Feed<I>({
}
ref={virtuaHandle}
style={{ height: "100%" }}
onScrollEnd={() => {
scrollingRef.current = false;
}}
onScroll={(offset) => {
onScroll();

scrollingRef.current = true;
setIsListAtTop(offset < 10);
setScrolledPastSearch(offset > 40);
}}
Expand Down
Loading