5
5
< meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
6
< title > Edit Scratch Coding Hut Wiki</ title >
7
7
< style >
8
- /* Similar styles as in the main page */
8
+ /* Global reset */
9
9
* {
10
10
margin : 0 ;
11
11
padding : 0 ;
@@ -114,13 +114,15 @@ <h2>Edit Wiki Post</h2>
114
114
const wikiContentInput = document . getElementById ( 'wikiContent' ) ;
115
115
const urlParams = new URLSearchParams ( window . location . search ) ;
116
116
const wikiTitle = urlParams . get ( 'edit' ) ;
117
-
117
+
118
118
if ( ! wikiTitle ) {
119
119
alert ( 'No wiki title provided to edit.' ) ;
120
- window . location . href = 'index.html' ;
120
+ window . location . href = 'index.html' ; // Redirect to main page
121
121
return ;
122
122
}
123
123
124
+ let wikiId = null ;
125
+
124
126
// Fetch the wiki to edit
125
127
const fetchWiki = async ( ) => {
126
128
try {
@@ -131,8 +133,9 @@ <h2>Edit Wiki Post</h2>
131
133
132
134
if ( ! wiki ) {
133
135
alert ( 'Wiki not found!' ) ;
134
- window . location . href = 'Wiki/wiki' ;
136
+ window . location . href = 'Wiki/wiki' ; // Redirect to wiki list if not found
135
137
} else {
138
+ wikiId = wiki . id ; // Store the wiki ID
136
139
wikiTitleInput . value = wiki . title ;
137
140
wikiContentInput . value = wiki . content ;
138
141
}
@@ -154,8 +157,13 @@ <h2>Edit Wiki Post</h2>
154
157
return ;
155
158
}
156
159
160
+ if ( ! wikiId ) {
161
+ alert ( 'Wiki ID not found' ) ;
162
+ return ;
163
+ }
164
+
157
165
try {
158
- const response = await fetch ( `${ backendUrl } /wikis` , {
166
+ const response = await fetch ( `${ backendUrl } /wikis/ ${ wikiId } ` , {
159
167
method : 'PUT' ,
160
168
headers : { 'Content-Type' : 'application/json' } ,
161
169
body : JSON . stringify ( {
0 commit comments