From 844fe7adf083eb126d84d987cf06f1fa9f0692f6 Mon Sep 17 00:00:00 2001 From: Ricardo Arturo Cabral Mejia Date: Sun, 30 Jan 2022 02:09:08 +0000 Subject: [PATCH 1/7] chore: install tributejs --- package.json | 1 + yarn.lock | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/package.json b/package.json index d5a6e89..982b1a1 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "relative-date": "^1.1.3", "stream": "^0.0.2", "tailwindcss": "^3.0.1", + "tributejs": "^5.1.3", "vuex": "^4.0.1" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index dc9c763..2505b26 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6631,6 +6631,11 @@ totalist@^1.0.0: resolved "https://registry.yarnpkg.com/totalist/-/totalist-1.1.0.tgz#a4d65a3e546517701e3e5c37a47a70ac97fe56df" integrity sha512-gduQwd1rOdDMGxFG1gEvhV88Oirdo2p+KjoYFU7k2g+i7n6AFFbDQ5kMPUsW0pNbfQsB/cwXvT1i4Bue0s9g5g== +tributejs@^5.1.3: + version "5.1.3" + resolved "https://registry.yarnpkg.com/tributejs/-/tributejs-5.1.3.tgz#980600fc72865be5868893078b4bfde721129eae" + integrity sha512-B5CXihaVzXw+1UHhNFyAwUTMDk1EfoLP5Tj1VhD9yybZ1I8DZJEv8tZ1l0RJo0t0tk9ZhR8eG5tEsaCvRigmdQ== + trim-left-x@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/trim-left-x/-/trim-left-x-3.0.0.tgz#356cf055896726b9754425e841398842e90b4cdf" From e6f5ada1142a067cd0a94e5bbd62d8c7b86f857f Mon Sep 17 00:00:00 2001 From: Ricardo Arturo Cabral Mejia Date: Sun, 30 Jan 2022 02:09:24 +0000 Subject: [PATCH 2/7] chore: add tributejs css to bundle --- quasar.conf.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/quasar.conf.js b/quasar.conf.js index 5256fab..226fd8a 100644 --- a/quasar.conf.js +++ b/quasar.conf.js @@ -27,7 +27,11 @@ module.exports = configure(function (ctx) { boot: ['global-components'], // https://quasar.dev/quasar-cli/quasar-conf-js#Property%3A-css - css: ['add-tailwind.css', '../../node_modules/highlight.js/styles/base16/solarized-light.css'], + css: [ + 'add-tailwind.css', + '../../node_modules/highlight.js/styles/base16/solarized-light.css', + '../../node_modules/tributejs/tribute.css' + ], // https://github.com/quasarframework/quasar/tree/dev/extras extras: [ From 885fc2acf452cbafc5f44e9796c4fde61a07f731 Mon Sep 17 00:00:00 2001 From: Ricardo Arturo Cabral Mejia Date: Sun, 30 Jan 2022 02:10:29 +0000 Subject: [PATCH 3/7] chore: move shorten to helpers --- src/utils/helpers.js | 4 ++++ src/utils/mixin.js | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utils/helpers.js b/src/utils/helpers.js index 1de9b0b..f039250 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -1,3 +1,7 @@ +export function shorten(str) { + return str ? str.slice(0, 3) + '…' + str.slice(-4) : '' +} + export function getElementFullHeight(element) { let styles = window.getComputedStyle(element) let margin = diff --git a/src/utils/mixin.js b/src/utils/mixin.js index ceca9b1..7dbb4fa 100644 --- a/src/utils/mixin.js +++ b/src/utils/mixin.js @@ -1,5 +1,6 @@ import relative from 'relative-date' import {date} from 'quasar' +import {shorten} from './helpers' export default { methods: { @@ -19,9 +20,7 @@ export default { this.$router.push('/event/' + id) }, - shorten(str) { - return str ? str.slice(0, 3) + '…' + str.slice(-4) : '' - }, + shorten, niceDate(value) { if (value + 60 * 60 /* an hour */ > Date.now() / 1000) { From 1549959f0a479357c8b676576ecd4fa2f78e7cb3 Mon Sep 17 00:00:00 2001 From: Ricardo Arturo Cabral Mejia Date: Sun, 30 Jan 2022 02:11:12 +0000 Subject: [PATCH 4/7] chore: remove useless code --- src/utils/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/helpers.js b/src/utils/helpers.js index f039250..5827c40 100644 --- a/src/utils/helpers.js +++ b/src/utils/helpers.js @@ -58,7 +58,7 @@ export function processMentions(event) { match => match.groups.p ) - const tags = Array.from(new Set(matches).values()).reduce( + const tags = matches.reduce( (tags, pubkey) => tags.find(([t, v]) => t === 'p' && v === pubkey) ? tags From 8df90b1fc2f4cffc82f91df1a5bcb36ab78f23cc Mon Sep 17 00:00:00 2001 From: Ricardo Arturo Cabral Mejia Date: Sun, 30 Jan 2022 02:11:46 +0000 Subject: [PATCH 5/7] feat: add namedProfiles getter --- src/store/getters.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/store/getters.js b/src/store/getters.js index 2a755c2..8eeabaf 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -1,5 +1,14 @@ import Identicon from 'identicon.js' +export function namedProfiles(state, getters) { + return Object.entries(state.profilesCache) + .reduce((result, [pubkey, profile]) => getters.hasName(pubkey) + ? [...result, { ...profile, pubkey }] // [..., { name, pubkey, nip05, ...}, ...] + : result, + [] + ) +} + export function hasName(state) { return pubkey => { let {name, nip05} = state.profilesCache[pubkey] || {} From 550d356bd3b13139ed7cab8725068235f719c5b3 Mon Sep 17 00:00:00 2001 From: Ricardo Arturo Cabral Mejia Date: Sun, 30 Jan 2022 02:12:19 +0000 Subject: [PATCH 6/7] feat: add createMentionsProvider mixin --- src/utils/mixin.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/utils/mixin.js b/src/utils/mixin.js index 7dbb4fa..94bc6e0 100644 --- a/src/utils/mixin.js +++ b/src/utils/mixin.js @@ -1,5 +1,6 @@ import relative from 'relative-date' import {date} from 'quasar' +import Tribute from 'tributejs' import {shorten} from './helpers' export default { @@ -38,6 +39,47 @@ export default { } return text.replace(/\B#\[(\d+)\]\B/g, replacer) + }, + + createMentionsProvider(options) { + const tribute = new Tribute({ + spaceSelectsMatch: true, + menuShowMinLength: 1, + + selectTemplate: item => `@${item.original.value.pubkey}`, + + menuItemTemplate: item => { + return ` +
+
+
${item.string}
+ ${item.original.value.nip05 + ? '' + : ''} +
+
${shorten(item.original.value.pubkey)}
+
+ ` + }, + + values: (_pattern, callback) => { + callback( + this.$store.getters + .namedProfiles + .map(profile => ({ + key: this.$store.getters.displayName(profile.pubkey), + value: profile, + })) + ) + }, + + noMatchTemplate: () => undefined, // hide "No matches" + }) + + return { + attach: element => tribute.attach(element), + detach: element => tribute.detach(element), + } } } } From 12041956b08285c3ecbdef75a8044ce520a0790c Mon Sep 17 00:00:00 2001 From: Ricardo Arturo Cabral Mejia Date: Sun, 30 Jan 2022 02:12:52 +0000 Subject: [PATCH 7/7] feat: add mention menu to publish & replies --- src/components/Publish.vue | 21 ++++++++++++++++++++- src/components/Reply.vue | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/components/Publish.vue b/src/components/Publish.vue index cc1aad1..ac1fac5 100644 --- a/src/components/Publish.vue +++ b/src/components/Publish.vue @@ -3,6 +3,7 @@