Fix error on room leave

Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
Ajay Bura 2022-01-09 10:29:06 +05:30
parent ca3cced6ad
commit 34bb5f9928
2 changed files with 24 additions and 22 deletions

View file

@ -188,16 +188,19 @@ function EmojiBoard({ onSelect }) {
const [availableEmojis, setAvailableEmojis] = useState([]); const [availableEmojis, setAvailableEmojis] = useState([]);
// This should be called whenever the room changes, so that we can switch out the emoji useEffect(() => {
// for whatever packs are relevant to this room const updateAvailableEmoji = (selectedRoomId) => {
function updateAvailableEmoji(selectedRoomId) { if (!selectedRoomId) {
setAvailableEmojis([]);
return;
}
// Retrieve the packs for the new room // Retrieve the packs for the new room
// Remove packs that aren't marked as emoji packs
// Remove packs without emojis
const packs = getRelevantPacks( const packs = getRelevantPacks(
initMatrix.matrixClient.getRoom(selectedRoomId), initMatrix.matrixClient.getRoom(selectedRoomId),
) )
// Remove packs that aren't marked as emoji packs
.filter((pack) => pack.usage.indexOf('emoticon') !== -1) .filter((pack) => pack.usage.indexOf('emoticon') !== -1)
// Remove packs without emojis
.filter((pack) => pack.getEmojis().length !== 0); .filter((pack) => pack.getEmojis().length !== 0);
// Set an index for each pack so that we know where to jump when the user uses the nav // Set an index for each pack so that we know where to jump when the user uses the nav
@ -205,12 +208,9 @@ function EmojiBoard({ onSelect }) {
packs[i].packIndex = i; packs[i].packIndex = i;
} }
// Update the component state
setAvailableEmojis(packs); setAvailableEmojis(packs);
} };
// Register the above function as an event listener
useEffect(() => {
navigation.on(cons.events.navigation.ROOM_SELECTED, updateAvailableEmoji); navigation.on(cons.events.navigation.ROOM_SELECTED, updateAvailableEmoji);
return () => { return () => {
navigation.removeListener(cons.events.navigation.ROOM_SELECTED, updateAvailableEmoji); navigation.removeListener(cons.events.navigation.ROOM_SELECTED, updateAvailableEmoji);

View file

@ -73,6 +73,8 @@ class Navigation extends EventEmitter {
this.emit(cons.events.navigation.SPACE_SELECTED, this.selectedSpaceId); this.emit(cons.events.navigation.SPACE_SELECTED, this.selectedSpaceId);
}, },
[cons.actions.navigation.SELECT_ROOM]: () => { [cons.actions.navigation.SELECT_ROOM]: () => {
if (this.selectedRoomId === action.roomId) return;
const prevSelectedRoomId = this.selectedRoomId; const prevSelectedRoomId = this.selectedRoomId;
this.selectedRoomId = action.roomId; this.selectedRoomId = action.roomId;
this.removeRecentRoom(prevSelectedRoomId); this.removeRecentRoom(prevSelectedRoomId);