TIMBOVILL commited on
Commit
26bf5c6
1 Parent(s): f7e25b8

Update scripts.js

Browse files
Files changed (1) hide show
  1. scripts.js +34 -65
scripts.js CHANGED
@@ -1,85 +1,54 @@
1
- const manifest = [
2
- {
3
- name: "App One",
4
- description: "This is the first app.",
5
- installUrl: "#",
6
- iconUrl: "https://via.placeholder.com/50"
7
- },
8
- {
9
- name: "App Two",
10
- description: "This is the second app.",
11
- installUrl: "#",
12
- iconUrl: "https://via.placeholder.com/50"
13
- },
14
- {
15
- name: "App Three",
16
- description: "This is the third app.",
17
- installUrl: "#",
18
- iconUrl: "https://via.placeholder.com/50"
19
- },
20
- {
21
- name: "App Four",
22
- description: "This is the fourth app.",
23
- installUrl: "#",
24
- iconUrl: "https://via.placeholder.com/50"
25
- }
26
- ];
27
 
28
- function renderAppList() {
29
  const listContainer = document.getElementById('app-list-container');
30
  listContainer.innerHTML = '';
31
- manifest.forEach((app, index) => {
32
  const item = document.createElement('div');
33
  item.className = 'grid-item';
 
34
  item.innerHTML = `
35
  <img src="${app.iconUrl}" alt="${app.name}">
36
  <h2>${app.name}</h2>
37
  `;
38
- item.addEventListener('click', () => showAppDetail(index));
39
  listContainer.appendChild(item);
40
  });
41
  }
42
 
43
  function renderAppDetail(app) {
44
- const detail = document.createElement('div');
45
- detail.className = 'detail-view active';
46
- detail.id = 'app-detail';
47
-
48
- const name = document.createElement('h2');
49
- name.textContent = app.name;
50
-
51
- const description = document.createElement('p');
52
- description.textContent = app.description;
53
-
54
- const installButton = document.createElement('button');
55
- installButton.textContent = 'Install';
56
- installButton.addEventListener('click', () => {
57
- window.location.href = app.installUrl;
58
- });
59
-
60
- detail.appendChild(name);
61
- detail.appendChild(description);
62
- detail.appendChild(installButton);
63
-
64
- return detail;
65
  }
66
 
67
- function showAppDetail(index) {
68
- const detailView = document.getElementById('app-detail');
69
- if (detailView) {
70
- detailView.remove();
71
- }
72
- const appDetail = renderAppDetail(manifest[index]);
73
- document.getElementById('app').appendChild(appDetail);
74
  }
75
 
76
- document.addEventListener('DOMContentLoaded', () => {
77
- renderAppList();
 
78
 
79
- document.getElementById('browse-button').addEventListener('click', () => {
80
- const detailView = document.getElementById('app-detail');
81
- if (detailView) {
82
- detailView.remove();
83
- }
84
- });
85
  });
 
1
+ async function fetchManifest() {
2
+ const response = await fetch('manifest.json');
3
+ return await response.json();
4
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ function renderAppList(apps) {
7
  const listContainer = document.getElementById('app-list-container');
8
  listContainer.innerHTML = '';
9
+ apps.forEach((app, index) => {
10
  const item = document.createElement('div');
11
  item.className = 'grid-item';
12
+ item.style.background = `linear-gradient(135deg, ${app.gradient[0]}, ${app.gradient[1]})`;
13
  item.innerHTML = `
14
  <img src="${app.iconUrl}" alt="${app.name}">
15
  <h2>${app.name}</h2>
16
  `;
17
+ item.addEventListener('click', () => showAppDetail(app));
18
  listContainer.appendChild(item);
19
  });
20
  }
21
 
22
  function renderAppDetail(app) {
23
+ const detailContainer = document.getElementById('app-detail-container');
24
+ detailContainer.innerHTML = `
25
+ <div class="detail-view">
26
+ <h2>${app.name}</h2>
27
+ <p>${app.description}</p>
28
+ ${app.screenshots.map(src => `<img src="${src}" alt="${app.name} Screenshot">`).join('')}
29
+ <button onclick="backToList()">Back to List</button>
30
+ </div>
31
+ `;
32
+ }
33
+
34
+ function showAppDetail(app) {
35
+ const listContainer = document.getElementById('app-list-container');
36
+ const detailContainer = document.getElementById('app-detail-container');
37
+ listContainer.classList.add('hidden');
38
+ detailContainer.classList.remove('hidden');
39
+ renderAppDetail(app);
 
 
 
 
40
  }
41
 
42
+ function backToList() {
43
+ const listContainer = document.getElementById('app-list-container');
44
+ const detailContainer = document.getElementById('app-detail-container');
45
+ listContainer.classList.remove('hidden');
46
+ detailContainer.classList.add('hidden');
 
 
47
  }
48
 
49
+ document.addEventListener('DOMContentLoaded', async () => {
50
+ const apps = await fetchManifest();
51
+ renderAppList(apps);
52
 
53
+ document.getElementById('browse-button').addEventListener('click', backToList);
 
 
 
 
 
54
  });