mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-25 08:26:43 -06:00
Improve hashtag suggestion
This commit is contained in:
parent
7316352ff5
commit
afcf2fddb1
2 changed files with 22 additions and 14 deletions
|
@ -144,23 +144,28 @@ export default Vue.extend({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (this.type == 'hashtag') {
|
} else if (this.type == 'hashtag') {
|
||||||
const cacheKey = 'autocomplete:hashtag:' + this.q;
|
if (this.q == null || this.q == '') {
|
||||||
const cache = sessionStorage.getItem(cacheKey);
|
this.hashtags = JSON.parse(localStorage.getItem('hashtags') || '[]');
|
||||||
if (cache) {
|
|
||||||
const hashtags = JSON.parse(cache);
|
|
||||||
this.hashtags = hashtags;
|
|
||||||
this.fetching = false;
|
this.fetching = false;
|
||||||
} else {
|
} else {
|
||||||
(this as any).api('hashtags/search', {
|
const cacheKey = 'autocomplete:hashtag:' + this.q;
|
||||||
query: this.q,
|
const cache = sessionStorage.getItem(cacheKey);
|
||||||
limit: 30
|
if (cache) {
|
||||||
}).then(hashtags => {
|
const hashtags = JSON.parse(cache);
|
||||||
this.hashtags = hashtags;
|
this.hashtags = hashtags;
|
||||||
this.fetching = false;
|
this.fetching = false;
|
||||||
|
} 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));
|
sessionStorage.setItem(cacheKey, JSON.stringify(hashtags));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (this.type == 'emoji') {
|
} else if (this.type == 'emoji') {
|
||||||
const matched = [];
|
const matched = [];
|
||||||
|
|
|
@ -79,7 +79,10 @@ class Autocomplete {
|
||||||
hashtagIndex == -1 ? Infinity : hashtagIndex,
|
hashtagIndex == -1 ? Infinity : hashtagIndex,
|
||||||
emojiIndex == -1 ? Infinity : emojiIndex);
|
emojiIndex == -1 ? Infinity : emojiIndex);
|
||||||
|
|
||||||
if (start == Infinity) return;
|
if (start == Infinity) {
|
||||||
|
this.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const isMention = mentionIndex == start;
|
const isMention = mentionIndex == start;
|
||||||
const isHashtag = hashtagIndex == start;
|
const isHashtag = hashtagIndex == start;
|
||||||
|
@ -97,7 +100,7 @@ class Autocomplete {
|
||||||
|
|
||||||
if (isHashtag || opened == false) {
|
if (isHashtag || opened == false) {
|
||||||
const hashtag = text.substr(hashtagIndex + 1);
|
const hashtag = text.substr(hashtagIndex + 1);
|
||||||
if (hashtag != '' && !hashtag.includes(' ') && !hashtag.includes('\n')) {
|
if (!hashtag.includes(' ') && !hashtag.includes('\n')) {
|
||||||
this.open('hashtag', hashtag);
|
this.open('hashtag', hashtag);
|
||||||
opened = true;
|
opened = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue