diff --git a/commafeed-client/src/app/slices/entries.test.ts b/commafeed-client/src/app/slices/entries.test.ts index da08d11a..b7557078 100644 --- a/commafeed-client/src/app/slices/entries.test.ts +++ b/commafeed-client/src/app/slices/entries.test.ts @@ -32,14 +32,7 @@ describe("entries", () => { } as AxiosResponse) const store = configureStore({ reducer: reducers }) - const promise = store.dispatch( - loadEntries({ - sourceType: "feed", - req: { - id: "feed-id", - }, - }) - ) + const promise = store.dispatch(loadEntries({ type: "feed", id: "feed-id" })) expect(store.getState().entries.source.type).toBe("feed") expect(store.getState().entries.source.id).toBe("feed-id") diff --git a/commafeed-client/src/app/slices/entries.ts b/commafeed-client/src/app/slices/entries.ts index f2b46f46..499507f9 100644 --- a/commafeed-client/src/app/slices/entries.ts +++ b/commafeed-client/src/app/slices/entries.ts @@ -2,7 +2,7 @@ import { createAsyncThunk, createSlice, PayloadAction } from "@reduxjs/toolkit" import { client } from "app/client" import { Constants } from "app/constants" import { RootState } from "app/store" -import { Entries, Entry, GetEntriesRequest, MarkRequest } from "app/types" +import { Entries, Entry, MarkRequest } from "app/types" export type EntrySourceType = "category" | "feed" export type EntrySource = { type: EntrySourceType; id: string } @@ -35,18 +35,18 @@ const initialState: EntriesState = { } const getEndpoint = (sourceType: EntrySourceType) => (sourceType === "category" ? client.category.getEntries : client.feed.getEntries) -export const loadEntries = createAsyncThunk( - "entries/load", - async arg => { - const endpoint = getEndpoint(arg.sourceType) - const result = await endpoint({ - ...arg.req, - offset: 0, - limit: 50, - }) - return result.data - } -) +export const loadEntries = createAsyncThunk("entries/load", async (source, thunkApi) => { + const state = thunkApi.getState() + const endpoint = getEndpoint(source.type) + const result = await endpoint({ + id: source.id, + order: state.user.settings?.readingOrder, + readType: state.user.settings?.readingMode, + offset: 0, + limit: 50, + }) + return result.data +}) export const loadMoreEntries = createAsyncThunk("entries/loadMore", async (_, thunkApi) => { const state = thunkApi.getState() const offset = @@ -61,17 +61,9 @@ export const loadMoreEntries = createAsyncThunk("entries/reload", async (_, thunkApi) => { +export const reloadEntries = createAsyncThunk("entries/reload", async (_, thunkApi) => { const state = thunkApi.getState() - const endpoint = getEndpoint(state.entries.source.type) - const result = await endpoint({ - id: state.entries.source.id, - readType: state.user.settings?.readingMode, - order: state.user.settings?.readingOrder, - offset: 0, - limit: 50, - }) - return result.data + thunkApi.dispatch(loadEntries(state.entries.source)) }) export const markEntry = createAsyncThunk( "entries/entry/mark", @@ -160,10 +152,7 @@ export const entriesSlice = createSlice({ }) }) builder.addCase(loadEntries.pending, (state, action) => { - state.source = { - type: action.meta.arg.sourceType, - id: action.meta.arg.req.id, - } + state.source = action.meta.arg state.entries = [] state.timestamp = undefined state.sourceLabel = "" @@ -184,21 +173,6 @@ export const entriesSlice = createSlice({ state.entries = [...state.entries, ...entriesToAdd] state.hasMore = action.payload.hasMore }) - builder.addCase(reloadEntries.pending, state => { - state.entries = [] - state.timestamp = undefined - state.sourceLabel = "" - state.sourceWebsiteUrl = "" - state.hasMore = true - state.selectedEntryId = undefined - }) - builder.addCase(reloadEntries.fulfilled, (state, action) => { - state.entries = action.payload.entries - state.timestamp = action.payload.timestamp - state.sourceLabel = action.payload.name - state.sourceWebsiteUrl = action.payload.feedLink - state.hasMore = action.payload.hasMore - }) }, }) diff --git a/commafeed-client/src/app/slices/user.ts b/commafeed-client/src/app/slices/user.ts index 26c5cc0d..7539d633 100644 --- a/commafeed-client/src/app/slices/user.ts +++ b/commafeed-client/src/app/slices/user.ts @@ -4,6 +4,7 @@ import { createAsyncThunk, createSlice, isAnyOf } from "@reduxjs/toolkit" import { client } from "app/client" import { RootState } from "app/store" import { ReadingMode, ReadingOrder, Settings, UserModel } from "app/types" +import { reloadEntries } from "./entries" interface UserState { settings?: Settings @@ -20,6 +21,7 @@ export const changeReadingMode = createAsyncThunk( @@ -28,6 +30,7 @@ export const changeReadingOrder = createAsyncThunk("settings/language", (language, thunkApi) => { diff --git a/commafeed-client/src/pages/app/FeedEntriesPage.tsx b/commafeed-client/src/pages/app/FeedEntriesPage.tsx index 9cff7114..d3dbf262 100644 --- a/commafeed-client/src/pages/app/FeedEntriesPage.tsx +++ b/commafeed-client/src/pages/app/FeedEntriesPage.tsx @@ -36,8 +36,6 @@ export function FeedEntriesPage(props: FeedEntriesPageProps) { const sourceLabel = useAppSelector(state => state.entries.sourceLabel) const sourceWebsiteUrl = useAppSelector(state => state.entries.sourceWebsiteUrl) const hasMore = useAppSelector(state => state.entries.hasMore) - const readType = useAppSelector(state => state.user.settings?.readingMode) - const order = useAppSelector(state => state.user.settings?.readingOrder) const dispatch = useAppDispatch() const titleClicked = () => { @@ -46,14 +44,8 @@ export function FeedEntriesPage(props: FeedEntriesPageProps) { } useEffect(() => { - if (!readType || !order) return - dispatch( - loadEntries({ - sourceType: props.sourceType, - req: { id, readType, order }, - }) - ) - }, [dispatch, props.sourceType, id, readType, order, location.state]) + dispatch(loadEntries({ type: props.sourceType, id })) + }, [dispatch, props.sourceType, id, location.state]) const hideEditButton = props.sourceType === "category" && id === Constants.categoryIds.all