]> PHS Git Server - phs-admin.git/commitdiff
Adding authentication, media, and messaging.
authorcharleswrayjr <charleswrayjr@gmail.com>
Sat, 13 Sep 2025 08:00:54 +0000 (03:00 -0500)
committercharleswrayjr <charleswrayjr@gmail.com>
Sat, 13 Sep 2025 08:00:54 +0000 (03:00 -0500)
src/app/components/PostsTable.js
src/app/services/posts.js

index 5adcf499d254317060e87f3b37f58002022130c9..dd2f259671515d77412d68503a5e6d8162f28e70 100644 (file)
@@ -15,18 +15,22 @@ const PostsTable = () => {
   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(() => [
     {
index a3211fcb7649ccd57437aa66a34b0f02bb8eb70c..d8713c7ee443fe8033a29efbcda6d80135907613 100644 (file)
@@ -4,29 +4,28 @@
 
 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