Skip to content

Commit d47f738

Browse files
authored
Update sitemaplinks.html
1 parent a228b90 commit d47f738

File tree

1 file changed

+21
-45
lines changed

1 file changed

+21
-45
lines changed

src/Wiki/sitemaplinks.html

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -156,53 +156,29 @@ <h2>Wiki Posts</h2>
156156
</div>
157157

158158
<script>
159-
if (!localStorage.getItem('username') || localStorage.getItem('username') === "null") {
160-
document.getElementById('makeWiki').style.display = 'none';
161-
}
162-
163-
document.addEventListener('DOMContentLoaded', () => {
164-
const createWikiForm = document.getElementById('createWikiForm');
165-
const wikiList = document.getElementById('wikiList');
166-
const backendUrl = 'https://thejsurlback.onrender.com/api'; // Replace with your backend URL
167-
168-
// Retrieve username from localStorage (this is optional, users can view wikis when logged out)
169-
const username = localStorage.getItem('username');
170-
171-
// Fetch and display all wikis
172-
const fetchWikis = async () => {
173-
const response = await fetch(`${backendUrl}/wikis`);
174-
const wikis = await response.json();
175-
wikiList.innerHTML = ''; // Clear the current list
176-
177-
wikis.forEach(wiki => {
178-
const li = document.createElement('li');
179-
li.innerHTML = `
180-
<h3><a href="https://thejsurlback.onrender.com/wiki/${encodeURIComponent(wiki.title)}?user=${btoa(localStorage.getItem('username'))}">${wiki.title}</a></h3>
181-
`;
182-
wikiList.appendChild(li);
183-
});
184-
};
185-
186-
// Create a new wiki
187-
createWikiForm.addEventListener('submit', async (e) => {
188-
e.preventDefault();
189-
const title = document.getElementById('wikiTitle').value;
190-
const content = document.getElementById('wikiContent').value;
191-
192-
const response = await fetch(`${backendUrl}/wikis`, {
193-
method: 'POST',
194-
headers: { 'Content-Type': 'application/json' },
195-
body: JSON.stringify({ title, content, owner: username }), // Send username from localStorage
196-
});
197-
198-
const newWiki = await response.json();
199-
fetchWikis(); // Refresh wiki list
200-
createWikiForm.reset();
159+
// Retrieve username from localStorage (this is optional, users can view wikis when logged out)
160+
const username = localStorage.getItem('username');
161+
const backendUrl = 'https://thejsurlback.onrender.com/api'; // Replace with your backend URL
162+
const wikiList = document.getElementById('wikiList');
163+
164+
// Fetch and display all wikis
165+
const fetchWikis = async () => {
166+
const response = await fetch(`${backendUrl}/wikis`);
167+
const wikis = await response.json();
168+
wikiList.innerHTML = ''; // Clear the current list
169+
170+
wikis.forEach(wiki => {
171+
const li = document.createElement('li');
172+
li.innerHTML = `
173+
<h3><a href="https://thejsurlback.onrender.com/wiki/${encodeURIComponent(wiki.title)}?user=${btoa(username)}">${wiki.title}</a></h3>
174+
<small>Owner: ${wiki.owner}</small>
175+
`;
176+
wikiList.appendChild(li);
201177
});
178+
};
202179

203-
// Initial fetch of wikis
204-
fetchWikis();
205-
});
180+
// Initial fetch of wikis
181+
fetchWikis();
206182
</script>
207183
</body>
208184
</html>

0 commit comments

Comments
 (0)