source: Klonkt/src/views/partials/profile-sheet.ejs@ 5a6a457

main
Last change on this file since 5a6a457 was 5410d4d, checked in by Robin Genis <roboburr@…>, 3 months ago

Remove the dead Favourites feature (local likes replaced by fediverse ⭐)

No local likes anymore, so /favorieten could never fill. Removed the route, the
favorites view, the local POST /posts/:id/like toggle, the Favourites menu items
(topnav + profile sheet), and the now-dead like queries/imports. post_likes table
left in place (harmless).

Co-Authored-By: Claude <noreply@…>

  • Property mode set to 100644
File size: 15.0 KB
Line 
1<%
2// Profile bottom sheet — mobile-only.
3//
4// Triggered by tapping any element with [data-profile-sheet-toggle]
5// (the Profiel tab in bottom-tab.ejs sets this).
6//
7// UX matches .audio-sheet for consistency: slide-up from bottom,
8// drag-to-dismiss, blur backdrop, safe-area-aware. Hidden ≥768px
9// (desktop uses the user dropdown in top-nav).
10//
11// Extension point: add more <li> blocks in any of the menu groups.
12
13if (!user) return;
14
15const _isAdmin = (user.role === 'god' || user.role === 'admin');
16const _canPost = !!((typeof canMutate === 'undefined' || canMutate)
17 && typeof permissions !== 'undefined'
18 && permissions
19 && permissions.canCreatePost
20 && permissions.canCreatePost(user, site));
21const _roleLabel = (user.role === 'god' || user.role === 'admin') ? 'beheerder'
22 : (user.role === 'editor') ? 'redacteur'
23 : '';
24// Site-scoped link (post-aanmaken) heeft in hub de /user/<slug>-prefix nodig.
25const _base = (typeof siteUrlBase !== 'undefined' && siteUrlBase) ? siteUrlBase : '';
26%>
27
28<div class="profile-sheet" id="profile-sheet" aria-hidden="true" role="dialog" aria-label="Profiel menu">
29 <div class="profile-sheet-backdrop" id="profile-sheet-backdrop"></div>
30 <div class="profile-sheet-panel">
31
32 <div class="profile-sheet-drag-zone" id="profile-sheet-drag-zone">
33 <button type="button" class="profile-sheet-handle" id="profile-sheet-close" aria-label="Sluiten"></button>
34 </div>
35
36 <!-- Identity header -->
37 <div class="profile-sheet-header">
38 <% if (user.avatar_url) { %>
39 <img class="profile-sheet-avatar profile-sheet-avatar-img" src="<%= user.avatar_url %>" alt="" aria-hidden="true">
40 <% } else { %>
41 <div class="profile-sheet-avatar" aria-hidden="true"><%= user.username.charAt(0).toUpperCase() %></div>
42 <% } %>
43 <div class="profile-sheet-meta">
44 <div class="profile-sheet-name"><%= user.username %></div>
45 <% if (_roleLabel) { %><div class="profile-sheet-role"><%= _roleLabel %></div><% } %>
46 </div>
47 </div>
48
49 <!-- Group 1: primary destinations -->
50 <ul class="profile-sheet-menu" role="menu">
51 <li role="none">
52 <a href="/account" class="profile-sheet-item" role="menuitem" data-close-sheet>
53 <svg class="psi-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
54 <span class="psi-label">Account</span>
55 <svg class="psi-chev" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="9 18 15 12 9 6"/></svg>
56 </a>
57 </li>
58 <li role="none">
59 <a href="/notifications" class="profile-sheet-item" role="menuitem" data-close-sheet>
60 <svg class="psi-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 8a6 6 0 0 0-12 0c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 0 1-3.46 0"/></svg>
61 <span class="psi-label"><%= t('nav.notifications') %><% if (typeof notifUnread !== 'undefined' && notifUnread > 0) { %> (<%= notifUnread %>)<% } %></span>
62 <svg class="psi-chev" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="9 18 15 12 9 6"/></svg>
63 </a>
64 </li>
65 <% if (typeof canSeeBeheer !== 'undefined' && canSeeBeheer) { %>
66 <li role="none">
67 <a href="/admin" class="profile-sheet-item" role="menuitem" data-close-sheet>
68 <svg class="psi-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 3h7v7H3zM14 3h7v7h-7zM14 14h7v7h-7zM3 14h7v7H3z"/></svg>
69 <span class="psi-label">Beheer</span>
70 <svg class="psi-chev" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="9 18 15 12 9 6"/></svg>
71 </a>
72 </li>
73 <% } %>
74 <% if (_canPost) { %>
75 <li role="none">
76 <a href="<%= _base %>/posts/new" class="profile-sheet-item" role="menuitem" data-close-sheet
77 hx-get="<%= _base %>/posts/new?partial=1" hx-target="#pcms-main" hx-swap="innerHTML"
78 hx-push-url="<%= _base %>/posts/new" hx-indicator="#pcms-loading">
79 <svg class="psi-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/></svg>
80 <span class="psi-label">Nieuwe post</span>
81 <svg class="psi-chev" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="9 18 15 12 9 6"/></svg>
82 </a>
83 </li>
84 <% } %>
85 </ul>
86
87 <div class="profile-sheet-divider" role="separator"></div>
88
89 <!-- Group 2: preferences (inline toggles) -->
90 <ul class="profile-sheet-menu" role="menu">
91 <li role="none">
92 <button type="button" class="profile-sheet-item" id="profile-sheet-theme" role="menuitemcheckbox">
93 <svg class="psi-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"/></svg>
94 <span class="psi-label">Thema</span>
95 <span class="psi-meta" id="profile-sheet-theme-state">Donker</span>
96 </button>
97 </li>
98 </ul>
99
100 <div class="profile-sheet-divider" role="separator"></div>
101
102 <!-- Group 3: destructive actions -->
103 <ul class="profile-sheet-menu" role="menu">
104 <li role="none">
105 <a href="/auth/logout" class="profile-sheet-item is-destructive" role="menuitem">
106 <svg class="psi-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>
107 <span class="psi-label">Uitloggen</span>
108 </a>
109 </li>
110 </ul>
111
112 </div>
113</div>
114
115<style>
116/* ============================================================
117 PROFILE SHEET — mobile bottom-sheet menu
118 Hidden ≥768px (desktop uses .user-menu dropdown in top-nav).
119 ============================================================ */
120
121.profile-sheet {
122 position: fixed;
123 inset: 0;
124 z-index: 1100; /* same as audio-sheet — modal layer */
125 pointer-events: none;
126 opacity: 0;
127 transition: opacity .2s ease;
128}
129.profile-sheet.is-open {
130 pointer-events: auto;
131 opacity: 1;
132}
133
134@media (min-width: 768px) {
135 /* Desktop has its own user-menu dropdown */
136 .profile-sheet { display: none !important; }
137}
138
139body.profile-sheet-locked { overflow: hidden; }
140
141.profile-sheet-backdrop {
142 position: absolute;
143 inset: 0;
144 background: color-mix(in srgb, var(--ink, #000) 35%, transparent);
145 backdrop-filter: blur(6px);
146 -webkit-backdrop-filter: blur(6px);
147}
148
149.profile-sheet-panel {
150 position: absolute;
151 left: 0; right: 0; bottom: 0;
152 background: var(--paper);
153 color: var(--ink);
154 border-top-left-radius: 22px;
155 border-top-right-radius: 22px;
156 box-shadow: 0 -20px 60px rgba(0, 0, 0, .25);
157 padding-bottom: max(.75rem, env(safe-area-inset-bottom, 0));
158 transform: translateY(100%);
159 transition: transform .3s cubic-bezier(.22, .9, .3, 1);
160 display: flex;
161 flex-direction: column;
162 max-height: 85vh;
163 overflow-y: auto;
164 overscroll-behavior: contain;
165}
166.profile-sheet.is-open .profile-sheet-panel {
167 transform: translateY(var(--pcms-drag-y, 0px));
168}
169.profile-sheet-panel.is-dragging { transition: none; will-change: transform; }
170
171[data-theme="dark"] .profile-sheet-panel {
172 box-shadow: 0 -20px 60px rgba(0, 0, 0, .5);
173}
174
175/* ── Drag handle zone ───────────────────────────── */
176.profile-sheet-drag-zone {
177 flex-shrink: 0;
178 padding: 12px 16px 4px;
179 /* MUST be 'none' so JS pointer events get the gesture (see audio-sheet) */
180 touch-action: none;
181 user-select: none;
182 -webkit-user-select: none;
183 cursor: grab;
184}
185.profile-sheet-drag-zone:active { cursor: grabbing; }
186@media (hover: hover) and (pointer: fine) {
187 /* On desktop the sheet isn't shown anyway, but be safe */
188 .profile-sheet-drag-zone { touch-action: auto; cursor: default; }
189}
190
191.profile-sheet-handle {
192 display: block;
193 margin: 0 auto;
194 width: 44px;
195 height: 4px;
196 border-radius: 2px;
197 background: color-mix(in srgb, var(--ink, #000) 25%, transparent);
198 border: 0;
199 padding: 0;
200 position: relative;
201}
202.profile-sheet-handle::before {
203 /* Larger invisible tap target on the handle itself */
204 content: "";
205 position: absolute;
206 inset: -16px -32px;
207}
208
209/* ── Identity header ────────────────────────────── */
210.profile-sheet-header {
211 display: flex;
212 align-items: center;
213 gap: 14px;
214 padding: 8px 20px 18px;
215}
216.profile-sheet-avatar {
217 width: 48px;
218 height: 48px;
219 display: flex;
220 align-items: center;
221 justify-content: center;
222 border-radius: 50%;
223 background: var(--paper-2); /* neutral so transparent avatars blend */
224 color: var(--accent); /* fallback initial color */
225 font-family: var(--font-ui);
226 font-weight: 700;
227 font-size: 20px;
228 flex-shrink: 0;
229 overflow: hidden;
230}
231.profile-sheet-avatar-img {
232 /* When rendered as <img>, fill the round container edge-to-edge. */
233 object-fit: cover;
234}
235.profile-sheet-meta { min-width: 0; }
236.profile-sheet-name {
237 font-family: var(--font-display, var(--font-ui));
238 font-size: 1.2rem;
239 font-weight: 600;
240 line-height: 1.2;
241 color: var(--ink);
242}
243.profile-sheet-role {
244 font-family: var(--font-ui);
245 font-size: .82rem;
246 color: var(--ink-soft);
247 margin-top: 3px;
248 text-transform: lowercase;
249 letter-spacing: .02em;
250}
251
252/* ── Menu list ──────────────────────────────────── */
253.profile-sheet-menu {
254 list-style: none;
255 margin: 0;
256 padding: 0;
257}
258.profile-sheet-divider {
259 height: 1px;
260 background: var(--rule);
261 margin: 4px 20px;
262}
263.profile-sheet-item {
264 display: flex;
265 align-items: center;
266 gap: 14px;
267 width: 100%;
268 min-height: 52px;
269 padding: 12px 20px;
270 background: transparent;
271 border: 0;
272 color: var(--ink);
273 text-decoration: none;
274 font-family: var(--font-ui);
275 font-size: 1rem;
276 text-align: left;
277 cursor: pointer;
278 -webkit-tap-highlight-color: transparent;
279 transition: background .12s ease, transform .12s ease;
280}
281.profile-sheet-item:active {
282 background: var(--paper-2);
283 transform: scale(0.99);
284}
285@media (hover: hover) {
286 .profile-sheet-item:hover { background: var(--paper-2); }
287}
288
289.psi-icon {
290 width: 22px;
291 height: 22px;
292 flex-shrink: 0;
293 color: var(--ink-soft);
294}
295.psi-label {
296 flex: 1;
297 min-width: 0;
298}
299.psi-chev {
300 width: 16px;
301 height: 16px;
302 color: var(--ink-muted);
303 flex-shrink: 0;
304}
305.psi-meta {
306 font-size: .85rem;
307 color: var(--ink-soft);
308 font-family: var(--font-ui);
309}
310
311.profile-sheet-item.is-destructive { color: #dc2626; }
312.profile-sheet-item.is-destructive .psi-icon { color: currentColor; }
313[data-theme="dark"] .profile-sheet-item.is-destructive { color: #f87171; }
314</style>
315
316<script>
317(function() {
318 const sheet = document.getElementById('profile-sheet');
319 if (!sheet) return;
320
321 const backdrop = document.getElementById('profile-sheet-backdrop');
322 const panel = sheet.querySelector('.profile-sheet-panel');
323 const closeBtn = document.getElementById('profile-sheet-close');
324 const dragZone = document.getElementById('profile-sheet-drag-zone');
325 const themeBtn = document.getElementById('profile-sheet-theme');
326 const themeLbl = document.getElementById('profile-sheet-theme-state');
327
328 function openSheet() {
329 sheet.classList.add('is-open');
330 sheet.setAttribute('aria-hidden', 'false');
331 document.body.classList.add('profile-sheet-locked');
332 syncTheme();
333 }
334 function closeSheet() {
335 sheet.classList.remove('is-open');
336 sheet.setAttribute('aria-hidden', 'true');
337 document.body.classList.remove('profile-sheet-locked');
338 panel.style.removeProperty('--pcms-drag-y');
339 }
340
341 // Open: any element with [data-profile-sheet-toggle]
342 document.addEventListener('click', function(e) {
343 const trigger = e.target.closest('[data-profile-sheet-toggle]');
344 if (trigger) {
345 e.preventDefault();
346 openSheet();
347 }
348 });
349
350 // Close: backdrop tap, handle tap, ESC, or any [data-close-sheet] item
351 if (backdrop) backdrop.addEventListener('click', closeSheet);
352 if (closeBtn) closeBtn.addEventListener('click', closeSheet);
353 document.addEventListener('keydown', (e) => {
354 if (e.key === 'Escape' && sheet.classList.contains('is-open')) closeSheet();
355 });
356
357 // Menu items that navigate: close synchronously before nav fires
358 sheet.querySelectorAll('[data-close-sheet]').forEach((el) => {
359 el.addEventListener('click', closeSheet);
360 });
361
362 // Drag-down-to-close on touch.
363 // Uses --pcms-drag-y custom property rather than overwriting the panel's
364 // transform string. This composes correctly with any horizontal centering
365 // (currently none here, but the pattern matches audio-sheet for safety).
366 let startY = 0, lastY = 0, dragging = false;
367 function onDown(e) {
368 if (e.pointerType !== 'touch') return;
369 if (panel.scrollTop > 0) return;
370 startY = lastY = e.clientY;
371 dragging = true;
372 panel.classList.add('is-dragging');
373 }
374 function onMove(e) {
375 if (!dragging) return;
376 lastY = e.clientY;
377 const dy = Math.max(0, lastY - startY);
378 panel.style.setProperty('--pcms-drag-y', dy + 'px');
379 }
380 function onUp() {
381 if (!dragging) return;
382 dragging = false;
383 panel.classList.remove('is-dragging');
384 const dy = lastY - startY;
385 if (dy > 80) closeSheet();
386 else panel.style.removeProperty('--pcms-drag-y');
387 }
388 if (window.PointerEvent && dragZone) {
389 dragZone.addEventListener('pointerdown', onDown);
390 document.addEventListener('pointermove', onMove);
391 document.addEventListener('pointerup', onUp);
392 document.addEventListener('pointercancel', onUp);
393 }
394
395 // Theme toggle inside sheet — syncs label
396 function syncTheme() {
397 if (!themeLbl) return;
398 const t = document.documentElement.getAttribute('data-theme') || 'dark';
399 themeLbl.textContent = t === 'dark' ? 'Donker' : 'Licht';
400 }
401 if (themeBtn) {
402 themeBtn.addEventListener('click', function() {
403 const cur = document.documentElement.getAttribute('data-theme') || 'dark';
404 const next = cur === 'dark' ? 'light' : 'dark';
405 document.documentElement.setAttribute('data-theme', next);
406 try { localStorage.setItem('pcms-theme', next); } catch (e) {}
407 syncTheme();
408 });
409 }
410})();
411</script>
Note: See TracBrowser for help on using the repository browser.