summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-07-21 03:15:31 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-07-21 03:15:31 +0900
commitafcf2fddb12898bc6e0b6ce33f7c4071af66762f (patch)
tree5b5549fd15f86758a7aa5fa42c5a182bea4c8f4b /src
parent:v: (diff)
downloadsharkey-afcf2fddb12898bc6e0b6ce33f7c4071af66762f.tar.gz
sharkey-afcf2fddb12898bc6e0b6ce33f7c4071af66762f.tar.bz2
sharkey-afcf2fddb12898bc6e0b6ce33f7c4071af66762f.zip
Improve hashtag suggestion
Diffstat (limited to 'src')
-rw-r--r--src/client/app/common/views/components/autocomplete.vue29
-rw-r--r--src/client/app/common/views/directives/autocomplete.ts7
2 files changed, 22 insertions, 14 deletions
diff --git a/src/client/app/common/views/components/autocomplete.vue b/src/client/app/common/views/components/autocomplete.vue
index d7006e3aa3..50f0d9154a 100644
--- a/src/client/app/common/views/components/autocomplete.vue
+++ b/src/client/app/common/views/components/autocomplete.vue
@@ -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;
+ } 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') {
const matched = [];
diff --git a/src/client/app/common/views/directives/autocomplete.ts b/src/client/app/common/views/directives/autocomplete.ts
index 7ec377111b..bb97bc2887 100644
--- a/src/client/app/common/views/directives/autocomplete.ts
+++ b/src/client/app/common/views/directives/autocomplete.ts
@@ -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;
}