source: Klonkt/src/views/partials/profile-sheet.ejs@ 89cc8c4

main
Last change on this file since 89cc8c4 was eefd302, checked in by Robin Genis <roboburr@…>, 2 months ago

feat(fedi): rename feed Newspaper -> News (/newspaper -> /news)

EN label + route shortened to 'News' / '/news' (+ sub-routes, links, form actions,
render path, view newspaper.ejs->news.ejs, RESERVED_SLUGS, pageTitle). NL 'Krant' and
DE 'Zeitung' unchanged.

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