|
9 | 9 |
|
10 | 10 | async function fetchPages() { |
11 | 11 | const response = await fetch(apiUrl); |
12 | | - const pages = await response.json(); |
| 12 | + const data = await response.json(); |
| 13 | + |
| 14 | + console.log('Fetched data:', data); // Log the response to check its structure |
| 15 | + |
| 16 | + // Check if data has a record property or handle the structure appropriately |
| 17 | + const pages = data.record || []; // Adjust based on actual response structure |
13 | 18 | renderPages(pages); |
14 | 19 | } |
15 | 20 |
|
16 | 21 | async function createPage() { |
17 | | - const title = prompt('Enter title:'); |
18 | | - const content = prompt('Enter content:'); |
| 22 | + const title = document.getElementById('createTitle').value; |
| 23 | + const content = document.getElementById('createContent').value; |
19 | 24 | if (!title || !content) return; |
| 25 | + |
20 | 26 | await fetch(apiUrl, { |
21 | 27 | method: 'POST', |
22 | 28 | headers: { 'Content-Type': 'application/json' }, |
23 | 29 | body: JSON.stringify({ title, body: content }) |
24 | 30 | }); |
| 31 | + |
| 32 | + // Clear the input fields and refresh the list of pages |
| 33 | + document.getElementById('createTitle').value = ''; |
| 34 | + document.getElementById('createContent').value = ''; |
25 | 35 | fetchPages(); |
26 | 36 | } |
27 | 37 |
|
|
46 | 56 | function renderPages(pages) { |
47 | 57 | const pagesDiv = document.getElementById('pages'); |
48 | 58 | pagesDiv.innerHTML = ''; |
| 59 | + |
49 | 60 | pages.forEach(page => { |
50 | 61 | pagesDiv.innerHTML += ` |
51 | 62 | <div class="card"> |
|
64 | 75 | window.onload = fetchPages; |
65 | 76 | </script> |
66 | 77 | <style> |
67 | | - body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #0f172a; color: #f8fafc; margin: 0; padding: 0; } |
68 | | - .container { max-width: 800px; margin: 50px auto; padding: 20px; } |
69 | | - .card { background: #1e293b; padding: 20px; border-radius: 16px; margin-bottom: 15px; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5); transition: transform 0.2s, box-shadow 0.2s; } |
70 | | - .card:hover { transform: scale(1.02); box-shadow: 0 8px 20px rgba(0, 0, 0, 0.7); } |
71 | | - .card-content { margin-bottom: 10px; } |
72 | | - .card-content strong { font-size: 1.5em; color: #38bdf8; } |
73 | | - .actions { display: flex; gap: 10px; } |
74 | | - button { padding: 10px 15px; border-radius: 12px; border: none; background: #38bdf8; color: #0f172a; font-weight: bold; cursor: pointer; transition: background 0.3s ease-in-out; } |
75 | | - button:hover { background: #7dd3fc; } |
| 78 | + body { |
| 79 | + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; |
| 80 | + background: #0f172a; |
| 81 | + color: #f8fafc; |
| 82 | + margin: 0; |
| 83 | + padding: 0; |
| 84 | + } |
| 85 | + |
| 86 | + .container { |
| 87 | + max-width: 800px; |
| 88 | + margin: 50px auto; |
| 89 | + padding: 20px; |
| 90 | + } |
| 91 | + |
| 92 | + .card { |
| 93 | + background: #1e293b; |
| 94 | + padding: 20px; |
| 95 | + border-radius: 16px; |
| 96 | + margin-bottom: 15px; |
| 97 | + box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5); |
| 98 | + transition: transform 0.2s, box-shadow 0.2s; |
| 99 | + } |
| 100 | + |
| 101 | + .card:hover { |
| 102 | + transform: scale(1.02); |
| 103 | + box-shadow: 0 8px 20px rgba(0, 0, 0, 0.7); |
| 104 | + } |
| 105 | + |
| 106 | + .card-content { |
| 107 | + margin-bottom: 10px; |
| 108 | + } |
| 109 | + |
| 110 | + .card-content strong { |
| 111 | + font-size: 1.5em; |
| 112 | + color: #38bdf8; |
| 113 | + } |
| 114 | + |
| 115 | + .actions { |
| 116 | + display: flex; |
| 117 | + gap: 10px; |
| 118 | + } |
| 119 | + |
| 120 | + button { |
| 121 | + padding: 10px 15px; |
| 122 | + border-radius: 12px; |
| 123 | + border: none; |
| 124 | + background: #38bdf8; |
| 125 | + color: #0f172a; |
| 126 | + font-weight: bold; |
| 127 | + cursor: pointer; |
| 128 | + transition: background 0.3s ease-in-out; |
| 129 | + } |
| 130 | + |
| 131 | + button:hover { |
| 132 | + background: #7dd3fc; |
| 133 | + } |
| 134 | + |
| 135 | + .form-container { |
| 136 | + margin-bottom: 20px; |
| 137 | + background: #1e293b; |
| 138 | + padding: 20px; |
| 139 | + border-radius: 8px; |
| 140 | + box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3); |
| 141 | + } |
| 142 | + |
| 143 | + .form-container input, |
| 144 | + .form-container textarea { |
| 145 | + width: 100%; |
| 146 | + padding: 10px; |
| 147 | + margin-bottom: 10px; |
| 148 | + border-radius: 8px; |
| 149 | + border: 1px solid #38bdf8; |
| 150 | + background: #0f172a; |
| 151 | + color: #f8fafc; |
| 152 | + font-size: 1em; |
| 153 | + } |
| 154 | + |
| 155 | + .form-container button { |
| 156 | + width: 100%; |
| 157 | + } |
| 158 | + |
| 159 | + h2 { |
| 160 | + font-size: 1.8em; |
| 161 | + color: #38bdf8; |
| 162 | + } |
76 | 163 | </style> |
77 | 164 | </head> |
78 | 165 | <body> |
79 | 166 | <div class="container"> |
80 | | - <button onclick="createPage()">➕ Create New Wiki</button> |
81 | | - <div id="pages"></div> |
| 167 | + <h2>Create New Wiki</h2> |
| 168 | + <div class="form-container"> |
| 169 | + <input type="text" id="createTitle" placeholder="Enter title" /> |
| 170 | + <textarea id="createContent" placeholder="Enter content"></textarea> |
| 171 | + <button onclick="createPage()">➕ Create Wiki</button> |
| 172 | + </div> |
| 173 | + |
| 174 | + <div id="pages"> |
| 175 | + <!-- List of pages will appear here --> |
| 176 | + </div> |
82 | 177 | </div> |
83 | 178 | </body> |
84 | 179 | </html> |
0 commit comments