Newer
Older
My-Portfolio / frontend / src / components / sections / MainPage.jsx
  1. import React, { useContext, useState, useEffect, Fragment } from "react";
  2. import { LoadingContext } from "../utils/LoadingContext";
  3. import { fetchData } from "../../api";
  4. import Home from "./Home";
  5. import About from "./About";
  6. import Work from "./Work";
  7. import Skills from "./Skills";
  8. import Activity from "./Activity";
  9. import Contact from "./Contact";
  10. import SectionObserver from "./SectionObserver";
  11. const GET_INTRO = import.meta.env.VITE_GET_INTRO;
  12. const GET_ABOUT = import.meta.env.VITE_GET_ABOUT;
  13. const GET_WORK = import.meta.env.VITE_GET_WORK;
  14. const GET_SKILLS = import.meta.env.VITE_GET_SKILLS;
  15. const GET_ACTIVITY = import.meta.env.VITE_GET_ACTIVITY;
  16. const GET_CONTACT = import.meta.env.VITE_GET_CONTACT;
  17. const MainPage = () => {
  18. const { isLoading, setIsLoading } = useContext(LoadingContext);
  19. const activeSections = SectionObserver();
  20. // State to store fetched data
  21. const [introData, setIntroData] = useState([]);
  22. const [aboutMe, setAboutData] = useState([]);
  23. const [projects, setWorkData] = useState([]);
  24. const [skillsData, setSkillsData] = useState([]);
  25. const [activityData, setActivityData] = useState([]);
  26. const [contactData, setContactData] = useState([]);
  27. useEffect(() => {
  28. const fetchAllData = async () => {
  29. try {
  30. setIsLoading(true); // Set loading to true before fetching data
  31. const [intro, about, work, skills, activity, contact] =
  32. await Promise.all([
  33. fetchData(GET_INTRO),
  34. fetchData(GET_ABOUT),
  35. fetchData(GET_WORK),
  36. fetchData(GET_SKILLS),
  37. fetchData(GET_ACTIVITY),
  38. fetchData(GET_CONTACT),
  39. ]);
  40. // Store fetched data in state
  41. setIntroData(intro);
  42. setAboutData(about);
  43. setWorkData(work);
  44. setSkillsData(skills);
  45. setActivityData(activity);
  46. setContactData(contact);
  47. } catch (error) {
  48. console.error("Error fetching data:", error);
  49. } finally {
  50. setIsLoading(false); // Set loading to false after fetching data
  51. }
  52. };
  53. fetchAllData();
  54. }, [setIsLoading]);
  55. if (isLoading) {
  56. return <div>Loading...</div>; // Or your custom loading spinner
  57. }
  58. return (
  59. <Fragment>
  60. {/* Home Section */}
  61. <section id="home" className="bg-[#181818] text-white">
  62. <Home isVisible={activeSections.has("home")} introData={introData} />
  63. {/* Diagonal separator */}
  64. <svg
  65. xmlns="http://www.w3.org/2000/svg"
  66. width="100%"
  67. height="100"
  68. viewBox="0 0 1200 100"
  69. preserveAspectRatio="none"
  70. >
  71. <polygon
  72. points="0,0 1200,0 1200,100 0,100"
  73. style={{ fill: "#232323" }}
  74. />
  75. <polygon
  76. points="0,0 1200,100 1200,0 0,0"
  77. style={{ fill: "#181818" }}
  78. />
  79. </svg>
  80. </section>
  81. {/* About Section */}
  82. <section id="about" className="bg-[#232323] text-white">
  83. <About isVisible={activeSections.has("about")} aboutMe={aboutMe} />
  84. {/* Diagonal separator */}
  85. <svg
  86. xmlns="http://www.w3.org/2000/svg"
  87. width="100%"
  88. height="100"
  89. viewBox="0 0 1200 100"
  90. preserveAspectRatio="none"
  91. >
  92. <polygon
  93. points="0,0 1200,0 1200,100 0,100"
  94. style={{ fill: "#232323" }}
  95. />
  96. <polygon
  97. points="0,100 1200,0 1200,100 0,100"
  98. style={{ fill: "#181818" }}
  99. />
  100. </svg>
  101. </section>
  102. {/* Work Section */}
  103. <section id="work" className="bg-[#181818] text-white">
  104. <Work isVisible={activeSections.has("work")} projects={projects} />
  105. {/* Diagonal separator */}
  106. <svg
  107. xmlns="http://www.w3.org/2000/svg"
  108. width="100%"
  109. height="100"
  110. viewBox="0 0 1200 100"
  111. preserveAspectRatio="none"
  112. >
  113. <polygon
  114. points="0,0 1200,0 1200,100 0,100"
  115. style={{ fill: "#232323" }}
  116. />
  117. <polygon
  118. points="0,0 1200,100 1200,0 0,0"
  119. style={{ fill: "#181818" }}
  120. />
  121. </svg>
  122. </section>
  123. {/* Skills Section */}
  124. <section id="skills" className="bg-[#232323] text-white">
  125. <Skills
  126. isVisible={activeSections.has("skills")}
  127. skillsData={skillsData}
  128. />
  129. {/* Diagonal separator */}
  130. <svg
  131. xmlns="http://www.w3.org/2000/svg"
  132. width="100%"
  133. height="100"
  134. viewBox="0 0 1200 100"
  135. preserveAspectRatio="none"
  136. >
  137. <polygon
  138. points="0,0 1200,0 1200,100 0,100"
  139. style={{ fill: "#232323" }}
  140. />
  141. <polygon
  142. points="0,100 1200,0 1200,100 0,100"
  143. style={{ fill: "#181818" }}
  144. />
  145. </svg>
  146. </section>
  147. {/* Activity Section */}
  148. <section id="activity" className="bg-[#181818] text-white">
  149. <Activity
  150. isVisible={activeSections.has("activity")}
  151. activityData={activityData}
  152. />
  153. {/* Diagonal separator */}
  154. <svg
  155. xmlns="http://www.w3.org/2000/svg"
  156. width="100%"
  157. height="100"
  158. viewBox="0 0 1200 100"
  159. preserveAspectRatio="none"
  160. >
  161. <polygon
  162. points="0,0 1200,0 1200,100 0,100"
  163. style={{ fill: "#232323" }}
  164. />
  165. <polygon
  166. points="0,0 1200,100 1200,0 0,0"
  167. style={{ fill: "#181818" }}
  168. />
  169. </svg>
  170. </section>
  171. {/* Contact Section */}
  172. <section id="contact" className="bg-[#232323] text-white">
  173. <Contact
  174. isVisible={activeSections.has("contact")}
  175. contactData={contactData}
  176. />
  177. </section>
  178. </Fragment>
  179. );
  180. };
  181. export default MainPage;