Skip to content

Instantly share code, notes, and snippets.

View techomoro's full-sized avatar

Techomoro techomoro

View GitHub Profile
// 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) =>
// 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,
});
// helpers/url_helper.js
//Post
export const GET_POSTS = "/posts";
export const GET_POST_DETAILS = "/posts";
// 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
// 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);
// 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() {
// 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();
// 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";
// 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";
// store/posts/saga.js
import { takeLatest, put, call } from "redux-saga/effects";
import { GET_POSTS, GET_POST_DETAILS } from "./actionTypes";
import {
getPostsSuccess,
getPostsFail,
getPostDetailsSuccess,