Skip to content

Commit

Permalink
also manually load more entries if needed when pressing the next entr…
Browse files Browse the repository at this point in the history
…y button in the header (#1557)
  • Loading branch information
Athou committed Sep 24, 2024
1 parent cb92ed7 commit dc86c9b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
16 changes: 12 additions & 4 deletions commafeed-client/src/app/entries/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export const selectPreviousEntry = createAppAsyncThunk(
)
export const selectNextEntry = createAppAsyncThunk(
"entries/entry/selectNext",
(
async (
arg: {
expand: boolean
markAsRead: boolean
Expand All @@ -239,12 +239,20 @@ export const selectNextEntry = createAppAsyncThunk(
thunkApi
) => {
const state = thunkApi.getState()
const { entries } = state.entries
const { entries, hasMore, loading } = state.entries
const nextIndex = entries.findIndex(e => e.id === state.entries.selectedEntryId) + 1
if (nextIndex < entries.length) {

// load more entries if needed
// this can happen if the last entry is too large to fit on the screen and the infinite loader doesn't trigger
if (nextIndex >= entries.length && hasMore && !loading) {
await thunkApi.dispatch(loadMoreEntries())
}

const entriesAfterLoading = thunkApi.getState().entries.entries
if (nextIndex < entriesAfterLoading.length) {
thunkApi.dispatch(
selectEntry({
entry: entries[nextIndex],
entry: entriesAfterLoading[nextIndex],
expand: arg.expand,
markAsRead: arg.markAsRead,
scrollToEntry: arg.scrollToEntry,
Expand Down
52 changes: 22 additions & 30 deletions commafeed-client/src/components/content/FeedEntries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,36 +128,28 @@ export function FeedEntries() {
}, [dispatch, entries, viewMode, scrollMarks, scrollingToEntry])

useMousetrap("r", async () => await dispatch(reloadEntries()))
useMousetrap("j", async () => {
// load more entries if needed
// this can happen if the last entry is too large to fit on the screen and the infinite loader doesn't trigger
if (hasMore && !loading && selectedEntry === entries[entries.length - 1]) {
await dispatch(loadMoreEntries())
}

await dispatch(
selectNextEntry({
expand: true,
markAsRead: true,
scrollToEntry: true,
})
)
})
useMousetrap("n", async () => {
// load more entries if needed
// this can happen if the last entry is too large to fit on the screen and the infinite loader doesn't trigger
if (hasMore && !loading && selectedEntry === entries[entries.length - 1]) {
await dispatch(loadMoreEntries())
}

await dispatch(
selectNextEntry({
expand: false,
markAsRead: false,
scrollToEntry: true,
})
)
})
useMousetrap(
"j",
async () =>
await dispatch(
selectNextEntry({
expand: true,
markAsRead: true,
scrollToEntry: true,
})
)
)
useMousetrap(
"n",
async () =>
await dispatch(
selectNextEntry({
expand: false,
markAsRead: false,
scrollToEntry: true,
})
)
)
useMousetrap(
"k",
async () =>
Expand Down

0 comments on commit dc86c9b

Please sign in to comment.