2022-08-26 20:21:45 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
|
2022-08-26 20:22:46 +03:00
|
|
|
<%- include("extra/meta", {title: "Create thread!" }) %>
|
2022-08-26 20:21:45 +03:00
|
|
|
|
2022-09-17 21:36:33 +03:00
|
|
|
<body >
|
2023-05-24 15:40:09 +03:00
|
|
|
|
2022-08-26 20:21:45 +03:00
|
|
|
<%- include("extra/navbar") %>
|
2023-05-24 15:40:09 +03:00
|
|
|
<link rel="stylesheet" href="/libs/simplemde/simplemde.min.css">
|
|
|
|
<script src="/libs/simplemde/simplemde.min.js"></script>
|
2022-08-26 20:21:45 +03:00
|
|
|
|
2023-05-24 15:40:09 +03:00
|
|
|
<form class="post">
|
2022-09-17 00:51:52 +03:00
|
|
|
<h2 class="title" style="align-self: baseline;">Title:</h2>
|
2022-09-17 20:25:19 +03:00
|
|
|
<input name="title" class="input" required></input>
|
2022-08-26 20:57:55 +03:00
|
|
|
<h2 class="title" style="align-self: baseline;">Content:</h2>
|
2023-05-24 15:40:09 +03:00
|
|
|
<div style="width: 100%;">
|
2022-09-23 23:20:00 +03:00
|
|
|
<textarea id="textarea"></textarea>
|
|
|
|
</div>
|
2022-09-09 20:55:05 +03:00
|
|
|
<h2 class="title" style="align-self: baseline;">Category:</h2>
|
|
|
|
|
2023-05-24 15:40:09 +03:00
|
|
|
<select name="category" class="input">
|
2022-09-09 20:47:28 +03:00
|
|
|
<% for (const category of categories) { %>
|
2022-09-09 20:55:05 +03:00
|
|
|
<option value="<%= category.id %>"><%= category.name %></option>
|
2022-09-09 20:47:28 +03:00
|
|
|
<% } %>
|
|
|
|
</select>
|
2022-08-26 20:21:45 +03:00
|
|
|
|
2022-09-01 14:02:47 +03:00
|
|
|
<button class="btn-primary" style="width:100%" type="submit">Create Thread!</button>
|
|
|
|
</form>
|
2023-05-24 15:40:09 +03:00
|
|
|
<script src="/js/editor.js"></script>
|
2022-08-26 20:21:45 +03:00
|
|
|
|
|
|
|
|
2022-09-01 14:02:47 +03:00
|
|
|
<script type="module">
|
2023-05-24 15:40:09 +03:00
|
|
|
const simplemde = editor("thread-create");
|
2022-09-17 21:36:33 +03:00
|
|
|
|
2022-08-26 20:21:45 +03:00
|
|
|
import request from "../../js/request.js";
|
|
|
|
|
|
|
|
document.addEventListener("submit", async e => {
|
2022-09-01 14:02:47 +03:00
|
|
|
e.preventDefault();
|
|
|
|
const form = e.target;
|
|
|
|
const data = new FormData(form);
|
2022-08-26 20:21:45 +03:00
|
|
|
|
2022-09-01 14:02:47 +03:00
|
|
|
const response = await request("/api/threads/", "POST", {
|
|
|
|
title: data.get("title"),
|
2022-09-17 21:36:33 +03:00
|
|
|
content: simplemde.value(),
|
2022-09-09 20:55:05 +03:00
|
|
|
category: data.get("category")
|
2022-09-01 14:02:47 +03:00
|
|
|
});
|
2022-08-26 20:21:45 +03:00
|
|
|
|
2023-05-24 15:40:09 +03:00
|
|
|
simplemde.clearAutosavedValue();
|
2022-08-26 20:21:45 +03:00
|
|
|
|
2022-09-01 14:02:47 +03:00
|
|
|
if (response)
|
|
|
|
window.location.href = "/threads/" + response.id;
|
2022-08-26 20:21:45 +03:00
|
|
|
|
|
|
|
|
2022-09-01 14:02:47 +03:00
|
|
|
});
|
|
|
|
</script>
|
2022-09-17 00:51:52 +03:00
|
|
|
<%- include("extra/footer") %>
|
|
|
|
|
2022-08-26 20:21:45 +03:00
|
|
|
</body>
|
|
|
|
|
2022-09-01 14:02:47 +03:00
|
|
|
</html>
|