show loader only while loading (#1131)

This commit is contained in:
Athou
2023-08-11 12:51:42 +02:00
parent 2988938440
commit 366294ab46
3 changed files with 15 additions and 2 deletions

View File

@@ -78,6 +78,7 @@ describe("entries", () => {
sourceWebsiteUrl: "", sourceWebsiteUrl: "",
entries: [{ id: "3" } as Entry], entries: [{ id: "3" } as Entry],
hasMore: true, hasMore: true,
loading: false,
scrollingToEntry: false, scrollingToEntry: false,
}, },
}, },
@@ -102,6 +103,7 @@ describe("entries", () => {
sourceWebsiteUrl: "", sourceWebsiteUrl: "",
entries: [{ id: "3", read: false } as Entry, { id: "4", read: false } as Entry], entries: [{ id: "3", read: false } as Entry, { id: "4", read: false } as Entry],
hasMore: true, hasMore: true,
loading: false,
scrollingToEntry: false, scrollingToEntry: false,
}, },
}, },
@@ -128,6 +130,7 @@ describe("entries", () => {
sourceWebsiteUrl: "", sourceWebsiteUrl: "",
entries: [{ id: "3", read: false } as Entry, { id: "4", read: false } as Entry], entries: [{ id: "3", read: false } as Entry, { id: "4", read: false } as Entry],
hasMore: true, hasMore: true,
loading: false,
scrollingToEntry: false, scrollingToEntry: false,
}, },
}, },

View File

@@ -27,6 +27,7 @@ interface EntriesState {
timestamp?: number timestamp?: number
selectedEntryId?: string selectedEntryId?: string
hasMore: boolean hasMore: boolean
loading: boolean
search?: string search?: string
scrollingToEntry: boolean scrollingToEntry: boolean
} }
@@ -40,6 +41,7 @@ const initialState: EntriesState = {
sourceWebsiteUrl: "", sourceWebsiteUrl: "",
entries: [], entries: [],
hasMore: true, hasMore: true,
loading: false,
scrollingToEntry: false, scrollingToEntry: false,
} }
@@ -329,6 +331,10 @@ export const entriesSlice = createSlice({
state.sourceWebsiteUrl = "" state.sourceWebsiteUrl = ""
state.hasMore = true state.hasMore = true
state.selectedEntryId = undefined state.selectedEntryId = undefined
state.loading = true
})
builder.addCase(loadMoreEntries.pending, state => {
state.loading = true
}) })
builder.addCase(loadEntries.fulfilled, (state, action) => { builder.addCase(loadEntries.fulfilled, (state, action) => {
state.entries = action.payload.entries state.entries = action.payload.entries
@@ -336,12 +342,14 @@ export const entriesSlice = createSlice({
state.sourceLabel = action.payload.name state.sourceLabel = action.payload.name
state.sourceWebsiteUrl = action.payload.feedLink state.sourceWebsiteUrl = action.payload.feedLink
state.hasMore = action.payload.hasMore state.hasMore = action.payload.hasMore
state.loading = false
}) })
builder.addCase(loadMoreEntries.fulfilled, (state, action) => { builder.addCase(loadMoreEntries.fulfilled, (state, action) => {
// remove already existing entries // remove already existing entries
const entriesToAdd = action.payload.entries.filter(e => !state.entries.some(e2 => e.id === e2.id)) const entriesToAdd = action.payload.entries.filter(e => !state.entries.some(e2 => e.id === e2.id))
state.entries = [...state.entries, ...entriesToAdd] state.entries = [...state.entries, ...entriesToAdd]
state.hasMore = action.payload.hasMore state.hasMore = action.payload.hasMore
state.loading = false
}) })
builder.addCase(tagEntry.pending, (state, action) => { builder.addCase(tagEntry.pending, (state, action) => {
state.entries state.entries

View File

@@ -1,4 +1,5 @@
import { Trans } from "@lingui/macro" import { Trans } from "@lingui/macro"
import { Box } from "@mantine/core"
import { openModal } from "@mantine/modals" import { openModal } from "@mantine/modals"
import { Constants } from "app/constants" import { Constants } from "app/constants"
import { import {
@@ -31,6 +32,7 @@ export function FeedEntries() {
const entriesTimestamp = useAppSelector(state => state.entries.timestamp) const entriesTimestamp = useAppSelector(state => state.entries.timestamp)
const selectedEntryId = useAppSelector(state => state.entries.selectedEntryId) const selectedEntryId = useAppSelector(state => state.entries.selectedEntryId)
const hasMore = useAppSelector(state => state.entries.hasMore) const hasMore = useAppSelector(state => state.entries.hasMore)
const loading = useAppSelector(state => state.entries.loading)
const scrollMarks = useAppSelector(state => state.user.settings?.scrollMarks) const scrollMarks = useAppSelector(state => state.user.settings?.scrollMarks)
const scrollingToEntry = useAppSelector(state => state.entries.scrollingToEntry) const scrollingToEntry = useAppSelector(state => state.entries.scrollingToEntry)
const sidebarVisible = useAppSelector(state => state.tree.sidebarVisible) const sidebarVisible = useAppSelector(state => state.tree.sidebarVisible)
@@ -283,9 +285,9 @@ export function FeedEntries() {
<InfiniteScroll <InfiniteScroll
id="entries" id="entries"
initialLoad={false} initialLoad={false}
loadMore={() => dispatch(loadMoreEntries())} loadMore={() => !loading && dispatch(loadMoreEntries())}
hasMore={hasMore} hasMore={hasMore}
loader={<Loader key={0} />} loader={<Box key={0}>{loading && <Loader />}</Box>}
> >
{entries.map(entry => ( {entries.map(entry => (
<div <div