Commit 6cdc14d6 authored by Ken's avatar Ken

feat: add reset page for home

parent 4addc5b6
...@@ -17,7 +17,11 @@ export const getNews = createAsyncThunk( ...@@ -17,7 +17,11 @@ export const getNews = createAsyncThunk(
const home = createSlice({ const home = createSlice({
name: "home", name: "home",
initialState, initialState,
reducers: {}, reducers: {
handleResetNews: (state) => {
state.newsData = [];
},
},
extraReducers: (builder) => { extraReducers: (builder) => {
builder.addCase(getNews.fulfilled, (state, action: PayloadAction<any>) => { builder.addCase(getNews.fulfilled, (state, action: PayloadAction<any>) => {
const { collection } = action.payload.data; const { collection } = action.payload.data;
...@@ -31,5 +35,6 @@ const home = createSlice({ ...@@ -31,5 +35,6 @@ const home = createSlice({
}, },
}); });
const { reducer } = home; const { reducer, actions } = home;
export const { handleResetNews } = actions;
export default reducer; export default reducer;
...@@ -3,7 +3,7 @@ import { homeSelector } from "app/selectors"; ...@@ -3,7 +3,7 @@ import { homeSelector } from "app/selectors";
import WrapperContainer from "components/WrapperContainer"; import WrapperContainer from "components/WrapperContainer";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import Newspaper from "../../components/Newspaper"; import Newspaper from "../../components/Newspaper";
import { getNews } from "./homePageSlice"; import { getNews, handleResetNews } from "./homePageSlice";
import { IPagination } from "pages/interface"; import { IPagination } from "pages/interface";
import { useInView } from "react-intersection-observer"; import { useInView } from "react-intersection-observer";
import { CircularProgress } from "@mui/material"; import { CircularProgress } from "@mui/material";
...@@ -50,6 +50,11 @@ const HomePage = () => { ...@@ -50,6 +50,11 @@ const HomePage = () => {
} }
}, [inView]); }, [inView]);
useEffect(() => {
dispatch(handleResetNews());
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return ( return (
<main className="homePage"> <main className="homePage">
<WrapperContainer> <WrapperContainer>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment