From 81caaa2ebed066f80939b04f565b307ec0dd2d61 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 10 Sep 2020 16:12:09 +0300 Subject: Split web things into subdirectories --- web/frequently-used.js | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 web/frequently-used.js (limited to 'web/frequently-used.js') diff --git a/web/frequently-used.js b/web/frequently-used.js deleted file mode 100644 index 1601e03..0000000 --- a/web/frequently-used.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2020 Tulir Asokan -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -const FREQUENTLY_USED = JSON.parse(window.localStorage.mauFrequentlyUsedStickerIDs || "{}") -let FREQUENTLY_USED_SORTED = null - -export const add = id => { - const [count] = FREQUENTLY_USED[id] || [0] - FREQUENTLY_USED[id] = [count + 1, Date.now()] - window.localStorage.mauFrequentlyUsedStickerIDs = JSON.stringify(FREQUENTLY_USED) - FREQUENTLY_USED_SORTED = null -} - -export const get = (limit = 16) => { - if (FREQUENTLY_USED_SORTED === null) { - FREQUENTLY_USED_SORTED = Object.entries(FREQUENTLY_USED) - .sort(([, [count1, date1]], [, [count2, date2]]) => - count2 === count1 ? date2 - date1 : count2 - count1) - .map(([emoji]) => emoji) - } - return FREQUENTLY_USED_SORTED.slice(0, limit) -} -- cgit v1.2.3