This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// helpers/backend_helper.js | |
import { get } from "./api_helper"; | |
import * as url from "./url_helper"; | |
//Post | |
export const getPosts = () => get(url.GET_POSTS); | |
//Post | |
export const getPostDetails = (id) => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// helpers/api_helper.js | |
import axios from "axios"; | |
//apply base url for axios | |
const REACT_APP_APP_URL = process.env.REACT_APP_APP_URL; | |
const axiosApi = axios.create({ | |
baseURL: REACT_APP_APP_URL, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// helpers/url_helper.js | |
//Post | |
export const GET_POSTS = "/posts"; | |
export const GET_POST_DETAILS = "/posts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// components/PostDetails.js | |
import React from "react"; | |
import { Container, Row, Col } from "react-bootstrap"; | |
import { useSelector } from "react-redux"; | |
import Loader from "react-loader-spinner"; | |
export default function PostDetails() { | |
const { post, loadingPostDetails } = useSelector( | |
(state) => state.PostReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// components/Posts.js | |
import React from "react"; | |
import { Card, Container, Row, Col } from "react-bootstrap"; | |
import { useSelector } from "react-redux"; | |
import { Link } from "react-router-dom"; | |
import Loader from "react-loader-spinner"; | |
export default function Posts() { | |
const { posts, loadingPosts } = useSelector((state) => state.PostReducer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pages/SinglePost.js | |
import { useEffect } from "react"; | |
import { Container } from "react-bootstrap"; | |
import PostDetails from "../components/PostDetails"; | |
import { useDispatch } from "react-redux"; | |
import { getPostDetails } from "../store/posts/actions"; | |
import { useParams } from "react-router-dom"; | |
function SinglePost() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pages/Home.js | |
import { Container } from "react-bootstrap"; | |
import Posts from "../components/Posts"; | |
import { useEffect } from "react"; | |
import { useDispatch } from "react-redux"; | |
import { getPosts } from "../store/posts/actions"; | |
export default function Home() { | |
let dispatch = useDispatch(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// store/posts/actions.js | |
import { | |
GET_POSTS, | |
GET_POSTS_SUCCESS, | |
GET_POSTS_FAIL, | |
GET_POST_DETAILS, | |
GET_POST_DETAILS_SUCCESS, | |
GET_POST_DETAILS_FAIL, | |
} from "./actionTypes"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// store/posts/reducer.js | |
import { | |
GET_POSTS, | |
GET_POSTS_SUCCESS, | |
GET_POSTS_FAIL, | |
GET_POST_DETAILS, | |
GET_POST_DETAILS_SUCCESS, | |
GET_POST_DETAILS_FAIL, | |
} from "./actionTypes"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// store/posts/saga.js | |
import { takeLatest, put, call } from "redux-saga/effects"; | |
import { GET_POSTS, GET_POST_DETAILS } from "./actionTypes"; | |
import { | |
getPostsSuccess, | |
getPostsFail, | |
getPostDetailsSuccess, |