forked from unimatrix/web
14 lines
2.4 KiB
JavaScript
14 lines
2.4 KiB
JavaScript
import {mountPoliticalDecision} from './cp-v2/cp-v2-political-decisions.mjs';
|
|
const el=(tag,text)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;return n;};
|
|
export function proclamationBox(kind,{editor=false}={}){
|
|
const names={house:'Faction',imperial:'Imperial',guild:'Spacing Guild'},seals={house:'office-house_leader.png',imperial:'emperor-v1.png',guild:'guild-envoy-v1.png'};
|
|
const root=el('article');root.className='politics-card';const art=el('img');art.src='https://www.dunerealms.com/assets/seals/'+seals[kind];art.alt='';art.width=art.height=72;root.append(art,el('h3',names[kind]+(editor?' Message settings':' Proclamations')));const status=el('p');status.role='status';const content=el('div');root.append(status,content);let page=1,version=0;
|
|
async function load(){const serial=++version;try{const response=await fetch('/api/politics/proclamations?kind='+kind+'&page='+page,{cache:'no-store'}),data=await response.json();if(!root.isConnected||serial!==version)return;if(!response.ok)throw Error(data.message||'Messages unavailable.');content.replaceChildren();status.textContent='';
|
|
if(!editor){if(data.post){content.append(el('h4',data.post.title));const body=el('p',data.post.body);body.className='honour-citation';content.append(body,el('small','Issued by '+data.post.author+' · '+new Date(Number(data.post.created_at)).toLocaleString('en-GB',{timeZone:'UTC'})+' GMT'));}else content.append(el('p','No proclamations have been published yet.'));const nav=el('nav');nav.className='politics-pagination';for(const [label,step]of [['Newer',-1],['Older',1]]){const b=el('button',label);b.type='button';b.disabled=step<0?page===1:page>=data.pages;b.onclick=()=>{page+=step;load();};nav.append(b);}nav.append(el('span','Page '+page+' of '+data.pages));content.append(nav);}
|
|
if(editor||kind==='guild'&&data.canPublish){if(!data.canPublish){content.append(el('p','Publishing is reserved for the current '+(kind==='house'?'faction leader':kind==='imperial'?'Emperor':'Guild leader')+'.'));return;}
|
|
if(data.decisionId)mountPoliticalDecision(content,data.decisionId);else content.append(el('p','Funded publication is unavailable for this office.'));}
|
|
|
|
}catch(error){if(serial===version)status.textContent=error.message;}}
|
|
queueMicrotask(load);return root;
|
|
}
|
|
export function renderProclamations(){const root=el('section');root.className='politics-grid council-motds';for(const kind of ['house','imperial','guild'])root.append(proclamationBox(kind));return root;}
|

Staff