A platform for community discussion. Free, open, simple.
UX: re-uses the autocomplete hashtag cache when applied to the rich editor (#35532)
Renato Atilioa61009284e7c
diff --git a/frontend/discourse/app/lib/hashtag-autocomplete.js b/frontend/discourse/app/lib/hashtag-autocomplete.jsindex 9cda4923533..b1fd65a6689 100644--- a/frontend/discourse/app/lib/hashtag-autocomplete.js+++ b/frontend/discourse/app/lib/hashtag-autocomplete.js@@ -180,3 +180,7 @@ export default function renderHashtagAutocomplete({ options }) {</div>`;}++export function getHashtagAutocompleteCache() {+ return searchCache;+}diff --git a/frontend/discourse/app/static/prosemirror/extensions/hashtag.js b/frontend/discourse/app/static/prosemirror/extensions/hashtag.jsindex f9d6a30882d..d1c716903f0 100644--- a/frontend/discourse/app/static/prosemirror/extensions/hashtag.js+++ b/frontend/discourse/app/static/prosemirror/extensions/hashtag.js@@ -1,4 +1,5 @@import { ajax } from "discourse/lib/ajax";+import { getHashtagAutocompleteCache } from "discourse/lib/hashtag-autocomplete";import { getHashtagTypeClasses } from "discourse/lib/hashtag-type-registry";import { emojiUnescape } from "discourse/lib/text";import { isBoundary } from "discourse/static/prosemirror/lib/markdown-it";@@ -165,7 +166,11 @@ const extension = {}// decorate valid hashtags based on their type- const tagText = emojiUnescape(validHashtag?.text || name);+ const displayText = validHashtag?.text || name;+ const tagText =+ typeof displayText === "string"+ ? emojiUnescape(displayText)+ : displayText;const hashtagTypeClass =getHashtagTypeClasses()[validHashtag.type];const hashtagIconHTML = hashtagTypeClass@@ -193,6 +198,21 @@ async function fetchHashtags(hashtags, context) {return;}+ const cache = getHashtagAutocompleteCache();+ if (cache) {+ const cachedItems = Object.values(cache).flat().filter(Boolean);+ cachedItems.forEach((item) => {+ if (slugs.includes(item.ref)) {+ VALID_HASHTAGS.set(item.ref, item);+ slugs.splice(slugs.indexOf(item.ref), 1);+ }+ });+ }++ if (!slugs.length) {+ return;+ }+const order = context.site.hashtag_configurations["topic-composer"];const response = await ajax("/hashtags", { data: { slugs, order } });