5.8 KiB · text History 3d71adc
{% import "_avatar.html" as ui %}
{# One post (topic page, Focus page and reader, the htmx reply). `post` is a
   PostRow: what it shows and which controls appear come from the server's
   rules (crate::policy via build_post_rows), so a control is here exactly
   when the write behind it would succeed. #}
<article id="post-{{ post.post_number }}" data-post="{{ post.id }}"
         class="card bg-base-200 border p-4 {% if post.moderated %}border-warning/60{% elif post.hidden %}border-error/40{% else %}border-base-300{% endif %}">
  {% if post.deleted %}
    <header class="flex items-center justify-between text-sm">
      <span class="opacity-60 italic">
        <i class="fas fa-trash-can mr-1"></i>
        post #{{ post.post_number }} removed{% if post.deleted_by %} by {{ post.deleted_by }}{% endif %}
      </span>
      {% if post.can_restore %}
      <form method="post" action="/p/{{ post.id }}/restore" class="m-0">
        <button class="btn btn-ghost btn-xs" type="submit">Restore</button>
      </form>
      {% endif %}
    </header>
  {% else %}
    <div class="flex gap-3">
      <div class="shrink-0">
        {{ ui.avatar(post.author_id, post.author, post.author_has_avatar, "size-10", "text-base") | safe }}
      </div>
      <div class="flex-1 min-w-0">
        <header class="flex items-center justify-between text-sm mb-2 gap-2">
          {% if user and user.is_staff %}<a href="/admin/users/{{ post.author_id }}" class="font-semibold link link-hover" title="Manage {{ post.author }}">{{ post.author }}</a>{% else %}<span class="font-semibold">{{ post.author }}</span>{% endif %}
          <span class="opacity-60 text-xs flex items-center gap-2 shrink-0">
            {% if post.pending_flags %}<a href="/admin/flags#flags-{{ post.id }}" class="badge badge-error badge-sm" title="Flags awaiting review"><i class="fas fa-flag mr-1"></i>{{ post.pending_flags }}</a>{% endif %}
            {% if post.edited %}
              <a href="/p/{{ post.id }}/history" class="link link-hover" title="View edit history">{% if post.moderated %}history{% else %}edited{% endif %}</a>
            {% endif %}
            <a href="/p/{{ post.id }}" hx-boost="false" class="link link-hover" title="{{ post.created_at_abs }} · permalink">#{{ post.post_number }} · {{ post.created_at }}</a>
          </span>
        </header>
        {% if post.hidden %}
          <div class="alert alert-error alert-soft py-2 text-sm" role="note" data-hidden-pending>
            <i class="fas fa-eye-slash"></i><span>Hidden pending staff review.</span>
          </div>
          {% if post.show_hidden %}
          <details class="mt-2">
            <summary class="cursor-pointer text-xs opacity-70">{% if user and user.is_staff %}Show the post{% else %}Your post (only you and staff can see it){% endif %}</summary>
            <div class="prose prose-sm max-w-none mt-2">{{ post.cooked | safe }}</div>
          </details>
          {% endif %}
        {% elif post.moderated %}
          <div class="rounded-box border-l-4 border-warning bg-warning/10 px-3 py-2" data-moderated>
            <p class="text-xs font-semibold uppercase tracking-wide text-warning-content/80 mb-1">
              <i class="fas fa-shield-halved mr-1"></i>staff{% if post.moderated_by %} · {{ post.moderated_by }}{% endif %}:
            </p>
            <div class="prose prose-sm max-w-none">{{ post.cooked | safe }}</div>
          </div>
        {% else %}
          <div class="prose prose-sm max-w-none">{{ post.cooked | safe }}</div>
        {% endif %}
        {% if post.can_react %}
          {% include "forum/_reactions.html" %}
        {% elif post.reactions %}
          <div class="flex flex-wrap items-center gap-1 mt-2">
            {% for r in post.reactions %}{% if r.count > 0 %}<span class="group/react badge badge-ghost badge-sm"><span class="emoji-tint">{{ r.emoji }}</span> {{ r.count }}</span>{% endif %}{% endfor %}
          </div>
        {% endif %}
        {% if user %}
        <footer class="flex flex-wrap justify-end items-center gap-2 mt-2">
          {% if post.can_bookmark %}{% include "forum/_bookmark_button.html" %}{% endif %}
          {% if post.can_flag or post.flagged %}{% include "forum/_flag.html" %}{% endif %}
          {% if post.can_edit %}
          <a href="/p/{{ post.id }}/edit" class="btn btn-ghost btn-xs">Edit</a>
          {% endif %}
          {% if post.can_edit or post.can_moderate %}
          <form method="post" action="/p/{{ post.id }}/delete" class="m-0"
                hx-boost="false" onsubmit="return confirm('Delete this post? It stays hidden but is kept so references don\'t break.');">
            <button class="btn btn-ghost btn-xs text-error" type="submit">Delete</button>
          </form>
          {% elif user.id == post.author_id %}
          <form method="post" action="/p/{{ post.id }}/delete" class="m-0"
                hx-boost="false" onsubmit="return confirm('Delete this post? It stays hidden but is kept so references don\'t break.');">
            <button class="btn btn-ghost btn-xs text-error" type="submit">Delete</button>
          </form>
          {% endif %}
          {% if post.can_moderate %}
            {% if post.moderated %}
            <form method="post" action="/p/{{ post.id }}/moderation/restore" class="m-0" hx-boost="false"
                  onsubmit="return confirm('Put the author\'s last version back?');">
              <button class="btn btn-ghost btn-xs" type="submit" title="Restore the pre-moderation body"><i class="fas fa-rotate-left mr-1"></i>Restore</button>
            </form>
            {% endif %}
            <a href="/p/{{ post.id }}/moderate" class="btn btn-ghost btn-xs text-warning" title="Replace with a staff note"><i class="fas fa-shield-halved mr-1"></i>Moderate</a>
          {% endif %}
        </footer>
        {% endif %}
      </div>
    </div>
  {% endif %}
</article>