source: Klonkt/src/views/partials/profile-sheet.ejs@ 0804d61

main
Last change on this file since 0804d61 was a3169f5, checked in by roboburr <roboburr@…>, 3 months ago

fix: viewer now sees the Admin link too (canSeeBeheer)

The Admin link was hidden for a viewer (nav only showed it for god/admin/site
owner), while the routes do allow a viewer read-only access. Single source of
truth canSeeBeheer (god/admin/viewer/owner) in render.js, used in topnav,
hub-nav, and profile sheet.

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

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