You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
711 B
29 lines
711 B
import { getEmojiName } from './util';
|
|
import { EmojiData, EmojiButtonOptions, RecentEmoji } from './types';
|
|
|
|
const LOCAL_STORAGE_KEY = 'emojiPicker.recent';
|
|
|
|
export function load() {
|
|
const recentJson = localStorage.getItem(LOCAL_STORAGE_KEY);
|
|
return recentJson ? JSON.parse(recentJson) : [];
|
|
}
|
|
|
|
export function save(emoji: any, options: EmojiButtonOptions): void {
|
|
const recents = load();
|
|
|
|
const recent = {
|
|
e: emoji.e,
|
|
n: getEmojiName(emoji),
|
|
k: emoji.k || getEmojiName(emoji)
|
|
};
|
|
|
|
localStorage.setItem(
|
|
LOCAL_STORAGE_KEY,
|
|
JSON.stringify(
|
|
[recent, ...recents.filter((r: RecentEmoji) => r.k !== recent.k)].slice(
|
|
0,
|
|
options.recentsCount
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|