|
| 1 | +const CONFIG = { |
| 2 | + BASE_URL: "./assets/js/data/", |
| 3 | + FILE_EXT: ".json", |
| 4 | +}; |
| 5 | + |
1 | 6 | function toggleDropdown(dropdownId) {
|
2 | 7 | const dropdown = document.getElementById(dropdownId);
|
3 | 8 |
|
@@ -32,68 +37,60 @@ function syntaxHighlight(json) {
|
32 | 37 | );
|
33 | 38 | }
|
34 | 39 |
|
35 |
| -const experiences = { |
36 |
| - message: "OK", |
37 |
| - data: [ |
38 |
| - { |
39 |
| - title: "Freelance Backend Developer", |
40 |
| - description: |
41 |
| - "Working as a backend developer, responsible for developing and maintaining the company's backend services", |
42 |
| - start_date: "January 2024", |
43 |
| - end_date: null, |
44 |
| - is_active: true, |
45 |
| - skills: ["Kotlin", "Spring Boot", "PostgreSQL", "Gitlab", "Scrum"], |
46 |
| - }, |
47 |
| - { |
48 |
| - title: "Freelance Backend Developer", |
49 |
| - company_name: "PT. Qatros Teknologi Nusantara", |
50 |
| - description: |
51 |
| - "As a backend developer, I create APIs, design database systems, and integrate third-party APIs like Challonge for tournament bracket generator. At MovesGG, a platform for gaming tournaments, I focus on building scalable backend services to handle tournament management and ensure smooth integration with external services.", |
52 |
| - start_date: "December 2022", |
53 |
| - end_date: "March 2023", |
54 |
| - is_active: false, |
55 |
| - skills: ["Ruby", "Ruby on Rails", "Scrum", "PostgreSQL", "Gitlab"], |
56 |
| - }, |
57 |
| - { |
58 |
| - title: "Internship Web Developer", |
59 |
| - company_name: "PT. Git Solution", |
60 |
| - description: |
61 |
| - "Internship as a full stack web developer, develop online learning management system (LMS) using Laravel.", |
62 |
| - start_date: "September 2021", |
63 |
| - end_date: "December 2021", |
64 |
| - is_active: false, |
65 |
| - skills: ["PHP", "Laravel", "PostgreSQL", "Git", "RESTApi"], |
66 |
| - }, |
67 |
| - ], |
68 |
| -}; |
| 40 | +async function getContent(filename) { |
| 41 | + return fetch(`${CONFIG.BASE_URL}/${filename}${CONFIG.FILE_EXT}`) |
| 42 | + .then((response) => response.json()) |
| 43 | + .then((data) => data) |
| 44 | + .catch((error) => |
| 45 | + console.error("Something shit happened: " + error.message) |
| 46 | + ); |
| 47 | +} |
69 | 48 |
|
70 |
| -const projects = { |
71 |
| - message: |
72 |
| - "The project I worked on was an internal system at my previous company, and due to confidentiality agreements, I’m unable to share specific details.", |
73 |
| - data: null, |
74 |
| -}; |
| 49 | +function createContentHtml(content, contentJson) { |
| 50 | + const { name, method, url, description, status } = content; |
75 | 51 |
|
76 |
| -const reachMeOut = { |
77 |
| - message: "OK", |
78 |
| - data: [ |
79 |
| - { |
80 |
| - platform_name: "linkedin", |
81 |
| - url: "https://www.linkedin.com/in/hafizalfikri/", |
82 |
| - }, |
83 |
| - { |
84 |
| - platform_name: "github", |
85 |
| - url: "https://github.com/escape-dev", |
86 |
| - }, |
87 |
| - { |
88 |
| - platform_name: "email", |
89 |
| - |
90 |
| - }, |
91 |
| - ], |
92 |
| -}; |
| 52 | + return `<div class="dropdown-container"> |
| 53 | + <button class="dropdown-btn" onclick="toggleDropdown('${name}')"> |
| 54 | + <span class="get-method">${method}</span> |
| 55 | + <p class="dropdown-description"> |
| 56 | + ${url} |
| 57 | + <small>${description}</small> |
| 58 | + </p> |
| 59 | + </button> |
| 60 | + <div class="dropdown-content" id="${name}"> |
| 61 | + <table> |
| 62 | + <tr> |
| 63 | + <th>Code</th> |
| 64 | + <th>Description</th> |
| 65 | + </tr> |
| 66 | + <tr> |
| 67 | + <td class="json-viewer">${status}</td> |
| 68 | + <td class="json-viewer"> |
| 69 | + <pre> ${syntaxHighlight(contentJson)} </pre> |
| 70 | + </td> |
| 71 | + </tr> |
| 72 | + </table> |
| 73 | + </div> |
| 74 | + </div>`; |
| 75 | +} |
| 76 | + |
| 77 | +async function renderContent() { |
| 78 | + const mainContent = document.getElementById("main-content"); |
| 79 | + const listContents = await getContent("listContents"); |
| 80 | + |
| 81 | + const contentPromises = listContents.data.map(async (value) => { |
| 82 | + const contentJson = await getContent(value.name); |
| 83 | + |
| 84 | + return { value, contentJson }; |
| 85 | + }); |
| 86 | + |
| 87 | + const contents = await Promise.all(contentPromises); |
| 88 | + |
| 89 | + const contentHtml = contents |
| 90 | + .map(({ value, contentJson }) => createContentHtml(value, contentJson)) |
| 91 | + .join(""); |
| 92 | + |
| 93 | + mainContent.innerHTML = contentHtml; |
| 94 | +} |
93 | 95 |
|
94 |
| -document.getElementById("experience-content").innerHTML = |
95 |
| - syntaxHighlight(experiences); |
96 |
| -document.getElementById("projects-content").innerHTML = |
97 |
| - syntaxHighlight(projects); |
98 |
| -document.getElementById("reach-me-out-content").innerHTML = |
99 |
| - syntaxHighlight(reachMeOut); |
| 96 | +document.addEventListener("DOMContentLoaded", renderContent); |
0 commit comments