text: import * as api from '../api';
  import { FETCH_ALL, CREATE, UPDATE, DELETE, lIKE_POST } from '../ActionTypes/actionTypes';
  
  // Create the actions.
  
  export const getPosts = () => async (dispatch) => {
    try {
      const { data } = await api.fetchPosts();
      const action = { type: FETCH_ALL, payload: data };
      dispatch(action);
    } catch (error) {
      console.log(error);
    }
  };
  
  export const createPost = (post) => async (dispatch) => {
    try {
      const { data } = await api.createPost(post);
      const action = { type: CREATE, payload: data };
      dispatch(action);
    } catch (error) {
      console.log(error);
    }
  };
  
  export const updatePost = (id, post) => async (dispatch) => {
    try {
      const { data } = await api.updatePost(id, post);
      const action = { type: UPDATE, payload: data };
      dispatch(action);
    } catch (error) {
      console.log('error');
    }
  };
  
  export const deletePost = (id) => async (dispatch) => {
    try {
      await api.deletePost(id);
      const action = { type: DELETE, payload: id };
      dispatch(action);
    } catch (error) {
      console.log(error);
    }
  };
  
  export const likePost = (id) => async (dispatch) => {
    try {
      const { data } = await api.likePost(id);
      const action = { type: lIKE_POST, payload: data };
      dispatch(action);
    } catch (error) {
      console.log(error);
    }
  };
  