2025-03-30 22:26:20 -04:00
|
|
|
{% import "macros.html" as macros %} {% extends "root.html" %} {% block head %}
|
2025-03-27 18:10:47 -04:00
|
|
|
<title>My communities - {{ config.name }}</title>
|
|
|
|
{% endblock %} {% block body %} {{ macros::nav(selected="communities") }}
|
|
|
|
<main class="flex flex-col gap-2">
|
2025-03-29 00:26:56 -04:00
|
|
|
{% if user %}
|
2025-03-27 18:10:47 -04:00
|
|
|
<div class="card-nest">
|
2025-03-29 00:26:56 -04:00
|
|
|
<div class="card small">
|
2025-03-27 18:10:47 -04:00
|
|
|
<b>{{ text "communities:label.create_new" }}</b>
|
|
|
|
</div>
|
|
|
|
|
2025-03-29 00:26:56 -04:00
|
|
|
<form
|
|
|
|
class="card flex flex-col gap-2"
|
|
|
|
onsubmit="create_community_from_form(event)"
|
|
|
|
>
|
2025-03-27 18:10:47 -04:00
|
|
|
<div class="flex flex-col gap-1">
|
|
|
|
<label for="">{{ text "communities:label.name" }}</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="title"
|
|
|
|
id="title"
|
|
|
|
placeholder="name"
|
|
|
|
required
|
|
|
|
minlength="2"
|
|
|
|
maxlength="32"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<button class="primary">
|
|
|
|
{{ text "communities:action.create" }}
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
2025-03-29 00:26:56 -04:00
|
|
|
{% endif %} {% for item in list %} {{
|
|
|
|
components::community_listing_card(community=item) }} {% endfor %}
|
2025-03-27 18:10:47 -04:00
|
|
|
</main>
|
2025-03-29 00:26:56 -04:00
|
|
|
|
|
|
|
<script>
|
|
|
|
function create_community_from_form(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
fetch("/api/v1/communities", {
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
title: e.target.title.value,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => {
|
|
|
|
trigger("atto::toast", [
|
|
|
|
res.ok ? "success" : "error",
|
|
|
|
res.message,
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
setTimeout(() => {
|
|
|
|
window.location.href = `/community/${res.payload}`;
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
2025-03-27 18:10:47 -04:00
|
|
|
{% endblock %}
|