Skip to content

Commit a256f51

Browse files
authored
Update edit.html
1 parent e3e818c commit a256f51

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/Wiki/edit.html

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>Edit Scratch Coding Hut Wiki</title>
77
<style>
8-
/* Similar styles as in the main page */
8+
/* Global reset */
99
* {
1010
margin: 0;
1111
padding: 0;
@@ -114,13 +114,15 @@ <h2>Edit Wiki Post</h2>
114114
const wikiContentInput = document.getElementById('wikiContent');
115115
const urlParams = new URLSearchParams(window.location.search);
116116
const wikiTitle = urlParams.get('edit');
117-
117+
118118
if (!wikiTitle) {
119119
alert('No wiki title provided to edit.');
120-
window.location.href = 'index.html';
120+
window.location.href = 'index.html'; // Redirect to main page
121121
return;
122122
}
123123

124+
let wikiId = null;
125+
124126
// Fetch the wiki to edit
125127
const fetchWiki = async () => {
126128
try {
@@ -131,8 +133,9 @@ <h2>Edit Wiki Post</h2>
131133

132134
if (!wiki) {
133135
alert('Wiki not found!');
134-
window.location.href = 'Wiki/wiki';
136+
window.location.href = 'Wiki/wiki'; // Redirect to wiki list if not found
135137
} else {
138+
wikiId = wiki.id; // Store the wiki ID
136139
wikiTitleInput.value = wiki.title;
137140
wikiContentInput.value = wiki.content;
138141
}
@@ -154,8 +157,13 @@ <h2>Edit Wiki Post</h2>
154157
return;
155158
}
156159

160+
if (!wikiId) {
161+
alert('Wiki ID not found');
162+
return;
163+
}
164+
157165
try {
158-
const response = await fetch(`${backendUrl}/wikis`, {
166+
const response = await fetch(`${backendUrl}/wikis/${wikiId}`, {
159167
method: 'PUT',
160168
headers: { 'Content-Type': 'application/json' },
161169
body: JSON.stringify({

0 commit comments

Comments
 (0)