tetratto/crates/app/src/public/html/communities/feed.html
trisua 48e0b02198 add: "town square" community option
with a town square community, users can post directly from their profiles!
2025-04-03 20:25:00 -04:00

97 lines
3.1 KiB
HTML

{% import "macros.html" as macros %} {% import "components.html" as components
%} {% extends "communities/base.html" %} {% block content %}
<div class="flex flex-col gap-4 w-full">
{% if user and can_post %}
<div class="card-nest">
<div class="card small flex items-center gap-2">
{{ icon "pencil" }}
<span>{{ text "communities:label.create_post" }}</span>
</div>
<form
class="card flex flex-col gap-2"
onsubmit="create_post_from_form(event)"
>
<div class="flex flex-col gap-1">
<label for="content"
>{{ text "communities:label.content" }}</label
>
<textarea
type="text"
name="content"
id="content"
placeholder="content"
required
minlength="2"
maxlength="4096"
></textarea>
</div>
<button class="primary">
{{ text "communities:action.create" }}
</button>
</form>
</div>
{% endif %} {% if pinned|length != 0 %}
<div class="card-nest">
<div class="card small flex gap-2 items-center">
{{ icon "pin" }}
<span>{{ text "communities:label.pinned" }}</span>
</div>
<div class="card flex flex-col gap-4">
<!-- prettier-ignore -->
{% for post in pinned %}
{{ components::post(post=post[0], owner=post[1], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
{% endfor %}
</div>
</div>
{% endif %}
<div class="card-nest">
<div class="card small flex gap-2 items-center">
{{ icon "newspaper" }}
<span>{{ text "communities:label.posts" }}</span>
</div>
<div class="card flex flex-col gap-4">
<!-- prettier-ignore -->
{% for post in feed %}
{{ components::post(post=post[0], owner=post[1], secondary=true, show_community=false, can_manage_post=can_manage_posts) }}
{% endfor %}
{{ components::pagination(page=page, items=feed|length) }}
</div>
</div>
</div>
<script>
async function create_post_from_form(e) {
e.preventDefault();
await trigger("atto::debounce", ["posts::create"]);
fetch("/api/v1/posts", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
content: e.target.content.value,
community: "{{ community.id }}",
}),
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
if (res.ok) {
setTimeout(() => {
window.location.href = `/post/${res.payload}`;
}, 100);
}
});
}
</script>
{% endblock %}