From 497f3ffd47471413657d07e7e1f72a2dd03286af Mon Sep 17 00:00:00 2001 From: Flemmli97 Date: Thu, 10 Oct 2024 17:28:52 +0200 Subject: [PATCH] update emoji picker --- .../messaging/emoji/EmojiSelector.svelte | 31 ++++++++----------- src/lib/state/ui/index.ts | 2 ++ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/lib/components/messaging/emoji/EmojiSelector.svelte b/src/lib/components/messaging/emoji/EmojiSelector.svelte index 4e3ed363d..27959ca04 100644 --- a/src/lib/components/messaging/emoji/EmojiSelector.svelte +++ b/src/lib/components/messaging/emoji/EmojiSelector.svelte @@ -7,6 +7,8 @@ import { _ } from "svelte-i18n" import { createEventDispatcher, tick } from "svelte" import { createPersistentState } from "$lib/state" + import { UIStore } from "$lib/state/ui" + import { derived } from "svelte/store" interface Emoji { skin_tone: boolean @@ -24,12 +26,7 @@ let searchQuery: string = "" let filteredEmojiData: EmojiCategory = { ...emojiData } let showSkinTonePopup: boolean = false - let selectedSkinTone: string = "" // No skin tone by default - - interface FrequentlyUsedEmoji { - [glyph: string]: number - } - const frequentlyUsedEmojis = createPersistentState("emoji.history", {}) + $: selectedSkinTone = UIStore.state.selectedSkinTone const skinTones: string[] = ["🚫", "🏿", "🏾", "🏽", "🏼", "🏻"] const sampleEmojis: string[] = ["👍", "👋", "👏", "👌", "✌️"] @@ -64,7 +61,7 @@ } function selectSkinTone(tone: string) { - selectedSkinTone = tone === "🚫" ? "" : tone + selectedSkinTone.set(tone === "🚫" ? "" : tone) randomEmoji = sampleEmojis[Math.floor(Math.random() * sampleEmojis.length)] showSkinTonePopup = false tick().then(filterEmojis) // Re-filter emojis to trigger re-render @@ -86,7 +83,7 @@ } function trackEmojiUsage(emoji: string) { - frequentlyUsedEmojis.update(current => { + UIStore.state.emojiCounter.update(current => { if (current[emoji]) { current[emoji]++ } else { @@ -96,14 +93,12 @@ }) } - let frequentlyUsed: { glyph: string }[] = [] - - frequentlyUsedEmojis.subscribe(value => { - const sortedEmojis = Object.entries(value).sort((a, b) => b[1] - a[1]) - frequentlyUsed = sortedEmojis.slice(0, 20).map(([glyph]) => ({ glyph })) + $: frequentlyUsed = derived(UIStore.state.emojiCounter, counter => { + const sortedEmojis = Object.entries(counter).sort((a, b) => b[1] - a[1]) + return sortedEmojis.slice(0, 20).map(([glyph]) => ({ glyph })) }) - $: skinToneEmoji = getEmojiWithSkinTone(randomEmoji, selectedSkinTone) + $: skinToneEmoji = getEmojiWithSkinTone(randomEmoji, $selectedSkinTone) const emojiSize = createPersistentState("emoji.selectorsize", 44) @@ -135,7 +130,7 @@
diff --git a/src/lib/state/ui/index.ts b/src/lib/state/ui/index.ts index 072579e6b..0ac52f6cd 100644 --- a/src/lib/state/ui/index.ts +++ b/src/lib/state/ui/index.ts @@ -19,6 +19,7 @@ export interface IUIState { hiddenChats: Writable emojiSelector: Writable emojiCounter: Writable<{ [emoji: string]: number }> + selectedSkinTone: Writable marketOpen: Writable } class Store { @@ -47,6 +48,7 @@ class Store { hiddenChats: createPersistentState("uplink.ui.hiddenChats", []), emojiSelector: writable(false), emojiCounter: createPersistentState("uplink.ui.emojiCounter", { "👍": 0, "👎": 0, "❤️": 0, "🖖": 0, "😂": 0 }), + selectedSkinTone: createPersistentState("uplink.ui.emojiSkintone", ""), marketOpen: writable(false), } }