mirror of
https://git.j0bot.ch/admin_j0bot/ploxion-invite.git
synced 2026-11-29 06:45:10 +00:00
synchro du labo (0bf0da65) : app.blade.php, README.md
This commit is contained in:
parent
cfded8d14f
commit
1e26a9e6e3
22
README.md
22
README.md
@ -1,3 +1,21 @@
|
|||||||
# ploxion-invite
|
# ✉️ invitations
|
||||||
|
|
||||||
PLOXION · Invite tes potes par lien — ils créent leur compte j0bot et deviennent tes amis. Ou ouvre un lien d'invitation reçu. · fournit: invite, onboarding, friends
|
Invite tes potes par lien — ils créent leur compte j0bot et deviennent tes amis. Ou ouvre un lien d'invitation reçu.
|
||||||
|
|
||||||
|
| | |
|
||||||
|
| --- | --- |
|
||||||
|
| id | `invite` |
|
||||||
|
| fournit | `invite` `onboarding` `friends` |
|
||||||
|
| bions qu'il nomme | `jOSApps` `jOSMobile` `jOSQR` `jOSSocial` |
|
||||||
|
| fichiers | `app.blade.php` |
|
||||||
|
| dans le labo | `resources/views/ploxions/invite/` (dépôt `my_website2`) |
|
||||||
|
|
||||||
|
## Contribuer
|
||||||
|
|
||||||
|
- **Dans le xer** : https://labo.j0bot.ch/px/atelier?ploxion=invite — prends-le, modifie-le, vois-le tourner, « ⧗ envoyer le tsoin ».
|
||||||
|
- **Dans VS Code** : `xb prendre invite` (ou l'extension xerboxion › ⇩ Prendre), puis ⧗ Envoyer.
|
||||||
|
- Le chemin complet : https://labo.j0bot.ch/px/contribuer
|
||||||
|
|
||||||
|
Ce dépôt est un **miroir** du labo (synchronisé par `bin/ploxions-forge.mjs`, depuis le commit `0bf0da65`) : une modif se propose par un tsoin ou une branche du labo, pas directement ici.
|
||||||
|
|
||||||
|
© 2026 chill-tekk · ne pas nuire
|
||||||
|
|||||||
256
app.blade.php
Normal file
256
app.blade.php
Normal file
@ -0,0 +1,256 @@
|
|||||||
|
{{-- PL0XION invite — l'ONBOARDING par lien (RS-7 : « que par invite link pour se créer un compte ;
|
||||||
|
chaque xerion peut créer un link ; t'es direct ami avec qui t'a envoyé le link »). Ploxion
|
||||||
|
LABO client-side, parle à l'IdP api.j0bot.ch en direct (CORS *.j0bot.ch).
|
||||||
|
2 faces : (1) tu es invité (?code=) → crée ton compte j0bot en 5s (redeem, pas de PoW) et tu
|
||||||
|
deviens ami de l'inviteur ; (2) tu es loggué → génère/partage tes liens + vois tes amis.
|
||||||
|
Lien d'invitation = labo.j0bot.ch/?px=invite&code=<code>. window.jOSApps['invite'].
|
||||||
|
SOCIAL v0 lot A (24.09, D2-D3) : le graphe d'amis est LOCAL ; le bon geste pour inviter = ton QR / code d'ami dans
|
||||||
|
👥 Amis (invitation zion → /join). Ce ploxion garde la face (1) (les vieux liens ?code= marchent toujours) et affiche,
|
||||||
|
en mode local, un bandeau vers Amis. Kill-switch : jOSSocial.mode() === 'idp' → plus de bandeau, tout comme avant. --}}
|
||||||
|
<style>
|
||||||
|
.iv{--bg:var(--xr-bg,#0a0e14);--bg2:var(--xr-surface,#0e141d);--card:var(--xr-surface,#121a26);--card2:var(--xr-surface,#16202e);--line:var(--xr-border,rgba(120,160,230,.14));
|
||||||
|
--ink:var(--xr-text,#e7eef7);--dim:var(--xr-muted,#8aa0bc);--acc:var(--xr-accent,#6ad0ff);--acc2:var(--xr-accent2,#b88dff);--ok:#5ce08c;--ko:#e87a6a;
|
||||||
|
display:flex;flex-direction:column;height:100%;min-height:0;background:var(--bg);color:var(--ink);
|
||||||
|
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",system-ui,sans-serif;font-size:16px;overflow:hidden}
|
||||||
|
.iv *{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
|
||||||
|
.iv__view{flex:1;min-height:0;display:none;flex-direction:column}.iv__view.on{display:flex}
|
||||||
|
.iv__hd{flex:0 0 auto;display:flex;align-items:center;gap:10px;padding:11px 13px;background:var(--bg2);border-bottom:1px solid var(--line);min-height:50px}
|
||||||
|
.iv__hd .t{font-weight:700;font-size:1.02rem;flex:1}.iv__hd .sub{font-size:.68rem;color:var(--dim);font-weight:500}
|
||||||
|
.iv__ic{width:38px;height:38px;flex:0 0 auto;display:flex;align-items:center;justify-content:center;border-radius:11px;border:1px solid var(--line);background:var(--card);font-size:1.1rem;cursor:pointer;color:var(--ink)}
|
||||||
|
.iv__bd{flex:1;min-height:0;overflow-y:auto;-webkit-overflow-scrolling:touch;padding:16px}
|
||||||
|
.iv__authbd{display:flex;flex-direction:column;justify-content:center}
|
||||||
|
.iv__logo{text-align:center;margin-bottom:6px}.iv__logo .b{font-size:2.4rem}.iv__logo .n{font-size:1.4rem;font-weight:800}.iv__logo .g{color:var(--dim);font-size:.85rem;margin-top:3px}
|
||||||
|
.iv__inv{background:linear-gradient(135deg,rgba(106,208,255,.13),rgba(184,141,255,.13));border:1px solid rgba(106,208,255,.32);border-radius:14px;padding:14px;margin-bottom:6px;text-align:center}
|
||||||
|
.iv__inv .by{font-weight:800;font-size:1.15rem;color:#fff}.iv__inv .s{color:var(--dim);font-size:.85rem;margin-top:2px}
|
||||||
|
.iv label{display:block;font-size:.7rem;color:var(--dim);margin:14px 0 6px;text-transform:uppercase;letter-spacing:.04em}
|
||||||
|
.iv input{width:100%;padding:14px;border-radius:12px;border:1px solid var(--line);background:var(--card);color:var(--ink);font-size:16px;outline:none}
|
||||||
|
.iv input:focus{border-color:var(--acc)}
|
||||||
|
.iv__btn{display:block;width:100%;padding:14px;border-radius:12px;border:none;cursor:pointer;font-size:1rem;font-weight:700;background:linear-gradient(135deg,var(--acc),var(--acc2));color:#08111b;margin-top:12px}
|
||||||
|
.iv__btn:active{filter:brightness(.92)}.iv__btn:disabled{opacity:.5}
|
||||||
|
.iv__btn.sec{background:var(--card);color:var(--ink);border:1px solid var(--line)}
|
||||||
|
.iv__err{color:var(--ko);font-size:.82rem;margin-top:10px;min-height:1em}
|
||||||
|
.iv__muted{color:var(--dim);font-size:.85rem;text-align:center;padding:18px 8px}
|
||||||
|
.iv__divider{display:flex;align-items:center;gap:10px;color:var(--dim);font-size:.7rem;margin:16px 0 4px}
|
||||||
|
.iv__divider::before,.iv__divider::after{content:'';flex:1;height:1px;background:var(--line)}
|
||||||
|
.iv__card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:13px;margin-bottom:10px}
|
||||||
|
.iv__link{display:flex;gap:8px;align-items:center}.iv__link input{font-size:.78rem;padding:10px}
|
||||||
|
.iv__row{display:flex;align-items:center;gap:11px;padding:11px 12px;background:var(--card);border:1px solid var(--line);border-radius:12px;margin-bottom:8px}
|
||||||
|
.iv__av{width:38px;height:38px;flex:0 0 auto;border-radius:11px;display:flex;align-items:center;justify-content:center;font-weight:700;color:#0a0e14;background:linear-gradient(135deg,var(--acc),var(--acc2))}
|
||||||
|
.iv__row .m{flex:1;min-width:0}.iv__row .nm{font-weight:600}.iv__row .mt{font-size:.72rem;color:var(--dim);margin-top:1px}
|
||||||
|
.iv__sec-t{font-size:.7rem;text-transform:uppercase;letter-spacing:.05em;color:var(--dim);margin:18px 0 8px}
|
||||||
|
.iv__toast{position:absolute;left:50%;bottom:22px;transform:translateX(-50%);background:#1a2636;border:1px solid var(--line);color:var(--ink);padding:10px 16px;border-radius:24px;font-size:.84rem;opacity:0;transition:opacity .2s;pointer-events:none;max-width:90%;text-align:center;z-index:30}
|
||||||
|
.iv__toast.on{opacity:1}
|
||||||
|
.iv__spin{display:inline-block;width:14px;height:14px;border:2px solid rgba(255,255,255,.3);border-top-color:#fff;border-radius:50%;animation:iv-sp .7s linear infinite;vertical-align:-2px}
|
||||||
|
@keyframes iv-sp{to{transform:rotate(360deg)}}
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
"use strict";
|
||||||
|
var ID = 'invite';
|
||||||
|
var API = 'https://api.j0bot.ch/api/v1';
|
||||||
|
|
||||||
|
var LIVE = null; // posé au mount : { user, links, friends }
|
||||||
|
function describe() {
|
||||||
|
var user = LIVE ? LIVE.user() : null;
|
||||||
|
if (!user) return { v: 1, id: ID, title: 'Invitations', icon: '✉️', items: [{ p: 1, kind: 'text', label: 'invitations', value: 'connexion requise' }] };
|
||||||
|
var links = LIVE ? LIVE.links() : 0, friends = LIVE ? LIVE.friends() : 0;
|
||||||
|
return { v: 1, id: ID, title: 'Invitations', icon: '✉️', items: [
|
||||||
|
{ p: 1, kind: 'stat', label: 'amis invités', value: friends },
|
||||||
|
{ p: 2, kind: 'stat', label: 'liens actifs', value: links }
|
||||||
|
] };
|
||||||
|
}
|
||||||
|
function mount(container, ctx) {
|
||||||
|
var alive = true;
|
||||||
|
var S = { token: get('jos_social_token'), user: null, code: null, join: null, invite: null };
|
||||||
|
var lastLinks = 0, lastFriends = 0;
|
||||||
|
try { S.user = JSON.parse(get('jos_social_user') || 'null'); } catch (e) {}
|
||||||
|
try { var _u = new URLSearchParams(location.search); S.code = _u.get('code') || null; S.join = _u.get('join') || null; } catch (e) {}
|
||||||
|
|
||||||
|
function get(k){ try { return localStorage.getItem(k) || ''; } catch (e) { return ''; } }
|
||||||
|
function setk(k,v){ try { localStorage.setItem(k, v); } catch (e) {} }
|
||||||
|
function save(){ setk('jos_social_token', S.token || ''); setk('jos_social_user', JSON.stringify(S.user || null)); }
|
||||||
|
function esc(s) { return window.jOSb.esc(s); }
|
||||||
|
function q(s){ return container.querySelector(s); }
|
||||||
|
function show(v){ container.querySelectorAll('.iv__view').forEach(function(e){e.classList.remove('on');}); var el=q('#iv-'+v); if(el) el.classList.add('on'); }
|
||||||
|
function initials(s){ s=(s||'?').trim(); return (s[0]||'?').toUpperCase(); }
|
||||||
|
var tT; function toast(m){ var t=q('#iv-toast'); t.textContent=m; t.classList.add('on'); clearTimeout(tT); tT=setTimeout(function(){ if(alive) t.classList.remove('on'); },2600); }
|
||||||
|
|
||||||
|
container.classList.add('iv');
|
||||||
|
container.innerHTML =
|
||||||
|
// REDEEM (invité)
|
||||||
|
'<section class="iv__view" id="iv-redeem"><div class="iv__bd iv__authbd">'
|
||||||
|
+ '<div class="iv__inv" id="iv-invbox"><div class="by">Tu es invité 🎉</div><div class="s">crée ton compte j0bot pour rejoindre</div></div>'
|
||||||
|
+ '<label>ton pseudo</label><input id="iv-r-name" autocapitalize="none" placeholder="comment on t\'appelle">'
|
||||||
|
+ '<label>mot de passe <span style="text-transform:none">(optionnel, pour garder ton compte)</span></label><input id="iv-r-pass" type="password" placeholder="laisse vide = compte rapide">'
|
||||||
|
+ '<button class="iv__btn" id="iv-r-go">Créer mon compte & rejoindre</button>'
|
||||||
|
+ '<div class="iv__err" id="iv-r-err"></div>'
|
||||||
|
+ '<div class="iv__divider">déjà un compte ?</div><button class="iv__btn sec" id="iv-r-login">Me connecter</button>'
|
||||||
|
+ '</div></section>'
|
||||||
|
// LOGIN (pour devenir inviteur)
|
||||||
|
+ '<section class="iv__view" id="iv-login"><div class="iv__bd iv__authbd">'
|
||||||
|
+ '<div class="iv__logo"><div class="b">✉️</div><div class="n">invitations</div><div class="g">invite tes potes, connecte le monde</div></div>'
|
||||||
|
+ '<label>identifiant ou email</label><input id="iv-login-u" autocapitalize="none" placeholder="ton pseudo j0bot">'
|
||||||
|
+ '<label>mot de passe</label><input id="iv-login-p" type="password" placeholder="••••••••">'
|
||||||
|
+ '<button class="iv__btn" id="iv-login-go">Se connecter</button>'
|
||||||
|
+ '<div class="iv__err" id="iv-login-err"></div>'
|
||||||
|
+ '<div class="iv__muted" style="margin-top:14px">Pas encore de compte ? Il te faut un <b>lien d\'invitation</b> de quelqu\'un.</div>'
|
||||||
|
+ '</div></section>'
|
||||||
|
// HOME (inviteur loggué)
|
||||||
|
+ '<section class="iv__view" id="iv-home"><div class="iv__hd">'
|
||||||
|
+ '<div class="iv__ic" id="iv-me-av" style="width:34px;height:34px;font-size:.9rem">·</div>'
|
||||||
|
+ '<div class="t">invitations<div class="sub" id="iv-me-name"></div></div>'
|
||||||
|
+ '<button class="iv__ic" id="iv-logout" title="déconnexion">⎋</button></div>'
|
||||||
|
+ '<div class="iv__bd">'
|
||||||
|
+ '<div class="iv__card"><div style="font-weight:700;margin-bottom:4px">Inviter quelqu\'un</div>'
|
||||||
|
+ '<div class="iv__muted" style="text-align:left;padding:0 0 10px">Génère un lien. Qui l\'ouvre crée son compte et devient ton ami.</div>'
|
||||||
|
+ '<label style="margin-top:0">label (optionnel)</label><input id="iv-newlabel" placeholder="soirée, contributeurs…">'
|
||||||
|
+ '<button class="iv__btn" id="iv-newlink">🔗 Générer un lien d\'invitation</button></div>'
|
||||||
|
+ '<div id="iv-lastlink"></div>'
|
||||||
|
+ '<div class="iv__sec-t">mes liens</div><div id="iv-links"><div class="iv__muted">…</div></div>'
|
||||||
|
+ '<div class="iv__sec-t">mes amis</div><div id="iv-friends"><div class="iv__muted">…</div></div>'
|
||||||
|
+ '</div></section>'
|
||||||
|
+ '<div class="iv__toast" id="iv-toast"></div>';
|
||||||
|
|
||||||
|
// bandeau « le graphe est local » (mode local seulement) : invitations et amis passent par 👥 Amis
|
||||||
|
try {
|
||||||
|
if (window.jOSSocial && window.jOSSocial.mode && window.jOSSocial.mode() === 'local') {
|
||||||
|
['#iv-home .iv__bd', '#iv-login .iv__bd'].forEach(function(sel){ var bd = container.querySelector(sel); if (!bd) return;
|
||||||
|
var b = document.createElement('div'); b.className = 'iv__inv'; b.style.textAlign = 'left';
|
||||||
|
b.innerHTML = '<div style="font-weight:700">🤝 Tes amis vivent maintenant sur ton boxion</div>'
|
||||||
|
+ '<div class="iv__muted" style="text-align:left;padding:6px 0 8px">Pour inviter un pote : ton <b>QR / code d\'ami</b> dans 👥 Amis. Il scanne, vous êtes amis direct (et il devient zion). Les anciens liens restent valables.</div>'
|
||||||
|
+ '<button class="iv__btn" data-iv-amis>👥 ouvrir Amis</button>';
|
||||||
|
bd.insertBefore(b, bd.firstChild);
|
||||||
|
b.querySelector('[data-iv-amis]').addEventListener('click', function(){ try { if (window.jOS && window.jOS.openPloxion && window.jOS.openPloxion('amis')) return; if (window.jOSMobile && window.jOSMobile.open) window.jOSMobile.open('amis', 'Amis'); } catch (e) {} });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
//==== API ====
|
||||||
|
async function api(method, path, body, _retry){
|
||||||
|
var opts={ method:method, headers:{ 'Accept':'application/json' } };
|
||||||
|
if(body!==undefined){ opts.headers['Content-Type']='application/json'; opts.body=JSON.stringify(body); }
|
||||||
|
if(S.token) opts.headers['Authorization']='Bearer '+S.token;
|
||||||
|
var r=await fetch(API+path, opts);
|
||||||
|
if(r.status===401 && S.token && !_retry){
|
||||||
|
var rr=await fetch(API+'/auth/refresh',{method:'POST',headers:{'Authorization':'Bearer '+S.token,'Accept':'application/json'}});
|
||||||
|
if(rr.ok){ var d=await rr.json(); S.token=d.token; save(); return api(method,path,body,true); }
|
||||||
|
logout(); throw new Error('session expirée');
|
||||||
|
}
|
||||||
|
var data={}; try{ data=await r.json(); }catch(e){}
|
||||||
|
if(!r.ok){ var er=new Error(data.message||data.error||('Erreur '+r.status)); er.status=r.status; throw er; }
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
// Le lien pointe vers /local = la page PUBLIQUE du labo (accessible SANS compte) → un invité
|
||||||
|
// peut l'ouvrir et créer son compte. (location.pathname pourrait être une page gatée.)
|
||||||
|
function inviteLink(code){ return location.origin+'/local?px=invite&code='+code; }
|
||||||
|
|
||||||
|
//==== REDEEM (invité) ====
|
||||||
|
async function loadInvite(){
|
||||||
|
try{ S.invite=await api('GET','/invites/'+encodeURIComponent(S.code)); if(!alive) return;
|
||||||
|
var who=(S.invite.inviter&&S.invite.inviter.username)||'quelqu\'un';
|
||||||
|
q('#iv-invbox').innerHTML='<div class="by">'+esc(who)+' t\'invite 🎉</div><div class="s">'
|
||||||
|
+(S.invite.usable?'crée ton compte j0bot pour rejoindre':'⚠️ ce lien n\'est plus valide')+'</div>';
|
||||||
|
if(!S.invite.usable) q('#iv-r-go').disabled=true;
|
||||||
|
}catch(e){ q('#iv-invbox').innerHTML='<div class="by">Lien invalide</div><div class="s">'+esc(e.message)+'</div>'; q('#iv-r-go').disabled=true; }
|
||||||
|
}
|
||||||
|
async function redeem(){
|
||||||
|
var name=q('#iv-r-name').value.trim(), pass=q('#iv-r-pass').value; q('#iv-r-err').textContent='';
|
||||||
|
if(!name){ q('#iv-r-err').textContent='choisis un pseudo'; return; }
|
||||||
|
var b=q('#iv-r-go'); b.disabled=true; b.innerHTML='<span class="iv__spin"></span>';
|
||||||
|
try{
|
||||||
|
var body={ code:S.code, username:name }; if(pass) body.password=pass;
|
||||||
|
var d=await api('POST','/auth/redeem', body);
|
||||||
|
S.token=d.token; S.user=d.user; save();
|
||||||
|
toast('Compte créé — ami avec ton inviteur ✓');
|
||||||
|
if(S.join){ try{ await api('POST','/spaces/'+encodeURIComponent(S.join)+'/join'); }catch(e){} } // rejoint le space invité
|
||||||
|
setTimeout(function(){ openSocial(); }, 800);
|
||||||
|
}catch(e){ q('#iv-r-err').textContent = e.message; b.disabled=false; b.textContent='Créer mon compte & rejoindre'; }
|
||||||
|
}
|
||||||
|
|
||||||
|
//==== LOGIN ====
|
||||||
|
async function login(){
|
||||||
|
var u=q('#iv-login-u').value.trim(), p=q('#iv-login-p').value; q('#iv-login-err').textContent='';
|
||||||
|
if(!u||!p){ q('#iv-login-err').textContent='identifiant + mot de passe'; return; }
|
||||||
|
var b=q('#iv-login-go'); b.disabled=true; b.innerHTML='<span class="iv__spin"></span>';
|
||||||
|
try{ var d=await api('POST','/auth/login',{login:u,password:p}); S.token=d.token; S.user=d.user; save(); enterHome(); }
|
||||||
|
catch(e){ q('#iv-login-err').textContent = e.status===401?'identifiants invalides':e.message; b.disabled=false; b.textContent='Se connecter'; }
|
||||||
|
}
|
||||||
|
function logout(){ S.token=''; S.user=null; save(); show(S.code?'redeem':'login'); }
|
||||||
|
|
||||||
|
//==== HOME (inviteur) ====
|
||||||
|
async function enterHome(){
|
||||||
|
if(!S.user || !S.user.id){ try{ var d=await api('GET','/me'); S.user=(d&&d.user)||d; save(); }catch(e){} }
|
||||||
|
q('#iv-me-name').textContent='@'+((S.user&&S.user.username)||'moi');
|
||||||
|
q('#iv-me-av').textContent=initials(S.user&&S.user.username);
|
||||||
|
show('home'); loadLinks(); loadFriends();
|
||||||
|
}
|
||||||
|
async function newLink(){
|
||||||
|
var label=q('#iv-newlabel').value.trim(); var b=q('#iv-newlink'); b.disabled=true; b.innerHTML='<span class="iv__spin"></span>';
|
||||||
|
try{ var d=await api('POST','/invites', label?{label:label}:{}); var url=inviteLink(d.code);
|
||||||
|
q('#iv-newlabel').value='';
|
||||||
|
q('#iv-lastlink').innerHTML='<div class="iv__card"><div style="font-weight:700;margin-bottom:6px">🔗 Ton lien'+(d.label?' « '+esc(d.label)+' »':'')+'</div>'
|
||||||
|
+'<div id="iv-lastqr" style="text-align:center;margin:0 0 10px"></div>'
|
||||||
|
+'<div class="iv__link"><input readonly value="'+esc(url)+'"><button class="iv__btn" style="width:auto;margin:0;padding:11px 14px" id="iv-share">Partager</button></div>'
|
||||||
|
+'<div class="iv__muted" style="margin-top:6px">📲 En personne : montre le QR à scanner.</div></div>';
|
||||||
|
if(window.jOSQR){ try{ window.jOSQR(url, q('#iv-lastqr'), 190); }catch(e){} }
|
||||||
|
q('#iv-share').onclick=function(){ doShare(url); };
|
||||||
|
doShare(url); loadLinks();
|
||||||
|
}catch(e){ toast(e.message); }
|
||||||
|
if(alive){ b.disabled=false; b.textContent='🔗 Générer un lien d\'invitation'; }
|
||||||
|
}
|
||||||
|
function doShare(url){ var txt='Rejoins-moi sur j0bot 🎉';
|
||||||
|
if(window.jOSiOS&&window.jOSiOS.share){ window.jOSiOS.share({title:txt,text:txt,url:url}); }
|
||||||
|
else if(navigator.share){ navigator.share({title:txt,text:txt,url:url}).catch(function(){}); }
|
||||||
|
else if(navigator.clipboard){ navigator.clipboard.writeText(url); toast('Lien copié ✓'); }
|
||||||
|
else { prompt('Lien d\'invitation :', url); }
|
||||||
|
}
|
||||||
|
async function loadLinks(){
|
||||||
|
try{ var d=await api('GET','/invites'); if(!alive) return; var L=d.data||[]; lastLinks=L.length;
|
||||||
|
q('#iv-links').innerHTML = L.length ? L.map(function(i){
|
||||||
|
return '<div class="iv__row"><div class="iv__av" style="font-size:1rem">🔗</div><div class="m"><div class="nm">'+esc(i.label||'lien')+'</div>'
|
||||||
|
+'<div class="mt">'+(i.uses||0)+(i.max_uses?('/'+i.max_uses):'')+' utilisé'+((i.uses>1)?'s':'')+' · '+(i.usable?'actif':'épuisé')+'</div></div>'
|
||||||
|
+'<button class="iv__ic" data-c="'+esc(i.code)+'" title="copier">⧉</button></div>';
|
||||||
|
}).join('') : '<div class="iv__muted">Aucun lien encore. Génère le premier ☝️</div>';
|
||||||
|
q('#iv-links').querySelectorAll('[data-c]').forEach(function(b){ b.onclick=function(){ doShare(inviteLink(b.dataset.c)); }; });
|
||||||
|
}catch(e){ if(alive) q('#iv-links').innerHTML='<div class="iv__muted">'+esc(e.message)+'</div>'; }
|
||||||
|
}
|
||||||
|
async function loadFriends(){
|
||||||
|
try{ var d=await api('GET','/friends'); if(!alive) return; var F=d.data||[]; lastFriends=F.length;
|
||||||
|
q('#iv-friends').innerHTML = F.length ? F.map(function(f){
|
||||||
|
return '<div class="iv__row"><div class="iv__av">'+esc(initials(f.username))+'</div><div class="m"><div class="nm">'+esc(f.username||'?')+'</div></div></div>';
|
||||||
|
}).join('') : '<div class="iv__muted">Pas encore d\'amis. Invite quelqu\'un ☝️</div>';
|
||||||
|
}catch(e){ if(alive) q('#iv-friends').innerHTML='<div class="iv__muted">'+esc(e.message)+'</div>'; }
|
||||||
|
}
|
||||||
|
function openSocial(){ try{ if(window.jOSMobile && window.jOSMobile.open('social','le social')) return; if(window.jOS && window.jOS.openPloxion) window.jOS.openPloxion('social'); }catch(e){} }
|
||||||
|
|
||||||
|
//==== wiring ====
|
||||||
|
q('#iv-r-go').onclick=redeem;
|
||||||
|
q('#iv-r-login').onclick=function(){ show('login'); };
|
||||||
|
q('#iv-login-go').onclick=login;
|
||||||
|
q('#iv-login-p').addEventListener('keydown',function(e){ if(e.key==='Enter') login(); });
|
||||||
|
q('#iv-logout').onclick=function(){ if(confirm('Se déconnecter ?')) logout(); };
|
||||||
|
q('#iv-newlink').onclick=newLink;
|
||||||
|
|
||||||
|
//==== démarrage ====
|
||||||
|
if(S.code && !S.token){ show('redeem'); loadInvite(); }
|
||||||
|
else if(S.token){ enterHome(); }
|
||||||
|
else { show('login'); }
|
||||||
|
|
||||||
|
LIVE = { user: function () { return S.user; }, links: function () { return lastLinks; }, friends: function () { return lastFriends; } };
|
||||||
|
return { unmount: function(){ LIVE=null; alive=false; container.classList.remove('iv'); container.innerHTML=''; } };
|
||||||
|
}
|
||||||
|
|
||||||
|
window.jOSApps = window.jOSApps || {};
|
||||||
|
window.jOSApps[ID] = { manifest: { id: ID, name: 'invitations', icon: '✉️' }, mount: mount, describe: describe };
|
||||||
|
|
||||||
|
// deep-link : ?px=invite (lien d'invitation) → auto-ouvre ce ploxion
|
||||||
|
try {
|
||||||
|
if (new URLSearchParams(location.search).get('px') === ID) {
|
||||||
|
var n=0, t=setInterval(function(){
|
||||||
|
if ((window.jOSMobile && window.jOSMobile.open(ID,'invitations')) ||
|
||||||
|
(window.jOS && window.jOS.openPloxion && window.jOS.openPloxion(ID)) || ++n>50) clearInterval(t);
|
||||||
|
}, 150);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user