tetratto/crates/app/src/public/html/post/post.html

345 lines
12 KiB
HTML
Raw Normal View History

{% extends "root.html" %} {% block head %}
<title>Post - {{ config.name }}</title>
{% endblock %} {% block body %} {{ macros::nav() }}
<main class="flex flex-col gap-2">
{% if post.replying_to %}
<a href="/post/{{ post.replying_to }}" class="button">
{{ icon "arrow-up" }}
<span>{{ text "communities:action.continue_thread" }}</span>
</a>
2025-04-10 18:16:52 -04:00
{% endif %}
<!-- prettier-ignore -->
<div style="display: contents;">
{% if post.context.repost and post.context.repost.reposting %}
{{ components::repost(repost=reposting, post=post, owner=owner, community=community, show_community=true, can_manage_post=can_manage_posts) }}
{% else %}
2025-04-12 22:25:54 -04:00
{{ components::post(post=post, owner=owner, question=question, community=community, show_community=true, can_manage_post=can_manage_posts) }}
2025-04-10 18:16:52 -04:00
{% endif %}
</div>
{% if user and post.context.comments_enabled %}
<div class="card-nest">
<div class="card small">
<b>{{ text "communities:label.create_reply" }}</b>
</div>
<form
class="card flex flex-col gap-2"
onsubmit="create_reply_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>
<div id="files_list" class="flex gap-2 flex-wrap"></div>
2025-05-05 23:12:46 -04:00
<div class="flex gap-2">
{{ components::emoji_picker(element_id="content",
render_dialog=true) }} {% if is_supporter %} {{
components::file_picker(files_list_id="files_list") }} {% endif
%}
2025-05-05 23:12:46 -04:00
<button class="primary">
{{ text "communities:action.create" }}
</button>
</div>
</form>
</div>
{% endif %}
2025-04-03 12:43:36 -04:00
<div class="pillmenu">
<a href="#/replies" data-tab-button="replies" class="active">
{{ icon "newspaper" }}
<span>{{ text "communities:label.replies" }}</span>
</a>
<a href="/post/{{ post.id }}/reposts">
{{ icon "repeat-2" }}
<span>{{ text "communities:label.reposts" }}</span>
</a>
<a href="/post/{{ post.id }}/reposts?quotes=true">
{{ icon "quote" }}
<span>{{ text "communities:label.quotes" }}</span>
</a>
</div>
2025-05-14 20:03:21 -04:00
{% if (user and user.id == post.owner) or can_manage_posts %}
<div class="pillmenu">
2025-05-14 20:03:21 -04:00
{% if user and user.id == post.owner %}
<a href="/post/{{ post.id }}#/edit">
{{ icon "pen" }}
<span>{{ text "communities:label.edit_content" }}</span>
</a>
{% endif %}
<a href="/post/{{ post.id }}/likes">
{{ icon "heart" }}
<span>{{ text "communities:label.likes" }}</span>
</a>
2025-04-03 12:43:36 -04:00
<a href="#/configure" data-tab-button="configure">
{{ icon "settings" }}
<span>{{ text "communities:action.configure" }}</span>
</a>
</div>
{% endif %}
2025-04-03 12:43:36 -04:00
<div class="flex flex-col gap-2 hidden" data-tab="configure">
<div class="card-nest w-full">
<div class="card small flex items-center gap-2">
{{ icon "settings" }}
<span>{{ text "communities:action.configure" }}</span>
</div>
<div
class="card tertiary flex flex-col gap-4"
id="post_context"
></div>
</div>
<button onclick="save_context()">
{{ icon "check" }}
<span>{{ text "general:action.save" }}</span>
</button>
<script>
setTimeout(() => {
const ui = ns("ui");
const element = document.getElementById("post_context");
const settings = JSON.parse("{{ post_context_serde|safe }}");
globalThis.save_context = () => {
fetch("/api/v1/posts/{{ post.id }}/context", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
context: settings,
}),
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
});
};
ui.refresh_container(element, []);
const can_manage_pins = "{{ can_manage_pins }}" === "true";
const is_owner =
"{{ user and user.id == post.owner }}" === "true";
2025-04-03 12:43:36 -04:00
const settings_fields = [
[
[
"comments_enabled",
"Allow people to comment on your post",
],
"{{ post.context.comments_enabled }}",
"checkbox",
2025-04-07 16:32:09 -04:00
],
[
[
"reposts_enabled",
"Allow people to repost/quote your post",
],
"{{ post.context.reposts_enabled }}",
"checkbox",
],
2025-04-10 18:16:52 -04:00
[
[
"reactions_enabled",
"Allow people to like/dislike your post",
],
"{{ post.context.reactions_enabled }}",
2025-04-10 18:16:52 -04:00
"checkbox",
],
2025-04-07 16:32:09 -04:00
[
2025-05-06 15:48:03 -04:00
["is_nsfw", "Hide from public timelines"],
2025-04-07 16:32:09 -04:00
"{{ community.context.is_nsfw }}",
"checkbox",
2025-04-03 12:43:36 -04:00
],
2025-05-06 15:48:03 -04:00
[
["content_warning", "Content warning"],
settings.content_warning,
"textarea",
],
2025-05-08 20:08:43 -04:00
[
["tags", "Tags"],
settings.tags.join(", "),
"input",
{
embed_html:
'<span class="fade">Tags should be separated by a comma.</span>',
},
],
2025-04-03 12:43:36 -04:00
];
if (can_manage_pins) {
settings_fields.push([
["is_pinned", "Pinned to community wall"],
"{{ post.context.is_pinned }}",
"checkbox",
]);
}
if (is_owner) {
settings_fields.push([
["is_profile_pinned", "Pinned to your profile"],
"{{ post.context.is_profile_pinned }}",
"checkbox",
]);
}
2025-05-08 20:08:43 -04:00
ui.generate_settings_ui(element, settings_fields, settings, {
tags: (new_tags) => {
settings.tags = new_tags
.split(",")
.map((t) => t.trim());
},
});
2025-04-03 12:43:36 -04:00
}, 250);
</script>
</div>
{% if user and user.id == post.owner %}
<div class="card-nest w-full hidden" data-tab="edit">
<div class="card small flex items-center gap-2">
{{ icon "pen" }}
<span>{{ text "communities:label.edit_content" }}</span>
</div>
<form
class="card flex flex-col gap-2"
onsubmit="edit_post_from_form(event)"
>
<div class="flex flex-col gap-1">
<label for="content"
>{{ text "communities:label.content" }}</label
>
<textarea
type="text"
2025-05-05 23:12:46 -04:00
name="new_content"
id="new_content"
placeholder="content"
required
minlength="2"
maxlength="4096"
>
{{ post.content }}</textarea
>
</div>
2025-05-05 23:12:46 -04:00
<div class="flex gap-2">
{{ components::emoji_picker(element_id="new_content",
render_dialog=false) }}
<button class="primary">
{{ text "general:action.save" }}
</button>
</div>
</form>
</div>
<script>
async function edit_post_from_form(e) {
e.preventDefault();
await trigger("atto::debounce", ["posts::edit"]);
fetch("/api/v1/posts/{{ post.id }}/content", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
2025-05-05 23:12:46 -04:00
content: e.target.new_content.value,
}),
})
.then((res) => res.json())
.then((res) => {
trigger("atto::toast", [
res.ok ? "success" : "error",
res.message,
]);
});
}
</script>
{% endif %}
2025-04-03 12:43:36 -04:00
<div class="card-nest w-full" data-tab="replies">
<div class="card small flex items-center gap-2">
{{ icon "newspaper" }}
<span>{{ text "communities:label.replies" }}</span>
</div>
<div class="card flex flex-col gap-4">
<!-- prettier-ignore -->
{% for post in replies %}
2025-04-12 22:42:57 -04:00
{{ components::post(post=post[0], owner=post[1], question=post[3], secondary=true, show_community=false) }}
{% endfor %}
{{ components::pagination(page=page, items=replies|length) }}
</div>
</div>
</main>
<script>
async function create_reply_from_form(e) {
e.preventDefault();
await trigger("atto::debounce", ["posts::create"]);
2025-05-11 14:27:55 -04:00
// create body
const body = new FormData();
if (e.target.file_picker) {
for (const file of e.target.file_picker.files) {
body.append(file.name, file);
}
}
2025-05-11 14:27:55 -04:00
body.append(
"body",
JSON.stringify({
content: e.target.content.value,
community: "{{ community.id }}",
replying_to: "{{ post.id }}",
}),
2025-05-11 14:27:55 -04:00
);
// ...
fetch("/api/v1/posts", {
method: "POST",
body,
})
.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 %}