akf-forum/themes/default/create_thread.ejs

69 lines
No EOL
1.8 KiB
Text

<!DOCTYPE html>
<html lang="en">
<%- include("extra/meta", {title: "Create thread!" }) %>
<body >
<link rel="stylesheet" href="/css/create_thread.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
<%- include("extra/navbar") %>
<form>
<h2 class="title" style="align-self: baseline;">Title:</h2>
<input name="title" class="input" required></input>
<h2 class="title" style="align-self: baseline;">Content:</h2>
<div style="width: 100%;">
<textarea id="textarea"></textarea>
</div>
<h2 class="title" style="align-self: baseline;">Category:</h2>
<select name="category">
<% for (const category of categories) { %>
<option value="<%= category.id %>"><%= category.name %></option>
<% } %>
</select>
<button class="btn-primary" style="width:100%" type="submit">Create Thread!</button>
</form>
<script type="module">
const textarea = document.getElementById("textarea");
const simplemde = new SimpleMDE({
autosave: {
enabled: true,
uniqueId: "thread-create",
delay: 1000,
},// width: 100%;
element: textarea,
spellChecker: false
});
import request from "../../js/request.js";
document.addEventListener("submit", async e => {
e.preventDefault();
const form = e.target;
const data = new FormData(form);
const response = await request("/api/threads/", "POST", {
title: data.get("title"),
content: simplemde.value(),
category: data.get("category")
});
if (response)
window.location.href = "/threads/" + response.id;
});
</script>
<%- include("extra/footer") %>
</body>
</html>