const navigate = useNavigate();
const [posts, setPosts] = useState([]);
+ const fetchPosts = async () => {
+ try {
+ console.log('Fetching posts...');
+ const response = await PostService.getPosts();
+ setPosts(response.data);
+ } catch (error) {
+ enqueueSnackbar(`Error fetching posts: ${error.message}`, { variant: 'error' });
+ }
+ };
+
// Fetch posts on mount
React.useEffect(() => {
- const fetchPosts = async () => {
- try {
- const response = await PostService.getPosts();
- setPosts(response.data);
- } catch (error) {
- enqueueSnackbar(`Error fetching posts: ${error.message}`, { variant: 'error' });
- }
- };
+ console.log('loaded...');
+
fetchPosts();
- }, [enqueueSnackbar]);
+ }, []);
const columns = useMemo(() => [
{
import axios from 'axios';
-const BASE_URL = 'http://localhost:3601';
+const base_url = require('../../globals');
-const getAuthHeaders = () => ({
- headers: { Authorization: `Bearer ${localStorage.getItem('token')}` },
-});
export const PostService = {
- async getPosts(params = {}) {
- return await axios.get(`${BASE_URL}/post`, { ...getAuthHeaders(), params });
+ async getPosts() {
+ const url = new URL(`${base_url}post`);
+ console.log(url.toString());
+ return await axios.get(url.toString());
},
async getPostByTitle(title) {
- return await axios.get(`${BASE_URL}/post/title/${title}`, getAuthHeaders());
+ return await axios.get(`${base_url}/post/title/${title}`);
},
async getPost(id) {
- return await axios.get(`${BASE_URL}/post/${id}`, getAuthHeaders());
+ return await axios.get(`${base_url}/post/${id}`);
},
async createPost(data) {
- return await axios.post(`${BASE_URL}/post/create`, data, getAuthHeaders());
+ return await axios.post(`${base_url}/post/create`, data);
},
async updatePost(id, data) {
- return await axios.put(`${BASE_URL}/post/${id}`, data, getAuthHeaders());
+ return await axios.put(`${base_url}/post/${id}`, data);
},
async softDeletePost(id, data) {
- return await axios.put(`${BASE_URL}/post/${id}/soft_delete`, data, getAuthHeaders());
+ return await axios.put(`${base_url}/post/${id}/soft_delete`, data);
},
};
\ No newline at end of file