Skip to content

Node.js based forum software built for the modern web

fix: show supported intents in modal

Julian Lam5288f7731f08
diff --git a/public/src/modules/intents.js b/public/src/modules/intents.js
index 81d68f8a2c..75a8ed713b 100644
--- a/public/src/modules/intents.js
+++ b/public/src/modules/intents.js
@@ -6,6 +6,18 @@ import * as alerts from './alerts';
const STORAGE_KEY = 'ap:intents:handles';
+const INTENT_DISPLAY_MAP = {
+ create: 'Create & Reply',
+ like: 'Upvote',
+ dislike: 'Downvote',
+ follow: 'Follow',
+ object: 'View',
+};
+
+function mapIntentNames(intents) {
+ return intents.map(intent => INTENT_DISPLAY_MAP[intent.toLowerCase()] || intent);
+}
+
export function list() {
let raw;
try {
@@ -79,7 +91,10 @@ export async function refresh(handle) {
export function register() {
let map = list();
- let handles = Array.from(map.entries()).map(([handle, intents]) => ({ handle, intents }));
+ let handles = Array.from(map.entries()).map(([handle, intents]) => ({
+ handle,
+ intents: mapIntentNames(intents).join(', '),
+ }));
app.parseAndTranslate('modals/intents/register', {
description: '[[intents:description]]',
@@ -116,7 +131,10 @@ export function register() {
try {
await refresh(handle);
map = list();
- handles = Array.from(map.entries()).map(([handle, intents]) => ({ handle, intents }));
+ handles = Array.from(map.entries()).map(([handle, intents]) => ({
+ handle,
+ intents: mapIntentNames(intents).join(', '),
+ }));
const html = await app.parseAndTranslate('modals/intents/register', 'handles', { handles });
modal.find('#intents-registered-list').html(html);
} catch (e) {
diff --git a/src/views/modals/intents/register.tpl b/src/views/modals/intents/register.tpl
index d4cc1d0c2f..453f2f0db3 100644
--- a/src/views/modals/intents/register.tpl
+++ b/src/views/modals/intents/register.tpl
@@ -24,7 +24,10 @@
<ul class="list-group list-group-flush" id="intents-registered-list">
{{{ each handles }}}
<li class="list-group-item d-flex justify-content-between align-items-center">
- <span>{./handle}</span>
+ <div>
+ <strong>{./handle}</strong>
+ {{{ if ./intents }}}<small class="text-muted ms-2">({./intents})</small>{{{ end }}}
+ </div>
<button type="button" class="btn btn-sm btn-outline-danger" data-action="remove" data-handle="{./handle}">
<i class="fa fa-times"></i>
</button>