web/website/node/public/clan-public.js

15 lines
2.1 KiB
JavaScript

import {createOrganisationNetwork} from '/organisation-network.mjs';
if(/^\/(companies|political-houses)(?:\/|$)/.test(location.pathname)){await import('/organisation-public.js');}else{
const {createDynastyTree,createDeedCard}=await import('/clan-dynasty.js');
const {formatDuneDate}=await import('/dune-date.js');
const el=(tag,text,cls)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;if(cls)n.className=cls;return n;};
const host=document.getElementById('clan-profile'),status=document.getElementById('clan-status');
try{
const tag=location.pathname.split('/').filter(Boolean)[1];if(!/^[a-z0-9]{2,6}$/i.test(tag||''))throw Error('Clan not found.');
const response=await fetch('/api/public/clans/'+encodeURIComponent(tag),{cache:'no-store',credentials:'omit'}),data=await response.json();if(!response.ok)throw Error(data.message||'Clan could not be loaded.');
document.title=data.clan.name+' · Clan Register | DuneRealms';
host.append(createDynastyTree({...data,placeholders:true}));if(data.network)host.append(createOrganisationNetwork(data.network));const about=el('section',undefined,'public-clan-about');about.append(el('small','THE HOUSE & ITS PEOPLE'),el('h2','['+data.clan.tag+'] · '+data.clan.name),el('p',data.clan.description||'No introduction has been published.'),el('p',data.clan.memberCount+' members · Est. '+formatDuneDate(data.clan.createdAt)));host.append(about,createDeedCard({...data,established:formatDuneDate(data.clan.createdAt)}));
const members=el('section',undefined,'public-clan-about'),grid=el('div',undefined,'public-clan-members');members.append(el('h2','Members'));for(const member of data.members||[]){const card=el('a',undefined,'public-clan-member'),face=el('img');card.href='/people/'+encodeURIComponent(member.username);face.src='https://cp.dunerealms.com/api/avatars/face/roster/'+encodeURIComponent(member.username);face.alt='';face.width=face.height=48;face.loading='lazy';card.append(face,el('strong',member.username),el('small',member.title));grid.append(card);}members.append(grid);host.append(members);status.hidden=true;
}catch(error){status.textContent=error.message;host.replaceChildren();}
}