summaryrefslogtreecommitdiff
path: root/templates/profile.html
blob: bbf70a230808f818c14d33dab330a3623a6a375b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Tyler's Film Diary · Lumière</title>
    <link rel="icon" href="/static/favicon.svg" type="image/svg+xml">
    <link rel="stylesheet" href="/static/styles.css" />
  </head>
  <body class="public-profile-page">
    <div class="public-shell">
      <header class="public-topbar">
        <a class="brand" href="/tyler">Lumière</a>
        <nav class="public-nav" aria-label="Primary">
          <a class="is-active" href="/tyler">Profile</a>
          <a href="/about">About</a>
          <a href="/login">Private Log In</a>
        </nav>
      </header>

      <main class="public-main">
        <section class="public-hero">
          <div class="public-hero-copy">
            <p class="eyebrow">Public Ledger</p>
            <h1>Tyler's Film Diary</h1>
            <p class="public-hero-text">A public cut of the diary: recent watches, recurring directors, and the films that keep returning.</p>
          </div>
          <div class="public-hero-metrics">
            <div class="public-metric-card">
              <span class="summary-label">Watched</span>
              <strong>{{ total_watched }}</strong>
            </div>
            <div class="public-metric-card">
              <span class="summary-label">Average</span>
              <strong>{{ average_stars }}</strong>
            </div>
          </div>
        </section>

        <section class="public-tabs">
          <button id="tab-overview" class="public-tab is-active" data-tab="overview" type="button">Overview</button>
          <button id="tab-films" class="public-tab" data-tab="films" type="button">All Films</button>
        </section>

        <section id="panel-overview" class="public-panel is-active">
          <div class="public-grid">
            <section class="public-section">
              <div class="public-section-head">
                <p class="eyebrow">Rotation</p>
                <h2>Most watched directors</h2>
              </div>
              <div class="public-list">
                {% for item in most_watched_directors %}
                <div class="public-list-row">
                  <span>{{ item.director }}</span>
                  <strong>{{ item.count }}</strong>
                </div>
                {% endfor %}
              </div>
            </section>

            <section class="public-section">
              <div class="public-section-head">
                <p class="eyebrow">Distribution</p>
                <h2>Ratings</h2>
              </div>
              <div class="public-bars">
                {% for item in star_distribution %}
                <div class="public-bar-row">
                  <span>
                    {% if item.stars == 0 %}Unrated{% else %}{% for _ in range(item.stars) %}✦{% endfor %}{% endif %}
                  </span>
                  <div class="public-bar-track">
                    {% if total_watched > 0 %}
                    <div class="public-bar-fill" style="width: {{ (item.count / total_watched * 100) }}%;"></div>
                    {% endif %}
                  </div>
                  <strong>{{ item.count }}</strong>
                </div>
                {% endfor %}
              </div>
            </section>

            {% if films_per_country %}
            <section class="public-section public-section-wide">
              <div class="public-section-head">
                <p class="eyebrow">Geography</p>
                <h2>Most watched countries</h2>
              </div>
              <div class="public-country-grid">
                {% for item in films_per_country %}
                <div class="public-country-card">
                  <strong>{{ item.count }}</strong>
                  <span>{{ item.country }}</span>
                </div>
                {% endfor %}
              </div>
            </section>
            {% endif %}

            {% if recent_films %}
            <section class="public-section public-section-wide">
              <div class="public-section-head">
                <p class="eyebrow">Recent</p>
                <h2>Recently watched</h2>
              </div>
              <div class="public-poster-grid">
                {% for film in recent_films %}
                <article class="public-poster-card">
                  <div class="poster-frame public-poster-frame">
                    {% if film.poster_url %}
                      <img src="{{ film.poster_url }}" alt="{{ film.title }} poster" loading="lazy">
                    {% else %}
                      <span>{{ film.title[:1] }}</span>
                    {% endif %}
                  </div>
                  <h3>{{ film.title }}</h3>
                  <p>{{ film.year }}{% if film.director %} · {{ film.director }}{% endif %}</p>
                  {% if film.date_watched %}
                  <span class="public-poster-meta">{{ film.date_watched[:10] }}</span>
                  {% endif %}
                </article>
                {% endfor %}
              </div>
            </section>
            {% endif %}
          </div>
        </section>

        <section id="panel-films" class="public-panel" hidden>
          <div id="public-films-feed" class="public-feed"></div>
          <div id="public-films-sentinel" data-offset="0" data-total="{{ total_watched }}" class="public-feed-sentinel"></div>
        </section>
      </main>

      <footer class="public-footer">
        <p>Made with <a href="https://git.tylerhoang.xyz/lumi.git">Lumière</a></p>
      </footer>
    </div>

    <script>
      const tabs = document.querySelectorAll(".public-tab");
      const panels = document.querySelectorAll(".public-panel");
      let filmsLoaded = false;

      function setActiveTab(tabName) {
        tabs.forEach((tab) => {
          const active = tab.dataset.tab === tabName;
          tab.classList.toggle("is-active", active);
        });
        panels.forEach((panel) => {
          const active = panel.id === `panel-${tabName}`;
          panel.hidden = !active;
        });
      }

      async function loadPublicFilms() {
        if (filmsLoaded) return;
        filmsLoaded = true;

        const sentinel = document.querySelector("#public-films-sentinel");
        const feed = document.querySelector("#public-films-feed");
        let loading = false;

        const loadMore = async () => {
          if (loading) return;
          loading = true;
          const offset = Number(sentinel.dataset.offset || 0);

          try {
            const response = await fetch(`/tyler/films/partial?offset=${offset}&limit=20`);
            if (!response.ok) return;
            const html = await response.text();
            const hasMore = response.headers.get("X-Has-More") === "true";

            if (html.trim()) {
              feed.insertAdjacentHTML("beforeend", html);
            }

            if (!hasMore) {
              observer.disconnect();
              sentinel.remove();
            } else {
              sentinel.dataset.offset = String(offset + 20);
            }
          } catch (error) {
            console.error("Failed to load public films", error);
          } finally {
            loading = false;
          }
        };

        const observer = new IntersectionObserver((entries) => {
          entries.forEach((entry) => {
            if (entry.isIntersecting) {
              loadMore();
            }
          });
        }, { rootMargin: "100px" });

        observer.observe(sentinel);
        loadMore();
      }

      tabs.forEach((tab) => {
        tab.addEventListener("click", () => {
          const tabName = tab.dataset.tab;
          setActiveTab(tabName);
          if (tabName === "films") {
            loadPublicFilms();
          }
        });
      });
    </script>
  </body>
</html>