Skip to content

Commit

Permalink
Add variable for scroll loading status JC-720
Browse files Browse the repository at this point in the history
  • Loading branch information
TebyakinaEkaterina committed Aug 21, 2024
1 parent 1ee153f commit 9b38de1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions apps/react/src/store/anime/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const selectAnimeListLoading = createSelector(
isLoading => isLoading,
);

/** Select anime additional loading state. */
export const selectAdditionalAnimeLoading = createSelector(
(state: RootState) => state.anime.isAdditionalLoading,
isAdditionalLoading => isAdditionalLoading,
);

/** Select anime error state. */
export const selectAnimeListError = createSelector(
(state: RootState) => state.anime.error,
Expand Down
6 changes: 3 additions & 3 deletions apps/react/src/store/anime/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const animeSlice = createSlice({
})

.addCase(fetchNewPage.pending, state => {
state.isLoading = true;
state.isAdditionalLoading = true;
})
.addCase(fetchNewPage.fulfilled, (state, action) => {
const { byId, allIds } = state.animeList;
Expand All @@ -47,12 +47,12 @@ export const animeSlice = createSlice({

state.nextPage = action.payload.next;
state.previousPage = action.payload.previous;
state.isLoading = false;
state.isAdditionalLoading = false;
})
.addCase(fetchNewPage.rejected, (state, action) => {
if (action.error.message) {
state.error = action.error.message;
}
state.isLoading = false;
state.isAdditionalLoading = false;
}),
});
4 changes: 4 additions & 0 deletions apps/react/src/store/anime/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ export type AnimeListState = {

/** Whether the anime are loading or not. */
readonly isLoading: boolean;

/** Whether the new page of anime list are loading or not. */
readonly isAdditionalLoading: boolean;
};

/** Initial state for anime list state. */
export const initialState: AnimeListState = {
isLoading: false,
isAdditionalLoading: false,
animeList: { byId: {}, allIds: [] },
previousPage: null,
nextPage: null,
Expand Down

0 comments on commit 9b38de1

Please sign in to comment.