You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
|
|
import {nip19} from 'nostr-tools';
|
|
import {elem} from './utils/dom';
|
|
|
|
export type DOMMap = {
|
|
[id: string]: HTMLElement
|
|
};
|
|
|
|
export type ViewTemplateOptions = {
|
|
type: 'feed'
|
|
} | {
|
|
type: 'note';
|
|
id: string;
|
|
} | {
|
|
type: 'profile';
|
|
id: string;
|
|
} | {
|
|
type: 'event';
|
|
id: string;
|
|
};
|
|
|
|
export const renderViewTemplate = (options: ViewTemplateOptions) => {
|
|
const content = elem('div', {className: 'content'});
|
|
const dom: DOMMap = {};
|
|
switch (options.type) {
|
|
case 'profile':
|
|
const pubkey = options.id;
|
|
const detail = elem('p', {data: {'profileDetails': pubkey}});
|
|
dom[`detail-${pubkey}`] = detail;
|
|
const header = elem('header', {className: 'hero'}, [
|
|
elem('small', {}, nip19.npubEncode(pubkey)),
|
|
elem('h1', {}, pubkey),
|
|
detail,
|
|
elem('footer', {}, [
|
|
elem('span', {data:{following: pubkey}})
|
|
])
|
|
]);
|
|
dom[pubkey] = header;
|
|
content.append(header);
|
|
document.title = pubkey;
|
|
break;
|
|
case 'note':
|
|
break;
|
|
case 'feed':
|
|
break;
|
|
case 'event':
|
|
const id = options.id;
|
|
const eventHeader = elem('header', {className: 'hero'}, [
|
|
elem('h1', {}, id),
|
|
]);
|
|
dom[id] = eventHeader;
|
|
content.append(eventHeader);
|
|
document.title = id;
|
|
break;
|
|
}
|
|
const view = elem('section', {className: 'view'}, [content]);
|
|
return {content, dom, view};
|
|
}; |