|
| 1 | +// project-details.js |
1 | 2 | document.addEventListener("DOMContentLoaded", async () => { |
2 | 3 | const urlParams = new URLSearchParams(window.location.search); |
3 | | - const projectId = urlParams.get("id"); // Keep it as a string |
4 | | - const osType = urlParams.get("os"); // Get OS type from URL |
| 4 | + const projectId = urlParams.get("id"); |
| 5 | + const osType = urlParams.get("os"); |
5 | 6 |
|
6 | | - console.log("Project ID from URL:", projectId); |
7 | | - console.log("OS Type from URL:", osType); |
8 | | - |
9 | | - if (!projectId || !osType) { |
10 | | - console.error("Missing project ID or OS type in URL."); |
11 | | - document.querySelector(".app-container").innerHTML = `<p>Invalid request.</p>`; |
12 | | - return; |
13 | | - } |
| 7 | + // If this file is included on landing.html, quietly bail. |
| 8 | + if (!projectId || !osType) return; |
14 | 9 |
|
15 | 10 | try { |
16 | | - const response = await fetch("../data/portfolio.json"); |
17 | | - const data = await response.json(); |
18 | | - |
19 | | - console.log("🔹 Full Project Data:", data); |
20 | | - |
21 | | - if (!data || !data.apps) { |
22 | | - throw new Error("Invalid project data format."); |
23 | | - } |
24 | | - |
25 | | - // Get the correct app list based on OS type |
26 | | - const apps = data.apps[`${osType}_apps`]; |
27 | | - |
28 | | - if (!apps || !Array.isArray(apps)) { |
29 | | - throw new Error(`Invalid OS type: ${osType}`); |
30 | | - } |
31 | | - |
32 | | - console.log("List of Apps for OS:", osType, apps); |
33 | | - |
34 | | - // Find the project by ID (convert both to strings for consistency) |
35 | | - const project = apps.find(app => String(app.app_id) === String(projectId)); |
36 | | - |
37 | | - console.log("Found Project:", project); |
38 | | - |
39 | | - if (!project) { |
40 | | - throw new Error("Project not found."); |
41 | | - } |
42 | | - |
43 | | - // Update the UI |
44 | | - document.getElementById("app-icon").src = project.icon; |
45 | | - document.getElementById("app-name").textContent = project.name; |
46 | | - document.getElementById("app-category").textContent = project.category; |
47 | | - // document.getElementById("app-rating").textContent = `Rating: ${project.rating}/5`; |
48 | | - document.getElementById("description").textContent = project.description; |
49 | | - document.getElementById("action-button").href = project.app_store_link; |
50 | | - |
51 | | - // Render screenshots |
52 | | - const screenshotContainer = document.getElementById("screenshot-container"); |
53 | | - screenshotContainer.innerHTML = ""; |
54 | | - project.screenshots.forEach(image => { |
55 | | - const img = document.createElement("img"); |
56 | | - img.src = image; |
57 | | - img.alt = "Screenshot"; |
58 | | - img.classList.add("screenshot"); |
59 | | - screenshotContainer.appendChild(img); |
60 | | - }); |
| 11 | + const response = await fetch("../data/portfolio.json"); |
| 12 | + const data = await response.json(); |
| 13 | + const apps = data.apps[`${osType}_apps`]; |
| 14 | + |
| 15 | + const project = apps.find(app => String(app.app_id) === String(projectId)); |
| 16 | + if (!project) throw new Error("Project not found."); |
| 17 | + |
| 18 | + // Update UI |
| 19 | + document.getElementById("app-icon").src = project.icon; |
| 20 | + document.getElementById("app-name").textContent = project.name; |
| 21 | + document.getElementById("app-category").textContent = project.category; |
| 22 | + document.getElementById("description").textContent = project.description; |
| 23 | + document.getElementById("action-button").href = project.app_store_link; |
| 24 | + |
| 25 | + // Render screenshots |
| 26 | + const screenshotContainer = document.getElementById("screenshot-container"); |
| 27 | + screenshotContainer.innerHTML = ""; |
| 28 | + project.screenshots.forEach(image => { |
| 29 | + const img = document.createElement("img"); |
| 30 | + img.src = image; |
| 31 | + img.alt = "Screenshot"; |
| 32 | + img.classList.add("screenshot"); |
| 33 | + screenshotContainer.appendChild(img); |
| 34 | + }); |
| 35 | + |
| 36 | + // Hook up the modal (works here and in popup) |
| 37 | + window.initScreenshotModal(screenshotContainer, project.screenshots); |
61 | 38 |
|
62 | 39 | } catch (error) { |
63 | | - console.error("❌ Error:", error); |
64 | | - document.querySelector(".app-container").innerHTML = `<p>Project not found.</p>`; |
| 40 | + console.error(error); |
| 41 | + const holder = document.querySelector(".app-container"); |
| 42 | + if (holder) holder.innerHTML = `<p>${error.message}</p>`; |
65 | 43 | } |
66 | 44 | }); |
0 commit comments