MCPcopy Create free account
hub / github.com/Bitbox-Connect/Bitbox / ProjectStates

Function ProjectStates

client/src/context/ProjectState.jsx:6–112  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

4// import SearchProjects from "../component/SearchProject.jsx";
5
6const ProjectStates = (props) => {
7 const VITE_SERVER_PORT = import.meta.env.VITE_SERVER_PORT || 'https://bitbox-uxbo.onrender.com';
8 const projectsInitial = [];
9
10 const [userProjects, setUserProjects] = useState(projectsInitial);
11 const [globalProjects, setGlobalProjects] = useState(projectsInitial); // Initialize global projects state
12
13 // Get All Globally Project
14 const getGlobalProjects = async () => {
15 // API CALL - Fetch All Global Projects
16 const response = await fetch(`${VITE_SERVER_PORT}/api/projects/fetchallglobalprojects`, {
17 method: "GET",
18 headers: {
19 "Content-Type": "application/json"
20 }
21 });
22 const json = await response.json();
23 setGlobalProjects(json.reverse());
24 }
25
26 // Get All Your Project
27 const getUserProjects = async () => {
28 // API CALL - Fetch All User Projects
29 const response = await fetch(`${VITE_SERVER_PORT}/api/projects/fetchalluserprojects`, {
30 method: "GET",
31 headers: {
32 "Content-Type": "application/json",
33 "auth-token": localStorage.getItem('token')
34 }
35 });
36 const json = await response.json();
37 setUserProjects(json.reverse());
38 }
39
40 // Add a Project
41 const addProject = async (title, description, gitHubLink, youTubeLink) => {
42 // API CALL - Add Projects
43 const response = await fetch(`${VITE_SERVER_PORT}/api/projects/addproject`, {
44 method: "POST",
45 headers: {
46 "Content-Type": "application/json",
47 "auth-token": localStorage.getItem('token')
48 },
49 body: JSON.stringify({ title, description, gitHubLink, youTubeLink }),
50 });
51 const project = await response.json();
52 setUserProjects([project, ...userProjects]);
53 props.setProgress(100)
54 }
55
56 // Delete a Project
57 const deleteProject = async (id) => {
58 // API CALL - Delete Project
59 const response = await fetch(`${VITE_SERVER_PORT}/api/projects/deleteproject/${id}`, {
60 method: "DELETE",
61 headers: {
62 "Content-Type": "application/json",
63 "auth-token": localStorage.getItem('token')

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected