Skip to content

Commit 8b5981c

Browse files
authored
Update sitemaplinks.html
1 parent de0184e commit 8b5981c

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

src/Wiki/sitemaplinks.html

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ <h2>Create a Wiki Post</h2>
190190
</form>
191191
</div>
192192

193-
<div class="wikis-container">
194-
<b>Make sure to read and follow the <a href="https://scratch-coding-hut.netlify.app/wiki/wiki-guidelines">Scratch Coding Hut Wiki Guidelines</a></b>
195-
196193
<div class="wikis-container">
197194
<h2>Wiki Posts</h2>
198195
<ul id="wikiList"></ul>
@@ -204,13 +201,9 @@ <h2>Wiki Posts</h2>
204201
const wikiList = document.getElementById('wikiList');
205202
const backendUrl = 'https://thejsurlback.onrender.com/api'; // Replace with your backend URL
206203

207-
// Retrieve username from localStorage
204+
// Retrieve username from localStorage (this is optional, users can view wikis when logged out)
208205
const username = localStorage.getItem('username');
209-
if (!username) {
210-
alert('Sorry, You must be logged in to interact with the wiki. Go to https://scratch-coding-hut.netlify.app/account to log in.');
211-
return; // Stop execution if no username is found
212-
}
213-
206+
214207
// Fetch and display all wikis
215208
const fetchWikis = async () => {
216209
const response = await fetch(`${backendUrl}/wikis`);
@@ -224,8 +217,8 @@ <h3>${wiki.title}</h3>
224217
<p>${wiki.content}</p>
225218
<small>Owner: ${wiki.owner}</small>
226219
<div class="button-container">
227-
${isOwnerOrAdmin(wiki.owner) ? `<button class="edit" onclick="editWiki(${wiki.id}, '${wiki.title}', '${wiki.content}')">Edit</button>` : ''}
228-
${isOwnerOrAdmin(wiki.owner) ? `<button class="delete" onclick="deleteWiki(${wiki.id})">Delete</button>` : ''}
220+
${username && isOwnerOrAdmin(wiki.owner) ? `<button class="edit" onclick="editWiki('${wiki.title}')">Edit</button>` : ''}
221+
${username && isOwnerOrAdmin(wiki.owner) ? `<button class="delete" onclick="deleteWiki(${wiki.id})">Delete</button>` : ''}
229222
</div>
230223
`;
231224
wikiList.appendChild(li);
@@ -274,30 +267,15 @@ <h3>${wiki.title}</h3>
274267
}
275268
};
276269

277-
// Edit a wiki
278-
window.editWiki = async (id, title, content) => {
270+
// Redirect to edit page
271+
window.editWiki = (title) => {
279272
if (!username) {
280273
alert('You must be logged in to edit a wiki. Go to https://scratch-coding-hut.netlify.app/account to log in.');
281274
return;
282275
}
283276

284-
// Open the title and content in editable textareas
285-
const newTitle = prompt('New title:', title);
286-
const newContent = prompt('New content:', content);
287-
288-
if (newTitle && newContent) {
289-
const response = await fetch(`${backendUrl}/wikis/${id}`, {
290-
method: 'PUT',
291-
headers: { 'Content-Type': 'application/json' },
292-
body: JSON.stringify({ title: newTitle, content: newContent, owner: username }), // Send username from localStorage
293-
});
294-
295-
if (response.ok) {
296-
fetchWikis(); // Refresh wiki list
297-
} else {
298-
alert('Not authorized to edit this wiki or wiki not found');
299-
}
300-
}
277+
// Redirect to the edit page with the 'edit' parameter
278+
window.location.href = `edit.html?edit=${encodeURIComponent(title)}`;
301279
};
302280

303281
// Initial fetch of wikis

0 commit comments

Comments
 (0)