Skip to content

Commit

Permalink
adding a post
Browse files Browse the repository at this point in the history
  • Loading branch information
jmort1021 committed Oct 28, 2024
1 parent 2bf6ca8 commit 307f65b
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions navigation/authentication/post.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ search_exclude: true
.form-container label {
margin-bottom: 5px;
}
.form-container input, .form-container textarea {
.form-container input, .form-container textarea, .form-container select {
margin-bottom: 10px;
padding: 10px;
border-radius: 5px;
Expand All @@ -52,8 +52,10 @@ search_exclude: true
<input type="text" id="title" name="title" required>
<label for="content">Content:</label>
<textarea id="content" name="content" required></textarea>
<label for="group_id">Group ID:</label>
<input type="number" id="group_id" name="group_id" required>
<label for="group_id">Group:</label>
<select id="group_id" name="group_id" required>
<option value="">Select a group</option>
</select>
<button type="submit">Add Post</button>
</form>
</div>
Expand All @@ -62,6 +64,25 @@ search_exclude: true
<script type="module">
import { pythonURI, fetchOptions } from '{{ site.baseurl }}/assets/js/api/config.js';

async function fetchGroups() {
try {
const response = await fetch(`${pythonURI}/api/group`, fetchOptions);
if (!response.ok) {
throw new Error('Failed to fetch groups: ' + response.statusText);
}
const groups = await response.json();
const groupSelect = document.getElementById('group_id');
groups.forEach(group => {
const option = document.createElement('option');
option.value = group.id;
option.textContent = group.name;
groupSelect.appendChild(option);
});
} catch (error) {
console.error('Error fetching groups:', error);
}
}

document.getElementById('postForm').addEventListener('submit', async function(event) {
event.preventDefault();

Expand Down Expand Up @@ -98,4 +119,7 @@ search_exclude: true
alert('Error adding post: ' + error.message);
}
});
</script>

// Fetch groups when the page loads
fetchGroups();
</script>

0 comments on commit 307f65b

Please sign in to comment.