6.8 KiB · text History 4fe8b36
{% extends "root.html" %}
{# Visual mode for one category (src/handlers/focus.rs): a rail of the
   categories beside it, its topics as tiles, each subcategory as a column of
   compact squares, and the reader over it all when ?topic= is set. #}
{% block width %}w-full max-w-none{% endblock %}
{% block main_class %}px-3 py-3 sm:px-4 lg:px-5{% endblock %}
{% block content %}
<div class="flex min-h-[calc(100dvh-5.5rem)] flex-col gap-4 text-left" id="focus" data-focus="{{ category.slug }}">
  <nav class="text-sm opacity-70" aria-label="Breadcrumb">
    <a href="/?view=focus" class="link link-hover">Categories</a>
    {% for a in ancestors %} / <a href="{{ a.href }}" class="link link-hover">{{ a.name }}</a>{% endfor %}
    / {{ category.name }}
  </nav>

  <div class="flex flex-wrap items-center justify-between gap-3">
    <h1 class="text-3xl font-bold flex items-center gap-2">
      <span class="size-6 rounded-full border border-base-content/20" style="background: {{ category_widget_bg }}" aria-hidden="true"></span>
      {{ category.name }}
    </h1>
    <div class="flex flex-wrap items-center gap-2">
      {% set toggle_base = "/c/" ~ category.slug ~ "?sort=" ~ current_sort %}{% set view_mode = "focus" %}
      {% include "forum/_view_toggle.html" %}
      {% if user %}
        {% include "forum/_watch_button.html" %}
        {% if can_write %}
        <a href="/c/{{ category.slug }}/new" class="btn btn-primary btn-sm"><i class="fas fa-plus mr-1"></i> New Topic</a>
        {% endif %}
      {% endif %}
    </div>
  </div>

  <div class="flex flex-1 flex-col gap-4 md:flex-row md:items-stretch">
    {# The rail: a horizontal strip on small screens, a column beside the page from md up. #}
    <nav id="focus-rail" aria-label="Other categories"
         class="flex shrink-0 gap-2 overflow-x-auto pb-1 md:sticky md:top-4 md:self-start md:max-h-[calc(100dvh-6rem)] md:overflow-y-auto md:w-20 md:flex-col md:pb-0">
      <a id="focus-up" href="{{ up.href }}" title="Up to {{ up.name }}" aria-label="Up to {{ up.name }}"
         class="flex aspect-square w-16 shrink-0 flex-col items-center justify-center rounded-box border border-base-300 bg-base-200 font-mono text-lg font-bold transition-all hover:-translate-y-0.5 hover:border-primary/60 focus-visible:outline-2 focus-visible:outline-primary md:w-full">
        ..
        <span class="max-w-full truncate px-1 font-sans text-[0.6rem] font-normal opacity-60">{{ up.name }}</span>
      </a>
      {% for r in rail %}
        {% if r.current %}
        <div id="focus-rail-{{ r.slug }}" aria-current="true" title="{{ r.name }} (in focus)"
             class="flex aspect-square w-16 shrink-0 flex-col justify-between rounded-box border-2 border-accent bg-accent/10 p-1.5 shadow-sm md:w-full">
          <span class="size-4 rounded-full border border-base-content/20" style="background: {{ r.widget_bg }}" aria-hidden="true"></span>
          <span class="line-clamp-2 text-[0.65rem] font-semibold leading-tight">{{ r.name }}</span>
          <span class="font-mono text-[0.6rem] opacity-60">{{ r.count }}</span>
        </div>
        {% else %}
        <a id="focus-rail-{{ r.slug }}" href="{{ r.href }}" title="Focus on {{ r.name }}" aria-label="Focus on {{ r.name }}"
           class="flex aspect-square w-16 shrink-0 flex-col justify-between rounded-box border border-base-300 bg-base-200 p-1.5 transition-all hover:-translate-y-0.5 hover:border-primary/60 focus-visible:outline-2 focus-visible:outline-primary md:w-full">
          <span class="size-4 rounded-full border border-base-content/20" style="background: {{ r.widget_bg }}" aria-hidden="true"></span>
          <span class="line-clamp-2 text-[0.65rem] font-medium leading-tight">{{ r.name }}</span>
          <span class="font-mono text-[0.6rem] opacity-50">{{ r.count }}</span>
        </a>
        {% endif %}
      {% endfor %}
    </nav>

    <section id="focus-{{ category.slug }}" aria-label="{{ category.name }}"
             class="min-w-0 flex-1 space-y-5 rounded-box border border-primary/40 bg-base-200/40 p-4">
      <div class="flex flex-wrap items-center justify-between gap-2">
        {% if category.description %}<p class="opacity-70 text-sm">{{ category.description }}</p>{% else %}<span></span>{% endif %}
        <div role="tablist" class="tabs tabs-bordered w-fit" aria-label="Sort">
          {% for opt in ["latest", "top", "hot", "bottom"] %}
          <a role="tab" class="tab {% if current_sort == opt %}tab-active{% endif %}" aria-selected="{{ 'true' if current_sort == opt else 'false' }}"
             href="/c/{{ category.slug }}?view=focus&amp;sort={{ opt }}">{{ opt | capitalize }}</a>
          {% endfor %}
        </div>
      </div>

      {% if topics %}
      <div class="grid grid-cols-[repeat(auto-fill,minmax(17rem,1fr))] gap-3">
        {% for t in topics %}{% include "forum/_topic_tile.html" %}{% endfor %}
      </div>
      {% elif not columns %}
      <p class="rounded-box border border-dashed border-base-300 p-6 text-center text-sm opacity-60">
        No topics yet.{% if can_write %} Be the first to post one.{% endif %}
      </p>
      {% endif %}

      {% if columns %}
      {# In focus, subcategories sit side by side as columns (pin_flip). #}
      <div class="flex items-start gap-4 overflow-x-auto pb-2">
        {% for col in columns %}
        <section id="focus-sub-{{ col.slug }}" class="min-w-56 flex-1 basis-56 space-y-2 rounded-box border border-base-300 bg-base-100 p-3" aria-label="{{ col.name }}">
          <a id="focus-link-{{ col.slug }}" href="{{ col.href }}" title="Focus on {{ col.name }}" aria-label="Focus on {{ col.name }}"
             class="group flex items-center gap-1.5 text-sm font-semibold hover:text-primary focus-visible:outline-2 focus-visible:outline-primary rounded">
            <span class="size-4 shrink-0 rounded-full border border-base-content/20" style="background: {{ col.widget_bg }}" aria-hidden="true"></span>
            <span class="truncate">{{ col.name }}</span>
            <span class="font-mono text-xs font-normal opacity-50">{{ col.count }}</span>
            <i class="fas fa-up-right-and-down-left-from-center ml-auto text-xs opacity-0 transition-opacity group-hover:opacity-60 group-focus-visible:opacity-60" aria-hidden="true"></i>
          </a>
          {% if col.topics %}
          <div class="grid grid-cols-[repeat(auto-fill,minmax(4.5rem,1fr))] gap-1.5">
            {% for t in col.topics %}{% set href = base ~ "&topic=" ~ t.id %}{% set reader_swap = true %}{% include "forum/_topic_square.html" %}{% endfor %}
          </div>
          {% if col.more %}<a href="{{ col.href }}" class="link link-hover text-xs opacity-70">+{{ col.more }} more</a>{% endif %}
          {% else %}
          <p class="text-xs opacity-50">No topics yet.</p>
          {% endif %}
        </section>
        {% endfor %}
      </div>
      {% endif %}
    </section>
  </div>

  {% include "forum/_reader.html" %}
</div>
{% endblock %}