Browse Source

Mobile header, user menu

imwald
Nuša Pukšič 8 months ago
parent
commit
6f8b9042c9
  1. 11
      assets/controllers/login_controller.js
  2. 9
      assets/controllers/menu_controller.js
  3. 3
      assets/styles/app.css
  4. 53
      assets/styles/layout.css
  5. 4
      assets/styles/spinner.css
  6. 9
      templates/components/Header.html.twig
  7. 7
      templates/components/UserMenu.html.twig

11
assets/controllers/login_controller.js

@ -8,7 +8,7 @@ export default class extends Controller {
async loginAct() { async loginAct() {
const tags = [ const tags = [
['u', window.location.origin + '/login'], ['u', window.location.origin + '/login'],
['method', 'GET'] ['method', 'POST']
] ]
const ev = { const ev = {
created_at: Math.floor(Date.now()/1000), created_at: Math.floor(Date.now()/1000),
@ -20,15 +20,14 @@ export default class extends Controller {
const signed = await window.nostr.signEvent(ev); const signed = await window.nostr.signEvent(ev);
// base64 encode and send as Auth header // base64 encode and send as Auth header
const result = await fetch('/login', { const result = await fetch('/login', {
method: 'GET', method: 'POST',
credentials: 'same-origin',
headers: { headers: {
'Authorization': 'Nostr ' + btoa(JSON.stringify(signed)) 'Authorization': 'Nostr ' + btoa(JSON.stringify(signed))
} }
}).then(response => { }).then(response => {
if (response.ok) return response.json(); if (!response.ok) return false;
return false; return 'Authentication Successful';
}).then(res => {
return res;
}) })
if (!!result) { if (!!result) {
this.component.render(); this.component.render();

9
assets/controllers/menu_controller.js

@ -0,0 +1,9 @@
import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
static targets = ["menu"];
toggle() {
this.menuTarget.classList.toggle("active");
}
}

3
assets/styles/app.css

@ -262,9 +262,8 @@ div:nth-child(odd) .featured-list {
z-index: 1000; /* Ensure it stays on top */ z-index: 1000; /* Ensure it stays on top */
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-around;
align-items: center; align-items: center;
padding: 10px 20px;
background-color: var(--color-bg); /* Black background */ background-color: var(--color-bg); /* Black background */
border-bottom: 1px solid var(--color-border); /* White bottom border */ border-bottom: 1px solid var(--color-border); /* White bottom border */
} }

53
assets/styles/layout.css

@ -48,13 +48,65 @@ nav a:hover {
text-decoration: none; text-decoration: none;
} }
header {
position: fixed;
width: 100vw;
top: 0;
left: 0;
}
/* Hamburger button */
.hamburger {
cursor: pointer;
display: none; /* Hidden on desktop */
}
.header__logo {
display: flex;
width: 100%;
justify-content: center;
}
/* Mobile Styles */
@media (max-width: 768px) {
.header__logo {
justify-content: space-around;
}
.header__categories {
display: none;
flex-direction: column;
padding-top: 1rem;
}
.header__categories.active {
display: flex;
}
.hamburger {
display: block;
align-self: center;
}
.header__categories ul {
flex-direction: column;
gap: 0.5rem;
}
}
/* Main content */ /* Main content */
main { main {
margin-top: 140px;
flex-grow: 1; flex-grow: 1;
padding: 1em; padding: 1em;
word-break: break-word; word-break: break-word;
} }
.user-menu {
position: fixed;
top: 180px;
}
/* Right sidebar */ /* Right sidebar */
aside { aside {
width: 190px; width: 190px;
@ -90,6 +142,7 @@ dt {
display: none; /* Hide the sidebars on small screens */ display: none; /* Hide the sidebars on small screens */
} }
main { main {
margin-top: 120px;
width: 100%; width: 100%;
} }
} }

4
assets/styles/spinner.css

@ -7,8 +7,8 @@
.lds-dual-ring { .lds-dual-ring {
display: inline-block; display: inline-block;
width: 40px; width: 30px;
height: 40px; height: 30px;
} }
.lds-dual-ring:after { .lds-dual-ring:after {
content: " "; content: " ";

9
templates/components/Header.html.twig

@ -1,6 +1,9 @@
<header class="header"> <header class="header" data-controller="menu" {{ attributes }}>
<div class="header__logo"><h1 class="brand"><a href="/">newsroom</a></h1></div> <div class="header__logo">
<div class="header__categories"> <h1 class="brand"><a href="/">newsroom</a></h1>
<button class="hamburger" data-action="click->menu#toggle" aria-label="Menu">&#9776;</button>
</div>
<div class="header__categories" data-menu-target="menu">
<ul> <ul>
{% for category in cats %} {% for category in cats %}
<li><twig:Molecules:CategoryLink coordinate="{{ category }}" /></li> <li><twig:Molecules:CategoryLink coordinate="{{ category }}" /></li>

7
templates/components/UserMenu.html.twig

@ -1,4 +1,4 @@
<div {{ attributes.defaults(stimulus_controller('login')) }}> <div class="user-menu" {{ attributes.defaults(stimulus_controller('login')) }}>
{% if app.user %} {% if app.user %}
<p>Hello, {{ app.user.displayName }}</p> <p>Hello, {{ app.user.displayName }}</p>
{% if is_granted('ROLE_ADMIN') %} {% if is_granted('ROLE_ADMIN') %}
@ -31,4 +31,9 @@
{% else %} {% else %}
<twig:Atoms:Button {{ ...stimulus_action('login', 'loginAct') }}>{{ 'heading.logIn'|trans }}</twig:Atoms:Button> <twig:Atoms:Button {{ ...stimulus_action('login', 'loginAct') }}>{{ 'heading.logIn'|trans }}</twig:Atoms:Button>
{% endif %} {% endif %}
<div style="text-align: center">
<div class="spinner" data-loading>
<div class="lds-dual-ring"></div>
</div>
</div>
</div> </div>

Loading…
Cancel
Save