Skip to content
Snippets Groups Projects
Commit afcf2fdd authored by syuilo's avatar syuilo
Browse files

Improve hashtag suggestion

parent 7316352f
No related branches found
No related tags found
No related merge requests found
......@@ -144,23 +144,28 @@ export default Vue.extend({
});
}
} else if (this.type == 'hashtag') {
const cacheKey = 'autocomplete:hashtag:' + this.q;
const cache = sessionStorage.getItem(cacheKey);
if (cache) {
const hashtags = JSON.parse(cache);
this.hashtags = hashtags;
if (this.q == null || this.q == '') {
this.hashtags = JSON.parse(localStorage.getItem('hashtags') || '[]');
this.fetching = false;
} else {
(this as any).api('hashtags/search', {
query: this.q,
limit: 30
}).then(hashtags => {
const cacheKey = 'autocomplete:hashtag:' + this.q;
const cache = sessionStorage.getItem(cacheKey);
if (cache) {
const hashtags = JSON.parse(cache);
this.hashtags = hashtags;
this.fetching = false;
// キャッシュ
sessionStorage.setItem(cacheKey, JSON.stringify(hashtags));
});
} else {
(this as any).api('hashtags/search', {
query: this.q,
limit: 30
}).then(hashtags => {
this.hashtags = hashtags;
this.fetching = false;
// キャッシュ
sessionStorage.setItem(cacheKey, JSON.stringify(hashtags));
});
}
}
} else if (this.type == 'emoji') {
const matched = [];
......
......@@ -79,7 +79,10 @@ class Autocomplete {
hashtagIndex == -1 ? Infinity : hashtagIndex,
emojiIndex == -1 ? Infinity : emojiIndex);
if (start == Infinity) return;
if (start == Infinity) {
this.close();
return;
}
const isMention = mentionIndex == start;
const isHashtag = hashtagIndex == start;
......@@ -97,7 +100,7 @@ class Autocomplete {
if (isHashtag || opened == false) {
const hashtag = text.substr(hashtagIndex + 1);
if (hashtag != '' && !hashtag.includes(' ') && !hashtag.includes('\n')) {
if (!hashtag.includes(' ') && !hashtag.includes('\n')) {
this.open('hashtag', hashtag);
opened = true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment