107
107
color : # ff4d4d ;
108
108
}
109
109
110
- li p {
111
- font-size : 1.1rem ;
112
- color : # 333 ;
113
- }
114
-
115
110
li small {
116
111
font-size : 0.9rem ;
117
112
color : # 777 ;
118
113
}
119
114
120
- /* Flexbox for Edit and Delete buttons */
121
- .button-container {
122
- display : flex;
123
- gap : 10px ;
124
- position : absolute;
125
- top : 10px ;
126
- right : 10px ;
127
- }
128
-
129
- .edit , .delete {
130
- padding : 8px 15px ;
131
- border-radius : 5px ;
132
- font-size : 1rem ;
133
- cursor : pointer;
134
- transition : transform 0.2s ease;
135
- }
136
-
137
- .edit {
138
- background-color : # ffcc00 ;
139
- color : white;
140
- }
141
-
142
- .edit : hover {
143
- transform : scale (1.1 );
144
- }
145
-
146
- .delete {
147
- background-color : # ff4d4d ;
148
- color : white;
149
- }
150
-
151
- .report {
152
- background-color : # FFC0CB ;
153
- color : white;
154
- }
155
-
156
- .report : hover {
157
- transform : scale (1.1 );
158
- }
159
-
160
- .delete : hover {
161
- transform : scale (1.1 );
162
- }
163
-
164
115
/* Mobile Responsive Styling */
165
116
@media (max-width : 768px ) {
166
117
.form-container {
@@ -226,25 +177,12 @@ <h2>Wiki Posts</h2>
226
177
wikis . forEach ( wiki => {
227
178
const li = document . createElement ( 'li' ) ;
228
179
li . innerHTML = `
229
- <h3>${ wiki . title } </h3>
230
- <p>${ wiki . content } </p>
231
- <small>Owner: ${ wiki . owner } </small>
232
- <div class="button-container">
233
- ${ username && isOwnerOrAdmin ( wiki . owner ) ? `<button class="edit" onclick="editWiki('${ wiki . title } ')">Edit</button>` : '' }
234
- ${ username && isOwnerOrAdmin ( wiki . owner ) ? `<button class="delete" onclick="deleteWiki(${ wiki . id } )">Delete</button>` : '' }
235
- <a href="report.html">
236
- <button>Report</button>
237
- </div>
180
+ <h3><a href="https://thejsurlback.onrender.com/wiki/${ encodeURIComponent ( wiki . title ) } ">${ wiki . title } </a></h3>
238
181
` ;
239
182
wikiList . appendChild ( li ) ;
240
183
} ) ;
241
184
} ;
242
185
243
- // Check if user is the owner or admin
244
- const isOwnerOrAdmin = ( owner ) => {
245
- return owner === username || username === "kRxZy_kRxZy" || username === "MyScratchedAccount" || username === "mcgdj" ;
246
- } ;
247
-
248
186
// Create a new wiki
249
187
createWikiForm . addEventListener ( 'submit' , async ( e ) => {
250
188
e . preventDefault ( ) ;
@@ -262,37 +200,6 @@ <h3>${wiki.title}</h3>
262
200
createWikiForm . reset ( ) ;
263
201
} ) ;
264
202
265
- // Delete a wiki
266
- window . deleteWiki = async ( id ) => {
267
- if ( ! username ) {
268
- alert ( 'You must be logged in to delete a wiki.' ) ;
269
- return ;
270
- }
271
-
272
- const response = await fetch ( `${ backendUrl } /wikis/${ id } ` , {
273
- method : 'DELETE' ,
274
- headers : { 'Content-Type' : 'application/json' } ,
275
- body : JSON . stringify ( { owner : username } ) , // Send username from localStorage
276
- } ) ;
277
-
278
- if ( response . ok ) {
279
- fetchWikis ( ) ; // Refresh wiki list
280
- } else {
281
- alert ( 'Not authorized to delete this wiki or wiki not found' ) ;
282
- }
283
- } ;
284
-
285
- // Redirect to edit page
286
- window . editWiki = ( title ) => {
287
- if ( ! username ) {
288
- alert ( 'You must be logged in to edit a wiki. Go to https://scratch-coding-hut.netlify.app/account to log in.' ) ;
289
- return ;
290
- }
291
-
292
- // Redirect to the edit page with the 'edit' parameter
293
- window . location . href = `edit.html?edit=${ encodeURIComponent ( title ) } ` ;
294
- } ;
295
-
296
203
// Initial fetch of wikis
297
204
fetchWikis ( ) ;
298
205
} ) ;
0 commit comments