Skip to content

Commit

Permalink
first emoji updater issue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminDreasond committed Aug 11, 2023
1 parent eb20f4e commit 2f90b91
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/app/organisms/emoji-board/EmojiBoard.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect, useRef, useReducer } from 'react';
import PropTypes from 'prop-types';

import parse from 'html-react-parser';
Expand Down Expand Up @@ -173,6 +173,7 @@ SearchedEmoji.propTypes = {
function EmojiBoard({ onSelect, searchRef, emojiBoardRef, scrollEmojisRef }) {

// First Values
const [, forceUpdate] = useReducer((count) => count + 1, 0);
const emojiInfo = useRef(null);
const [boardType, setBoardType] = useState('emoji');
const [selectedRoomId, setSelectedRoomId] = useState(null);
Expand All @@ -182,6 +183,8 @@ function EmojiBoard({ onSelect, searchRef, emojiBoardRef, scrollEmojisRef }) {
const [emojiData, setEmojiData] = useState([]);
const [emojiRecent, setEmojiRecent] = useState([]);

const mx = initMatrix.matrixClient;

ROW_COUNT = (boardType !== 'sticker' ? ROW_EMOJIS_COUNT : ROW_STICKERS_COUNT);
loadEmojiData(selectedRoomId);
getEmojiData(boardType, emojiRecent, emojiFav, emojiData, setEmojiRecent, setEmojiFav, setEmojiData);
Expand Down Expand Up @@ -373,6 +376,12 @@ function EmojiBoard({ onSelect, searchRef, emojiBoardRef, scrollEmojisRef }) {
const favOffset = emojiFav.length > 0 ? 1 : 0;

useEffect(() => {

const handleEvent = (event) => {
const eventType = event.getType();
if (eventType === 'im.ponies.emote_rooms' || eventType === 'im.ponies.user_emotes') forceUpdate();
};

const updateAvailableEmoji = async (newRoomId) => {
setSelectedRoomId(newRoomId);
};
Expand All @@ -383,13 +392,15 @@ function EmojiBoard({ onSelect, searchRef, emojiBoardRef, scrollEmojisRef }) {
setBoardType(dom);
};

navigation.on(cons.events.navigation.UPDATED_EMOJI_LIST, updateAvailableEmoji);
mx.addListener('accountData', handleEvent);
// navigation.on(cons.events.navigation.UPDATED_EMOJI_LIST, updateAvailableEmoji);
navigation.on(cons.events.navigation.ROOM_SELECTED, updateAvailableEmoji);
navigation.on(cons.events.navigation.EMOJIBOARD_OPENED, onOpen);
$(scrollEmojisRef.current).on('scroll', onScroll);
return () => {
$(scrollEmojisRef.current).off('scroll', onScroll);
navigation.removeListener(cons.events.navigation.UPDATED_EMOJI_LIST, updateAvailableEmoji);
mx.removeListener('accountData', handleEvent);
// navigation.removeListener(cons.events.navigation.UPDATED_EMOJI_LIST, updateAvailableEmoji);
navigation.removeListener(cons.events.navigation.ROOM_SELECTED, updateAvailableEmoji);
navigation.removeListener(cons.events.navigation.EMOJIBOARD_OPENED, onOpen);
};
Expand Down

0 comments on commit 2f90b91

Please sign in to comment.