feat(marketplace/site): hash-route the views (#view=submit) — shareable + bookmarkable
The pins now update the hash so How it works / Submit / Submissions are deep-linkable; the #<slug> app-focus link still works. One parseHash() distinguishes them. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: librelad <librelad@digitalangels.vip>
This commit is contained in:
parent
d1caee0b54
commit
ae39bba93f
@ -278,11 +278,15 @@
|
||||
// their own marketplace set this to their repo (a <meta name="lp-repo"> wins).
|
||||
var REPO_URL = (document.querySelector('meta[name="lp-repo"]') || {}).content || 'https://github.com/librelad/LibrePortal';
|
||||
|
||||
function readFocus() {
|
||||
// The hash is either a view (#view=submit) or an app focus (#<slug>).
|
||||
function parseHash() {
|
||||
var h = (window.location.hash || '').replace(/^#/, '');
|
||||
return /^[a-z0-9][a-z0-9_]{0,31}$/.test(h) ? h : '';
|
||||
if (/^view=(howto|submit|submissions)$/.test(h)) return { view: h.slice(5), focus: '' };
|
||||
if (/^[a-z0-9][a-z0-9_]{0,31}$/.test(h)) return { view: 'browse', focus: h };
|
||||
return { view: 'browse', focus: '' };
|
||||
}
|
||||
var state = { view: 'browse', apps: [], cat: 'all', q: '', focus: readFocus(),
|
||||
var _ph = parseHash();
|
||||
var state = { view: _ph.view, apps: [], cat: 'all', q: '', focus: _ph.focus,
|
||||
idx: null, channel: 'stable', signed: false, submissions: null };
|
||||
var main = document.getElementById('main');
|
||||
var cats = document.getElementById('cats');
|
||||
@ -430,12 +434,20 @@
|
||||
else if (state.view === 'submissions') main.innerHTML = submissionsHtml();
|
||||
else renderBrowse();
|
||||
}
|
||||
function go(view) { state.view = view; window.scrollTo(0, 0); render(); }
|
||||
function setHash(h) {
|
||||
try { history.replaceState(null, '', h ? ('#' + h) : (window.location.pathname + window.location.search)); }
|
||||
catch (_) { window.location.hash = h; }
|
||||
}
|
||||
function go(view) {
|
||||
state.view = view; state.focus = '';
|
||||
setHash(view === 'browse' ? '' : ('view=' + view));
|
||||
window.scrollTo(0, 0); render();
|
||||
}
|
||||
function toBrowse() { state.view = 'browse'; }
|
||||
function clearFocus() {
|
||||
if (!state.focus) return;
|
||||
if (!state.focus && state.view === 'browse') return;
|
||||
state.focus = '';
|
||||
if (window.location.hash) { try { history.replaceState(null, '', window.location.pathname + window.location.search); } catch (_) { window.location.hash = ''; } }
|
||||
if (window.location.hash) setHash('');
|
||||
}
|
||||
|
||||
// ---- data ----
|
||||
@ -503,7 +515,7 @@
|
||||
if (e.target.closest('#showall')) { clearFocus(); render(); }
|
||||
});
|
||||
document.getElementById('q').addEventListener('input', function (e) { clearFocus(); toBrowse(); state.q = e.target.value; render(); });
|
||||
window.addEventListener('hashchange', function () { state.focus = readFocus(); if (state.focus) toBrowse(); render(); });
|
||||
window.addEventListener('hashchange', function () { var ph = parseHash(); state.view = ph.view; state.focus = ph.focus; render(); });
|
||||
|
||||
render();
|
||||
load();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user