source: Klonkt/src/views/pages/authorize-interaction.ejs@ 9d34855

main
Last change on this file since 9d34855 was c7ecaf9, checked in by Robin Genis <roboburr@…>, 2 months ago

feat(fedi): like/boost toggle in place on the interact page (no reload)

The Like/Boost forms now POST via fetch and flip the button + label client-side, so you
stay on the page instead of a full redirect+re-resolve. Route returns JSON {on} for a
fetch request (X-Requested-With), and still redirects for the no-JS fallback. Body sent
as urlencoded so the existing body parser reads it.

  • Property mode set to 100644
File size: 14.6 KB
Line 
1<div class="auth-interact">
2 <% if (typeof manage !== 'undefined' && manage) { %>
3 <%- include('../partials/fedi-tabs', { active: 'reacties' }) %>
4 <h1 class="auth-interact-title"><%= t('fedi.manage_title') %></h1>
5 <% if (!manage.length) { %>
6 <p class="auth-interact-note"><%= t('fedi.manage_empty') %></p>
7 <% } else { %>
8 <ul class="fedi-manage">
9 <% manage.forEach(function(m){ %>
10 <li class="fedi-manage-item">
11 <div class="fedi-manage-head">
12 <span class="fedi-manage-icon" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 17 4 12 9 7"/><path d="M20 18v-2a4 4 0 0 0-4-4H4"/></svg></span>
13 <% if (m.to_handle) { %><span class="fedi-manage-to"><%= m.to_handle %></span><% } %>
14 <% if (m.created_at && typeof formatDateTime === 'function') { %><span class="fedi-manage-time"><%= formatDateTime(m.created_at) %></span><% } %>
15 </div>
16 <div class="fedi-manage-content"><%- m.content %></div>
17 <div class="fedi-manage-foot">
18 <form method="post" action="/fediverse/<%= m.id %>/delete" onsubmit="return confirm('<%= t('fedi.delete_confirm') %>')">
19 <button type="submit" class="fedi-del-btn"><svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg> <%= t('comments.delete') %></button>
20 </form>
21 </div>
22 </li>
23 <% }); %>
24 </ul>
25 <% } %>
26 <p class="auth-interact-note"><a href="/"><%= t('fedi.remote_back') %></a></p>
27 <% } else if (typeof liked !== 'undefined' && liked) { %>
28 <h1 class="auth-interact-title">★ <%= t('fedi.liked_title') %></h1>
29 <p class="auth-interact-note"><%= t('fedi.liked_done') %></p>
30 <p class="auth-interact-actions">
31 <% if (uri) { %><a class="btn" href="<%= uri %>" rel="nofollow noopener"><%= t('fedi.remote_view_original') %></a><% } %>
32 <a class="btn btn-primary" href="/"><%= t('fedi.remote_back') %></a>
33 </p>
34 <% } else if (typeof boosted !== 'undefined' && boosted) { %>
35 <h1 class="auth-interact-title">🔁 <%= t('fedi.boosted_title') %></h1>
36 <p class="auth-interact-note"><%= t('fedi.boosted_done') %></p>
37 <p class="auth-interact-actions">
38 <% if (uri) { %><a class="btn" href="<%= uri %>" rel="nofollow noopener"><%= t('fedi.remote_view_original') %></a><% } %>
39 <a class="btn btn-primary" href="/"><%= t('fedi.remote_back') %></a>
40 </p>
41 <% } else if (typeof followed !== 'undefined' && followed) { %>
42 <h1 class="auth-interact-title"><%= t('fedi.followed_title') %></h1>
43 <p class="auth-interact-note"><%= t('fedi.followed_done') %></p>
44 <p class="auth-interact-actions">
45 <% if (uri) { %><a class="btn" href="<%= uri %>" rel="nofollow noopener"><%= t('fedi.view_profile') %></a><% } %>
46 <a class="btn btn-primary" href="/"><%= t('fedi.remote_back') %></a>
47 </p>
48 <% } else if (typeof sent !== 'undefined' && sent) { %>
49 <h1 class="auth-interact-title"><%= t('fedi.remote_sent_title') %></h1>
50 <p class="auth-interact-note"><%= t('fedi.remote_sent') %></p>
51 <p class="auth-interact-actions">
52 <% if (uri) { %><a class="btn btn-primary" href="<%= uri %>" rel="nofollow noopener"><%= t('fedi.remote_view_original') %></a><% } %>
53 <a class="btn" href="/"><%= t('fedi.remote_back') %></a>
54 </p>
55 <% } else if (typeof followTarget !== 'undefined' && followTarget) { %>
56 <h1 class="auth-interact-title"><%= t('fedi.follow_heading') %></h1>
57 <p class="auth-interact-meta">
58 <%= t('fedi.follow_intro') %>
59 <a href="<%= followTarget.actor_url %>" rel="nofollow noopener" target="_blank"><strong><%= followTarget.actor_name %></strong></a>
60 <span class="fedi-handle"><%= followTarget.actor_handle %></span>
61 </p>
62 <form method="post" action="/authorize_interaction/follow" class="auth-interact-form">
63 <input type="hidden" name="uri" value="<%= followTarget.actor_uri %>">
64 <div class="auth-interact-actions">
65 <button type="submit" class="btn btn-primary"><%= t('fedi.follow_btn') %></button>
66 <a href="/" class="btn"><%= t('comments.cancel') %></a>
67 </div>
68 </form>
69 <p class="auth-interact-note"><%= t('fedi.remote_as', { site: siteTitle }) %></p>
70 <% } else { %>
71 <h1 class="auth-interact-title"><%= t('fedi.remote_title') %></h1>
72
73 <% if (!target) { %>
74 <p class="auth-interact-note"><%= t('fedi.remote_notfound') %></p>
75 <form method="get" action="/authorize_interaction" class="auth-interact-form">
76 <input type="url" name="uri" placeholder="https://…/een-post" value="<%= uri || '' %>" required>
77 <button type="submit" class="btn btn-primary"><%= t('fedi.remote_load') %></button>
78 </form>
79 <% } else { %>
80 <p class="auth-interact-meta">
81 <%= t('fedi.remote_replying_to') %>
82 <a href="<%= target.actor_url %>" rel="nofollow noopener" target="_blank"><strong><%= target.actor_name %></strong></a>
83 <span class="fedi-handle"><%= target.actor_handle %></span>
84 </p>
85 <blockquote class="auth-interact-preview">
86 <% if (target.content) { %><div class="auth-interact-content"><%- target.content %></div>
87 <% } else if (target.preview) { %><%= target.preview %><% } %>
88 <% (target.images || []).forEach(function(im){ %>
89 <img class="auth-interact-img" src="<%= im %>" alt="" loading="lazy">
90 <% }); %>
91 </blockquote>
92 <% if (target.url || uri) { %>
93 <a class="auth-view-src" href="<%= target.url || uri %>" target="_blank" rel="nofollow noopener">
94 <svg viewBox="0 0 24 24" width="17" height="17" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 17 17 7"/><path d="M7 7h10v10"/></svg>
95 <span><%= t('fedi.remote_view_original') %></span>
96 </a>
97 <% } %>
98 <% var _liked = (typeof reacted !== 'undefined' && reacted.liked); var _boosted = (typeof reacted !== 'undefined' && reacted.boosted); %>
99 <div class="auth-interact-react">
100 <form method="post" action="/authorize_interaction/like" class="fedi-react-form">
101 <input type="hidden" name="uri" value="<%= uri %>">
102 <button type="submit" class="fedi-bigact fedi-bigact-like<%= _liked ? ' is-on' : '' %>" data-on="<%= t('fedi.unlike_short') %>" data-off="<%= t('fedi.like_short') %>">
103 <svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M12 2.6l2.9 5.88 6.49.95-4.7 4.58 1.11 6.46L12 17.96l-5.8 3.06 1.1-6.46-4.69-4.58 6.49-.95z"/></svg>
104 <span class="fedi-bigact-label"><%= _liked ? t('fedi.unlike_short') : t('fedi.like_short') %></span>
105 </button>
106 </form>
107 <form method="post" action="/authorize_interaction/boost" class="fedi-react-form">
108 <input type="hidden" name="uri" value="<%= uri %>">
109 <button type="submit" class="fedi-bigact fedi-bigact-boost<%= _boosted ? ' is-on' : '' %>" data-on="<%= t('tl.unboost') %>" data-off="<%= t('fedi.boost_short') %>">
110 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="17 1 21 5 17 9"/><path d="M3 11V9a4 4 0 0 1 4-4h14"/><polyline points="7 23 3 19 7 15"/><path d="M21 13v2a4 4 0 0 1-4 4H3"/></svg>
111 <span class="fedi-bigact-label"><%= _boosted ? t('tl.unboost') : t('fedi.boost_short') %></span>
112 </button>
113 </form>
114 </div>
115 <p class="auth-interact-or"><%= t('fedi.or_reply') %></p>
116 <p class="auth-interact-where">💬 <%= t('fedi.reply_where') %></p>
117 <form method="post" action="/authorize_interaction" class="auth-interact-form">
118 <input type="hidden" name="uri" value="<%= uri %>">
119 <textarea name="text" rows="4" required placeholder="<%= t('fedi.reply_ph') %>"></textarea>
120 <div class="auth-interact-actions">
121 <button type="submit" class="btn"><%= t('fedi.send') %></button>
122 <a href="<%= uri %>" class="btn"><%= t('comments.cancel') %></a>
123 </div>
124 </form>
125 <p class="auth-interact-note"><%= t('fedi.remote_as', { site: siteTitle }) %></p>
126 <% } %>
127 <% } %>
128</div>
129
130<style>
131 .auth-interact { max-width: 640px; margin: 1rem auto; padding: 0 1rem; }
132 .auth-interact-title { margin: 0 0 1rem; }
133 .auth-interact-meta { color: var(--ink-soft, #888); margin: 0 0 .75rem; }
134 .auth-interact-preview {
135 margin: 0 0 1rem; padding: .75rem 1rem; border-left: 3px solid var(--accent, #888);
136 background: color-mix(in srgb, var(--ink, #000) 4%, transparent); border-radius: 0 12px 12px 0;
137 color: var(--ink, inherit);
138 }
139 .auth-interact-form { display: flex; flex-direction: column; gap: .75rem; }
140 .auth-interact-form textarea, .auth-interact-form input[type=url] {
141 width: 100%; box-sizing: border-box; padding: .6rem .8rem; font: inherit; resize: vertical;
142 border-radius: 12px; border: 1px solid color-mix(in srgb, var(--ink, #000) 18%, transparent);
143 background: var(--paper, #fff); color: var(--ink, #000);
144 }
145 .auth-interact-actions { display: flex; gap: .5rem; align-items: center; }
146 .auth-interact-note { color: var(--ink-soft, #999); font-size: .85rem; margin-top: 1rem; }
147 .auth-interact-where { margin: .25rem 0 .85rem; padding: .6rem .8rem; font-size: .85rem; line-height: 1.5; border-radius: 10px; background: color-mix(in srgb, var(--accent, #888) 12%, transparent); color: var(--ink, inherit); }
148 .auth-interact-content { line-height: 1.55; }
149 .auth-interact-content p { margin: .35rem 0; }
150 .auth-interact-content p:first-child { margin-top: 0; }
151 .auth-interact-img { max-width: 100%; height: auto; border-radius: 10px; margin: .5rem 0 0; display: block; }
152 .auth-interact-orig { margin: .75rem 0 0; font-size: .85rem; }
153 .auth-interact-orig a { color: var(--accent, #06c); }
154 .auth-view-src { display: inline-flex; align-items: center; gap: .5rem; margin: 0 0 1.1rem; padding: .6rem 1rem;
155 border: 1px solid color-mix(in srgb, var(--accent, #888) 45%, transparent); border-radius: 12px;
156 background: color-mix(in srgb, var(--accent, #888) 10%, transparent); color: var(--accent, #06c);
157 text-decoration: none; font-weight: 600; font-size: .92rem; transition: background .15s, border-color .15s; }
158 .auth-view-src:hover { background: color-mix(in srgb, var(--accent, #888) 18%, transparent); border-color: var(--accent, #888); }
159 .auth-interact-react { display: flex; gap: .6rem; flex-wrap: wrap; margin: 0 0 .25rem; }
160 .auth-interact-react form { margin: 0; }
161 .fedi-bigact { display: inline-flex; align-items: center; gap: .5rem; padding: .55rem 1.1rem; border-radius: 999px;
162 border: 1px solid color-mix(in srgb, var(--ink, #000) 14%, transparent);
163 background: color-mix(in srgb, var(--ink, #000) 4%, transparent);
164 color: var(--ink, inherit); font: inherit; font-weight: 600; font-size: .92rem; cursor: pointer; white-space: nowrap;
165 transition: background .12s, border-color .12s; }
166 .fedi-bigact svg { width: 17px; height: 17px; flex: 0 0 17px; }
167 .fedi-bigact-like svg { color: #e8b04b; }
168 .fedi-bigact-like:hover, .fedi-bigact-like.is-on { background: color-mix(in srgb, #e8b04b 16%, transparent); border-color: color-mix(in srgb, #e8b04b 55%, transparent); }
169 .fedi-bigact-boost svg { color: #2fa85a; }
170 .fedi-bigact-boost:hover, .fedi-bigact-boost.is-on { background: color-mix(in srgb, #2fa85a 16%, transparent); border-color: color-mix(in srgb, #2fa85a 55%, transparent); }
171 .fedi-manage { list-style: none; padding: 0; margin: 1.25rem 0 1rem; display: flex; flex-direction: column; gap: .7rem; }
172 .fedi-manage-item { padding: .9rem 1rem; border-radius: 14px; background: color-mix(in srgb, var(--ink, #000) 3.5%, transparent); border: 1px solid color-mix(in srgb, var(--ink, #000) 9%, transparent); transition: border-color .15s ease, box-shadow .15s ease; }
173 .fedi-manage-item:hover { border-color: color-mix(in srgb, var(--accent, #888) 28%, transparent); box-shadow: 0 2px 12px color-mix(in srgb, var(--ink, #000) 6%, transparent); }
174 .fedi-manage-head { display: flex; align-items: center; gap: .5rem; margin: 0 0 .5rem; }
175 .fedi-manage-icon { flex: 0 0 26px; width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
176 background: color-mix(in srgb, var(--accent, #888) 16%, transparent); color: var(--accent, #06c); }
177 .fedi-manage-icon svg { width: 14px; height: 14px; }
178 .fedi-manage-to { font-weight: 600; color: var(--ink, inherit); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
179 .fedi-manage-time { color: var(--ink-soft, #999); font-size: .76rem; margin-left: auto; flex: 0 0 auto; white-space: nowrap; }
180 .fedi-manage-content { line-height: 1.55; overflow-wrap: anywhere; padding-left: calc(26px + .5rem); }
181 .fedi-manage-content p { margin: .15rem 0; }
182 .fedi-manage-content p:first-child { margin-top: 0; }
183 .fedi-manage-content p:last-child { margin-bottom: 0; }
184 .fedi-manage-foot { display: flex; justify-content: flex-end; margin-top: .65rem; }
185 .fedi-del-btn { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid color-mix(in srgb, #d9534f 45%, transparent); background: color-mix(in srgb, #d9534f 12%, transparent); color: #e06b66; border-radius: 999px; padding: .3rem .8rem; font: inherit; font-size: .82rem; cursor: pointer; transition: background .15s ease; }
186 .fedi-del-btn:hover { background: color-mix(in srgb, #d9534f 24%, transparent); }
187</style>
188
189<script>
190/* Like/Boost toggle in place — POST via fetch, flip the button, stay on the page. */
191(function(){
192 if (window.__fediReactWired) return; window.__fediReactWired = true;
193 document.addEventListener('submit', function(e){
194 var f = e.target.closest && e.target.closest('.fedi-react-form');
195 if (!f) return;
196 e.preventDefault();
197 var btn = f.querySelector('button'); if (!btn || btn.disabled) return;
198 btn.disabled = true;
199 var body = new URLSearchParams();
200 new FormData(f).forEach(function(v, k){ body.append(k, v); });
201 fetch(f.action, { method: 'POST', body: body, headers: { 'X-Requested-With': 'fetch' }, credentials: 'same-origin' })
202 .then(function(r){ return r.ok ? r.json() : null; })
203 .then(function(j){
204 if (j) {
205 var on = !!j.on;
206 btn.classList.toggle('is-on', on);
207 var lbl = btn.querySelector('.fedi-bigact-label');
208 if (lbl) lbl.textContent = on ? (btn.getAttribute('data-on') || lbl.textContent) : (btn.getAttribute('data-off') || lbl.textContent);
209 }
210 })
211 .catch(function(){})
212 .then(function(){ btn.disabled = false; });
213 });
214})();
215</script>
Note: See TracBrowser for help on using the repository browser.