Skip to content

Commit 3de1209

Browse files
authored
Update Wiki.html
1 parent a75a4c1 commit 3de1209

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Wiki/Wiki.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ <h1>Global Wiki</h1>
6969
<h2>Create New Page</h2>
7070
<input id="new-title" placeholder="Page Title" /><br>
7171
<textarea id="new-content" placeholder="Page Content"></textarea><br>
72-
<button onclick="addPage()">Add Page</button>
72+
<button class="button" onclick="addPage()">Add Page</button>
7373
</div>
7474

7575
<script>
@@ -84,7 +84,9 @@ <h2>Create New Page</h2>
8484
async function fetchWiki() {
8585
try {
8686
const res = await fetch(JSON_BIN_READ_URL);
87+
if (!res.ok) throw new Error('Failed to fetch data');
8788
const data = await res.json();
89+
console.log('Fetched data:', data);
8890
const pages = data.record;
8991
document.getElementById('wiki').innerHTML = pages.map((page, index) => `
9092
<div class="page">
@@ -96,6 +98,7 @@ <h3>${page.title}</h3>
9698
`).join('');
9799
} catch (error) {
98100
console.error('Error fetching wiki:', error);
101+
alert('Failed to load wiki data. Please try again later.');
99102
}
100103
}
101104

@@ -106,9 +109,11 @@ <h3>${page.title}</h3>
106109
headers: { 'Content-Type': 'application/json' },
107110
body: JSON.stringify({ record: pages })
108111
});
112+
if (!res.ok) throw new Error('Failed to update data');
109113
fetchWiki();
110114
} catch (error) {
111115
console.error('Error updating wiki:', error);
116+
alert('Failed to update wiki. Please try again.');
112117
}
113118
}
114119

@@ -121,12 +126,14 @@ <h3>${page.title}</h3>
121126
}
122127
try {
123128
const res = await fetch(JSON_BIN_READ_URL);
129+
if (!res.ok) throw new Error('Failed to fetch data');
124130
const data = await res.json();
125131
const pages = data.record;
126132
pages.push({ title, content });
127133
updateWiki(pages);
128134
} catch (error) {
129135
console.error('Error adding page:', error);
136+
alert('Failed to add page. Please try again.');
130137
}
131138
}
132139

@@ -135,12 +142,14 @@ <h3>${page.title}</h3>
135142
if (newContent !== null) {
136143
try {
137144
const res = await fetch(JSON_BIN_READ_URL);
145+
if (!res.ok) throw new Error('Failed to fetch data');
138146
const data = await res.json();
139147
const pages = data.record;
140148
pages[index].content = newContent;
141149
updateWiki(pages);
142150
} catch (error) {
143151
console.error('Error editing page:', error);
152+
alert('Failed to edit page. Please try again.');
144153
}
145154
}
146155
}
@@ -149,12 +158,14 @@ <h3>${page.title}</h3>
149158
if (confirm('Are you sure you want to delete this page?')) {
150159
try {
151160
const res = await fetch(JSON_BIN_READ_URL);
161+
if (!res.ok) throw new Error('Failed to fetch data');
152162
const data = await res.json();
153163
const pages = data.record;
154164
pages.splice(index, 1);
155165
updateWiki(pages);
156166
} catch (error) {
157167
console.error('Error deleting page:', error);
168+
alert('Failed to delete page. Please try again.');
158169
}
159170
}
160171
}

0 commit comments

Comments
 (0)