add: pinned posts

This commit is contained in:
trisua 2025-04-03 12:43:36 -04:00
parent e52733b00c
commit eea3d08e1f
10 changed files with 324 additions and 55 deletions

View file

@ -31,6 +31,20 @@
</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">
@ -42,7 +56,7 @@
<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) }}
{{ 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) }}

View file

@ -8,7 +8,8 @@
<span>{{ text "communities:action.continue_thread" }}</span>
</a>
{% endif %} {{ components::post(post=post, owner=owner, community=community,
show_community=true) }} {% if user %}
show_community=true, can_manage_post=can_manage_posts) }} {% if user and
post.context.comments_enabled %}
<div class="card-nest">
<div class="card small">
<b>{{ text "communities:label.create_reply" }}</b>
@ -38,9 +39,91 @@
</button>
</form>
</div>
{% endif %} {% if user and user.id == post.owner or can_manage_posts %}
<div class="pillmenu">
<a href="#/replies" data-tab-button="replies" class="active">
{{ icon "newspaper" }}
<span>{{ text "communities:label.replies" }}</span>
</a>
<a href="#/configure" data-tab-button="configure">
{{ icon "settings" }}
<span>{{ text "communities:action.configure" }}</span>
</a>
</div>
<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 settings_fields = [
[
[
"comments_enabled",
"Allow people to comment on your post",
],
"{{ post.context.comments_enabled }}",
"checkbox",
],
];
if (can_manage_pins) {
settings_fields.push([
["is_pinned", "Pinned to community wall"],
"{{ post.context.is_pinned }}",
"checkbox",
]);
}
ui.generate_settings_ui(element, settings_fields, settings);
}, 250);
</script>
</div>
{% endif %}
<div class="card-nest w-full">
<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>

View file

@ -346,7 +346,7 @@
role: (new_role) => {
return update_user_role(
e.target.uid.value,
user_role,
new_role,
);
},
},

View file

@ -105,7 +105,8 @@ community %}
{% endif %}
</div>
{%- endmacro %} {% macro post(post, owner, secondary=false, community=false,
show_community=true) -%} {% if community and show_community %}
show_community=true, can_manage_post=false) -%} {% if community and
show_community %}
<div class="card-nest">
<div class="card small">
<a
@ -115,6 +116,8 @@ show_community=true) -%} {% if community and show_community %}
{{ components::community_avatar(id=post.community,
community=community) }}
<b>{{ community.title }}</b>
{% if post.context.is_pinned %} {{ icon "pin" }} {% endif %}
</a>
</div>
{% endif %}
@ -197,7 +200,7 @@ show_community=true) -%} {% if community and show_community %}
<span>{{ text "general:action.report" }}</span>
</button>
{% endif %} {% if (user.id == post.owner) or is_helper
%}
or can_manage_post %}
<b class="title">{{ text "general:action.manage" }}</b>
<button
class="red"