タグサジェストが重複しないようにする

This commit is contained in:
Acid Chicken (硫酸鶏) 2018-07-20 19:23:10 +09:00 committed by Aya Morisawa
parent eb6c2d0f73
commit bc627fc55c
2 changed files with 4 additions and 6 deletions

View file

@ -382,9 +382,8 @@ export default Vue.extend({
if (this.text && this.text != '') {
const hashtags = parse(this.text).filter(x => x.type == 'hashtag').map(x => x.hashtag);
let history = JSON.parse(localStorage.getItem('hashtags') || '[]') as string[];
history = history.filter(x => !hashtags.includes(x));
localStorage.setItem('hashtags', JSON.stringify(hashtags.concat(history)));
const history = JSON.parse(localStorage.getItem('hashtags') || '[]') as string[];
localStorage.setItem('hashtags', JSON.stringify(hashtags.concat(history).reduce((a, c) => a.includes(c) ? a : [...a, c], [])));
}
},

View file

@ -295,9 +295,8 @@ export default Vue.extend({
if (this.text && this.text != '') {
const hashtags = parse(this.text).filter(x => x.type == 'hashtag').map(x => x.hashtag);
let history = JSON.parse(localStorage.getItem('hashtags') || '[]') as string[];
history = history.filter(x => !hashtags.includes(x));
localStorage.setItem('hashtags', JSON.stringify(hashtags.concat(history)));
const history = JSON.parse(localStorage.getItem('hashtags') || '[]') as string[];
localStorage.setItem('hashtags', JSON.stringify(hashtags.concat(history).reduce((a, c) => a.includes(c) ? a : [...a, c], [])));
}
},