activity_view.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. const { div, h2, p, section, button, form, a, input, img, textarea, br, span, video: videoHyperaxe, audio: audioHyperaxe, table, tr, td, th } = require("../server/node_modules/hyperaxe");
  2. const { template, i18n } = require('./main_views');
  3. const moment = require("../server/node_modules/moment");
  4. function capitalize(str) {
  5. return typeof str === 'string' && str.length ? str[0].toUpperCase() + str.slice(1) : '';
  6. }
  7. function renderActionCards(actions) {
  8. const validActions = actions
  9. .filter(action => {
  10. const content = action.value?.content || action.content;
  11. if (!content || typeof content !== 'object') return false;
  12. if (content.type === 'tombstone') return false;
  13. if (content.type === 'post' && content.private === true) return false;
  14. if (content.type === 'tribe' && content.isAnonymous === true) return false;
  15. if (content.type === 'task' && content.isPublic === "PRIVATE") return false;
  16. if (content.type === 'event' && content.isPublic === "private") return false;
  17. if (content.type === 'market') {
  18. if (content.stock === 0 && content.status !== 'SOLD') {
  19. return false;
  20. }
  21. }
  22. return true;
  23. })
  24. .sort((a, b) => b.ts - a.ts);
  25. if (!validActions.length) {
  26. return div({ class: "no-actions" }, p(i18n.noActions));
  27. }
  28. return validActions.map(action => {
  29. const date = action.ts ? new Date(action.ts).toLocaleString() : "";
  30. const userLink = action.author
  31. ? a({ href: `/author/${encodeURIComponent(action.author)}` }, action.author)
  32. : 'unknown';
  33. const type = action.type || 'unknown';
  34. const typeLabel = i18n[`type${capitalize(type)}`] || type;
  35. const content = action.content || {};
  36. const cardBody = [];
  37. if (type === 'votes') {
  38. const { question, deadline, status, votes, totalVotes } = content;
  39. const votesList = votes && typeof votes === 'object'
  40. ? Object.entries(votes).map(([option, count]) => ({ option, count }))
  41. : [];
  42. cardBody.push(
  43. div({ class: 'card-section votes' },
  44. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.question + ':'), span({ class: 'card-value' }, question)),
  45. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.deadline + ':'), span({ class: 'card-value' }, deadline ? new Date(deadline).toLocaleString() : '')),
  46. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.voteTotalVotes + ':'), span({ class: 'card-value' }, totalVotes)),
  47. table(
  48. tr(...votesList.map(({ option }) => th(i18n[option] || option))),
  49. tr(...votesList.map(({ count }) => td(count)))
  50. )
  51. )
  52. );
  53. }
  54. if (type === 'transfer') {
  55. const { from, to, concept, amount, deadline, status, confirmedBy } = content;
  56. cardBody.push(
  57. div({ class: 'card-section transfer' },
  58. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.concept + ':'), span({ class: 'card-value' }, concept)),
  59. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.deadline + ':'), span({ class: 'card-value' }, deadline ? new Date(deadline).toLocaleString() : '')),
  60. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.status + ':'), span({ class: 'card-value' }, status)),
  61. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.amount + ':'), span({ class: 'card-value' }, amount)),
  62. br,
  63. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.from + ': '), a({ class: 'user-link', href: `/author/${encodeURIComponent(from)}`, target: "_blank" }, from)),
  64. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.to + ': '), a({ class: 'user-link', href: `/author/${encodeURIComponent(to)}`, target: "_blank" }, to)),
  65. div({ class: 'card-field' }, h2({ class: 'card-label' }, i18n.transfersConfirmations + ': ' + `${confirmedBy.length}/2`)),
  66. )
  67. );
  68. }
  69. if (type === 'pixelia') {
  70. const { author } = content;
  71. cardBody.push(
  72. div({ class: 'card-section pixelia' },
  73. div({ class: 'card-field' },
  74. a({ href: `/author/${encodeURIComponent(author)}`, class: 'activityVotePost' }, author)
  75. )
  76. )
  77. );
  78. }
  79. if (type === 'tribe') {
  80. const { title, image, description, tags, isLARP, inviteMode, isAnonymous, members } = content;
  81. const validTags = Array.isArray(tags) ? tags : [];
  82. cardBody.push(
  83. div({ class: 'card-section tribe' },
  84. h2({ class: 'tribe-title' },
  85. a({ href: `/tribe/${encodeURIComponent(action.id)}`, class: "user-link" }, title)
  86. ),
  87. p({ class: 'tribe-description' }, description || ''),
  88. image
  89. ? img({ src: `/blob/${encodeURIComponent(image)}`, class: 'feed-image tribe-image' })
  90. : img({ src: '/assets/images/default-tribe.png', class: 'feed-image tribe-image' }),
  91. br(),
  92. typeof isAnonymous === 'boolean' ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.tribeIsAnonymousLabel+ ':'), span({ class: 'card-value' }, isAnonymous ? i18n.tribePrivate : i18n.tribePublic)) : "",
  93. inviteMode ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.tribeModeLabel) + ':'), span({ class: 'card-value' }, inviteMode.toUpperCase())) : "",
  94. typeof isLARP === 'boolean' ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.tribeLARPLabel+ ':'), span({ class: 'card-value' }, isLARP ? i18n.tribeYes : i18n.tribeNo)) : "",
  95. Array.isArray(members) ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.tribeMembersCount) + ':'), span({ class: 'card-value' }, members.length)) : "",
  96. validTags.length
  97. ? div({ class: 'card-tags' }, validTags.map(tag =>
  98. a({ href: `/search?query=%23${encodeURIComponent(tag)}`, class: "tag-link" }, `#${tag}`)))
  99. : ""
  100. )
  101. );
  102. }
  103. if (type === 'curriculum') {
  104. const { author, name, description, photo, personalSkills, oasisSkills, educationalSkills, languages, professionalSkills, status, preferences} = content;
  105. cardBody.push(
  106. div({ class: 'card-section curriculum' },
  107. h2(a({ href: `/author/${encodeURIComponent(author)}`, class: "user-link" }, `@`, name)),
  108. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.cvStatusLabel + ':'), span({ class: 'card-value' }, status)) : "",
  109. preferences ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.cvPreferencesLabel || 'Preferences') + ':'), span({ class: 'card-value' }, preferences)) : "",
  110. languages ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.cvLanguagesLabel || 'Languages') + ':'), span({ class: 'card-value' }, languages)) : "",
  111. br(),
  112. photo ? img({ class: "cv-photo", src: `/blob/${encodeURIComponent(photo)}` }) : "",
  113. br(),
  114. description ? div({ class: 'card-field' }, span({ class: 'card-value' }, description)) : "",
  115. br(),
  116. personalSkills && personalSkills.length
  117. ? div({ class: 'card-tags' }, personalSkills.map(skill =>
  118. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: "tag-link" }, `#${skill}`)
  119. )) : "",
  120. oasisSkills && oasisSkills.length
  121. ? div({ class: 'card-tags' }, oasisSkills.map(skill =>
  122. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: "tag-link" }, `#${skill}`)
  123. )) : "",
  124. educationalSkills && educationalSkills.length
  125. ? div({ class: 'card-tags' }, educationalSkills.map(skill =>
  126. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: "tag-link" }, `#${skill}`)
  127. )) : "",
  128. professionalSkills && professionalSkills.length
  129. ? div({ class: 'card-tags' }, professionalSkills.map(skill =>
  130. a({ href: `/search?query=%23${encodeURIComponent(skill)}`, class: "tag-link" }, `#${skill}`)
  131. )) : "",
  132. )
  133. );
  134. }
  135. if (type === 'image') {
  136. const { url } = content;
  137. cardBody.push(
  138. div({ class: 'card-section image' },
  139. img({ src: `/blob/${encodeURIComponent(url)}`, class: 'feed-image img-content' })
  140. )
  141. );
  142. }
  143. if (content.type === 'audio') {
  144. const { url, mimeType, title } = content;
  145. cardBody.push(
  146. div({ class: 'card-section audio' },
  147. title?.trim() ? h2({ class: 'audio-title' }, title) : "",
  148. url
  149. ? div({ class: "audio-container" },
  150. audioHyperaxe({
  151. controls: true,
  152. src: `/blob/${encodeURIComponent(url)}`,
  153. type: mimeType
  154. })
  155. )
  156. : p(i18n.audioNoFile),
  157. )
  158. );
  159. }
  160. if (content.type === 'video') {
  161. const { url, mimeType, title } = content;
  162. cardBody.push(
  163. div({ class: 'card-section video' },
  164. title?.trim() ? h2({ class: 'video-title' }, title) : "",
  165. url
  166. ? div({ class: "video-container" },
  167. videoHyperaxe({
  168. controls: true,
  169. src: `/blob/${encodeURIComponent(url)}`,
  170. type: mimeType,
  171. preload: 'metadata',
  172. width: '640',
  173. height: '360'
  174. })
  175. )
  176. : p(i18n.videoNoFile)
  177. )
  178. );
  179. }
  180. if (content.type === 'document') {
  181. const { url, title, key } = content;
  182. cardBody.push(
  183. div({ class: 'card-section document' },
  184. title?.trim() ? h2({ class: 'document-title' }, title) : "",
  185. div({
  186. id: `pdf-container-${key || url}`,
  187. class: 'pdf-viewer-container',
  188. 'data-pdf-url': `/blob/${encodeURIComponent(url)}`
  189. })
  190. )
  191. );
  192. }
  193. if (type === 'bookmark') {
  194. const { url, description, lastVisit } = content;
  195. cardBody.push(
  196. div({ class: 'card-section bookmark' },
  197. description ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.bookmarkDescriptionLabel + ':'), span({ class: 'card-value' }, description)) : "",
  198. h2(url ? p(a({ href: url, target: '_blank', class: "bookmark-url" }, url)) : ""),
  199. lastVisit ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.bookmarkLastVisit + ':'), span({ class: 'card-value' }, new Date(lastVisit).toLocaleString())) : ""
  200. )
  201. );
  202. }
  203. if (type === 'event') {
  204. const { title, description, date, location, price, url: eventUrl, attendees, organizer, status, isPublic } = content;
  205. cardBody.push(
  206. div({ class: 'card-section event' },
  207. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, title)),
  208. description ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.description + ':'), span({ class: 'card-value' }, description)) : "",
  209. date ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.date + ':'), span({ class: 'card-value' }, new Date(date).toLocaleString())) : "",
  210. location ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.location || 'Location') + ':'), span({ class: 'card-value' }, location)) : "",
  211. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.status + ':'), span({ class: 'card-value' }, status)) : "",
  212. typeof isPublic === 'boolean' ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.isPublic || 'Public') + ':'), span({ class: 'card-value' }, isPublic ? 'Yes' : 'No')) : "",
  213. price ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.price || 'Price') + ':'), span({ class: 'card-value' }, price + " ECO")) : "",
  214. eventUrl ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.trendingUrl + ':'), a({ href: eventUrl, target: '_blank' }, eventUrl)) : "",
  215. br,
  216. organizer ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.organizer || 'Organizer') + ': '), a({ class: "user-link", href: `/author/${encodeURIComponent(organizer)}` }, organizer)) : "",
  217. Array.isArray(attendees) ? h2({ class: 'card-label' }, (i18n.attendees || 'Attendees') + ': ' + attendees.length) : "",
  218. )
  219. );
  220. }
  221. if (type === 'task') {
  222. const { title, startTime, endTime, priority, status, author } = content;
  223. cardBody.push(
  224. div({ class: 'card-section task' },
  225. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, title)),
  226. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.status + ':'), span({ class: 'card-value' }, status)) : "",
  227. priority ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.priority || 'Priority') + ':'), span({ class: 'card-value' }, priority)) : "",
  228. startTime ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.taskStartTimeLabel || 'Start') + ':'), span({ class: 'card-value' }, new Date(startTime).toLocaleString())) : "",
  229. endTime ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.taskEndTimeLabel || 'End') + ':'), span({ class: 'card-value' }, new Date(endTime).toLocaleString())) : "",
  230. )
  231. );
  232. }
  233. if (type === 'feed') {
  234. const { text, refeeds } = content;
  235. cardBody.push(
  236. div({ class: 'card-section feed' },
  237. h2({ class: 'feed-title' }, text),
  238. h2({ class: 'card-field' }, span({ class: 'card-label' }, i18n.tribeFeedRefeeds + ': '), span({ class: 'card-label' }, refeeds))
  239. )
  240. );
  241. }
  242. if (type === 'post') {
  243. const { contentWarning, text } = content;
  244. cardBody.push(
  245. div({ class: 'card-section post' },
  246. contentWarning ? h2({ class: 'content-warning' }, contentWarning) : '',
  247. p({ innerHTML: text })
  248. )
  249. );
  250. }
  251. if (type === 'vote') {
  252. const { vote } = content;
  253. cardBody.push(
  254. div({ class: 'card-section vote' },
  255. p(
  256. a({ href: `/thread/${encodeURIComponent(vote.link)}#${encodeURIComponent(vote.link)}`, class: 'activityVotePost' }, vote.link)
  257. )
  258. )
  259. );
  260. }
  261. if (type === 'about') {
  262. const { about, name, description, image } = content;
  263. cardBody.push(
  264. div({ class: 'card-section about' },
  265. h2(a({ href: `/author/${encodeURIComponent(about)}`, class: "user-link" }, `@`, name)),
  266. image
  267. ? img({ src: `/blob/${encodeURIComponent(image)}` })
  268. : img({ src: '/assets/images/default-avatar.png', alt: name })
  269. )
  270. );
  271. }
  272. if (type === 'contact') {
  273. const { contact } = content;
  274. cardBody.push(
  275. div({ class: 'card-section contact' },
  276. p({ class: 'card-field' },
  277. a({ href: `/author/${encodeURIComponent(contact)}`, class: 'activitySpreadInhabitant2' }, contact)
  278. )
  279. )
  280. );
  281. }
  282. if (type === 'pub') {
  283. const { address } = content;
  284. const { host, key } = address;
  285. cardBody.push(
  286. div({ class: 'card-section pub' },
  287. p({ class: 'card-field' },
  288. a({ href: `/author/${encodeURIComponent(key)}`, class: 'activitySpreadInhabitant2' }, key)
  289. )
  290. )
  291. );
  292. }
  293. if (type === 'market') {
  294. const { item_type, title, price, status, deadline, stock, image, auctions_poll } = content;
  295. cardBody.push(
  296. div({ class: 'card-section market' },
  297. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemTitle + ':'), span({ class: 'card-value' }, title)),
  298. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemType + ':'), span({ class: 'card-value' }, item_type.toUpperCase())),
  299. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemStatus + ": " ), span({ class: 'card-value' }, status.toUpperCase())),
  300. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.marketItemStock + ':'), span({ class: 'card-value' }, stock)),
  301. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.deadline + ':'), span({ class: 'card-value' }, deadline ? new Date(deadline).toLocaleString() : "")),
  302. br,
  303. image
  304. ? img({ src: `/blob/${encodeURIComponent(image)}` })
  305. : img({ src: '/assets/images/default-market.png', alt: title }),
  306. br,
  307. div({ class: "market-card price" },
  308. p(`${i18n.marketItemPrice}: ${price} ECO`)
  309. ),
  310. item_type === 'auction' && status !== 'SOLD' && status !== 'DISCARDED'
  311. ? div({ class: "auction-info" },
  312. auctions_poll && auctions_poll.length > 0
  313. ? [
  314. p({ class: "auction-bid-text" }, i18n.marketAuctionBids),
  315. table({ class: 'auction-bid-table' },
  316. tr(
  317. th(i18n.marketAuctionBidTime),
  318. th(i18n.marketAuctionUser),
  319. th(i18n.marketAuctionBidAmount)
  320. ),
  321. ...auctions_poll.map(bid => {
  322. const [userId, bidAmount, bidTime] = bid.split(':');
  323. return tr(
  324. td(moment(bidTime).format('YYYY-MM-DD HH:mm:ss')),
  325. td(a({ href: `/author/${encodeURIComponent(userId)}` }, userId)),
  326. td(`${parseFloat(bidAmount).toFixed(6)} ECO`)
  327. );
  328. })
  329. )
  330. ]
  331. : p(i18n.marketNoBids),
  332. form({ method: "POST", action: `/market/bid/${encodeURIComponent(action.id)}` },
  333. input({ type: "number", name: "bidAmount", step: "0.000001", min: "0.000001", placeholder: i18n.marketYourBid, required: true }),
  334. br(),
  335. button({ class: "buy-btn", type: "submit" }, i18n.marketPlaceBidButton)
  336. )
  337. ) : "",
  338. item_type === 'exchange' && status !== 'SOLD' && status !== 'DISCARDED'
  339. ? form({ method: "POST", action: `/market/buy/${encodeURIComponent(action.id)}` },
  340. button({ class: "buy-btn", type: "submit" }, i18n.marketActionsBuy)
  341. ) : ""
  342. )
  343. );
  344. }
  345. if (type === 'report') {
  346. const { title, confirmations, severity, status } = content;
  347. cardBody.push(
  348. div({ class: 'card-section report' },
  349. div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.title + ':'), span({ class: 'card-value' }, title)),
  350. status ? div({ class: 'card-field' }, span({ class: 'card-label' }, i18n.status + ':'), span({ class: 'card-value' }, status)) : "",
  351. severity ? div({ class: 'card-field' }, span({ class: 'card-label' }, (i18n.severity || 'Severity') + ':'), span({ class: 'card-value' }, severity.toUpperCase())) : "",
  352. Array.isArray(confirmations) ? h2({ class: 'card-label' }, (i18n.transfersConfirmations) + ': ' + confirmations.length) : "",
  353. )
  354. );
  355. }
  356. return div({ class: 'card card-rpg' },
  357. div({ class: 'card-header' },
  358. h2({ class: 'card-label' }, `[${typeLabel}]`),
  359. type !== 'feed' ? form({ method: "GET", action: getViewDetailsAction(type, action) },
  360. button({ type: "submit", class: "filter-btn" }, i18n.viewDetails)
  361. ) : ''
  362. ),
  363. div({ class: 'card-body' }, ...cardBody),
  364. p({ class: 'card-footer' },
  365. span({ class: 'date-link' }, `${date} ${i18n.performed} `),
  366. a({ href: `/author/${encodeURIComponent(action.author)}`, class: 'user-link' }, `${action.author}`)
  367. )
  368. );
  369. });
  370. }
  371. function getViewDetailsAction(type, action) {
  372. switch (type) {
  373. case 'votes': return `/votes/${encodeURIComponent(action.id)}`;
  374. case 'transfer': return `/transfers/${encodeURIComponent(action.id)}`;
  375. case 'pixelia': return `/pixelia`;
  376. case 'tribe': return `/tribe/${encodeURIComponent(action.id)}`;
  377. case 'curriculum': return `/inhabitant/${encodeURIComponent(action.author)}`;
  378. case 'image': return `/images/${encodeURIComponent(action.id)}`;
  379. case 'audio': return `/audios/${encodeURIComponent(action.id)}`;
  380. case 'video': return `/videos/${encodeURIComponent(action.id)}`;
  381. case 'document': return `/documents/${encodeURIComponent(action.id)}`;
  382. case 'bookmark': return `/bookmarks/${encodeURIComponent(action.id)}`;
  383. case 'event': return `/events/${encodeURIComponent(action.id)}`;
  384. case 'task': return `/tasks/${encodeURIComponent(action.id)}`;
  385. case 'about': return `/author/${encodeURIComponent(action.author)}`;
  386. case 'post': return `/thread/${encodeURIComponent(action.id)}#${encodeURIComponent(action.id)}`;
  387. case 'vote': return `/thread/${encodeURIComponent(action.content.vote.link)}#${encodeURIComponent(action.content.vote.link)}`;
  388. case 'contact': return `/inhabitants`;
  389. case 'pub': return `/invites`;
  390. case 'market': return `/market/${encodeURIComponent(action.id)}`;
  391. case 'report': return `/reports/${encodeURIComponent(action.id)}`;
  392. }
  393. }
  394. exports.activityView = (actions, filter, userId) => {
  395. const title = filter === 'mine' ? i18n.yourActivity : i18n.globalActivity;
  396. const desc = i18n.activityDesc;
  397. const activityTypes = [
  398. { type: 'recent', label: i18n.typeRecent },
  399. { type: 'all', label: i18n.allButton },
  400. { type: 'mine', label: i18n.mineButton },
  401. { type: 'votes', label: i18n.typeVotes },
  402. { type: 'event', label: i18n.typeEvent },
  403. { type: 'task', label: i18n.typeTask },
  404. { type: 'report', label: i18n.typeReport },
  405. { type: 'tribe', label: i18n.typeTribe },
  406. { type: 'about', label: i18n.typeAbout },
  407. { type: 'curriculum', label: i18n.typeCurriculum },
  408. { type: 'market', label: i18n.typeMarket },
  409. { type: 'transfer', label: i18n.typeTransfer },
  410. { type: 'feed', label: i18n.typeFeed },
  411. { type: 'post', label: i18n.typePost },
  412. { type: 'pixelia', label: i18n.typePixelia },
  413. { type: 'bookmark', label: i18n.typeBookmark },
  414. { type: 'image', label: i18n.typeImage },
  415. { type: 'video', label: i18n.typeVideo },
  416. { type: 'audio', label: i18n.typeAudio },
  417. { type: 'document', label: i18n.typeDocument }
  418. ];
  419. let filteredActions;
  420. if (filter === 'mine') {
  421. filteredActions = actions.filter(action => actions.author === userId && action.type !== 'tombstone');
  422. } else if (filter === 'recent') {
  423. const now = Date.now();
  424. filteredActions = actions.filter(action =>
  425. action.type !== 'tombstone' && action.ts && now - action.ts < 24 * 60 * 60 * 1000
  426. );
  427. } else {
  428. filteredActions = actions.filter(action => (action.type === filter || filter === 'all') && action.type !== 'tombstone');
  429. }
  430. let html = template(
  431. title,
  432. section(
  433. div({ class: 'tags-header' },
  434. h2(i18n.activityList),
  435. p(desc)
  436. ),
  437. form({ method: 'GET', action: '/activity' },
  438. div({ class: 'mode-buttons', style: 'display:grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 24px;' },
  439. div({
  440. style: 'display: flex; flex-direction: column; gap: 8px;'
  441. },
  442. activityTypes.slice(0, 3).map(({ type, label }) =>
  443. form({ method: 'GET', action: '/activity' },
  444. input({ type: 'hidden', name: 'filter', value: type }),
  445. button({ type: 'submit', class: filter === type ? 'filter-btn active' : 'filter-btn' }, label)
  446. )
  447. )
  448. ),
  449. div({
  450. style: 'display: flex; flex-direction: column; gap: 8px;'
  451. },
  452. activityTypes.slice(3, 7).map(({ type, label }) =>
  453. form({ method: 'GET', action: '/activity' },
  454. input({ type: 'hidden', name: 'filter', value: type }),
  455. button({ type: 'submit', class: filter === type ? 'filter-btn active' : 'filter-btn' }, label)
  456. )
  457. )
  458. ),
  459. div({
  460. style: 'display: flex; flex-direction: column; gap: 8px;'
  461. },
  462. activityTypes.slice(7, 11).map(({ type, label }) =>
  463. form({ method: 'GET', action: '/activity' },
  464. input({ type: 'hidden', name: 'filter', value: type }),
  465. button({ type: 'submit', class: filter === type ? 'filter-btn active' : 'filter-btn' }, label)
  466. )
  467. )
  468. ),
  469. div({
  470. style: 'display: flex; flex-direction: column; gap: 8px;'
  471. },
  472. activityTypes.slice(11, 15).map(({ type, label }) =>
  473. form({ method: 'GET', action: '/activity' },
  474. input({ type: 'hidden', name: 'filter', value: type }),
  475. button({ type: 'submit', class: filter === type ? 'filter-btn active' : 'filter-btn' }, label)
  476. )
  477. )
  478. ),
  479. div({
  480. style: 'display: flex; flex-direction: column; gap: 8px;'
  481. },
  482. activityTypes.slice(15, 20).map(({ type, label }) =>
  483. form({ method: 'GET', action: '/activity' },
  484. input({ type: 'hidden', name: 'filter', value: type }),
  485. button({ type: 'submit', class: filter === type ? 'filter-btn active' : 'filter-btn' }, label)
  486. )
  487. )
  488. )
  489. )
  490. ),
  491. section({ class: 'feed-container' }, renderActionCards(filteredActions))
  492. )
  493. );
  494. const hasDocument = actions.some(a => a && a.type === 'document');
  495. if (hasDocument) {
  496. html += `
  497. <script type="module" src="/js/pdf.min.mjs"></script>
  498. <script src="/js/pdf-viewer.js"></script>
  499. `;
  500. }
  501. return html;
  502. };