Skip to content

Commit

Permalink
trying to fix emoji board load issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminDreasond committed Aug 11, 2023
1 parent 27e0b00 commit 1f7a959
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/app/molecules/image-pack/ImagePack.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, {
import PropTypes from 'prop-types';

import initMatrix from '../../../client/initMatrix';
import { openReusableDialog } from '../../../client/action/navigation';
import { openReusableDialog, updateEmojiList } from '../../../client/action/navigation';
import { suffixRename } from '../../../util/common';

import Button from '../../atoms/button/Button';
Expand All @@ -17,6 +17,7 @@ import { confirmDialog } from '../confirm-dialog/ConfirmDialog';
import ImagePackProfile from './ImagePackProfile';
import ImagePackItem from './ImagePackItem';
import ImagePackUpload from './ImagePackUpload';
import { getSelectRoom } from '../../../util/selectedRoom';

const renameImagePackItem = (shortcode) => new Promise((resolve) => {
let isCompleted = false;
Expand All @@ -27,12 +28,19 @@ const renameImagePackItem = (shortcode) => new Promise((resolve) => {
<div style={{ padding: 'var(--sp-normal)' }}>
<form
onSubmit={(e) => {

e.preventDefault();
const sc = e.target.shortcode.value;
if (sc.trim() === '') return;

isCompleted = true;
resolve(sc.trim());

const room = getSelectRoom();
updateEmojiList(room && room.roomId ? room.roomId : undefined);

requestClose();

}}
>
<div>
Expand Down Expand Up @@ -171,6 +179,10 @@ function useImagePackHandles(pack, sendPackContent) {

sendPackContent(pack.getContent());
forceUpdate();

const roomData = getSelectRoom();
updateEmojiList(roomData && roomData.roomId ? roomData.roomId : undefined);

};
const handleUsageItem = (key, newUsage) => {
const usage = [];
Expand Down Expand Up @@ -256,7 +268,12 @@ function ImagePack({ roomId, stateKey, handlePackDelete }) {
'danger',
);
if (!isConfirmed) return;

handlePackDelete(stateKey);

const roomData = getSelectRoom();
updateEmojiList(roomData && roomData.roomId ? roomData.roomId : undefined);

};

const images = [...pack.images].slice(0, viewMore ? pack.images.size : 2);
Expand Down
8 changes: 8 additions & 0 deletions src/app/molecules/image-pack/ImagePackUpload.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Text from '../../atoms/text/Text';
import Button from '../../atoms/button/Button';
import Input from '../../atoms/input/Input';
import IconButton from '../../atoms/button/IconButton';
import { updateEmojiList } from '../../../client/action/navigation';
import { getSelectRoom } from '../../../util/selectedRoom';

function ImagePackUpload({ onUpload }) {
const mx = initMatrix.matrixClient;
Expand All @@ -17,8 +19,10 @@ function ImagePackUpload({ onUpload }) {
const [progress, setProgress] = useState(false);

const handleSubmit = async (evt) => {

evt.preventDefault();
if (!imgFile) return;

const { shortcodeInput } = evt.target;
const shortcode = shortcodeInput.value.trim();
if (shortcode === '') return;
Expand All @@ -31,6 +35,10 @@ function ImagePackUpload({ onUpload }) {
setProgress(false);
setImgFile(null);
shortcodeRef.current.value = '';

const room = getSelectRoom();
updateEmojiList(room && room.roomId ? room.roomId : null);

};

const handleFileChange = (evt) => {
Expand Down
2 changes: 2 additions & 0 deletions src/app/organisms/emoji-board/EmojiBoard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,13 @@ function EmojiBoard({ onSelect, searchRef, emojiBoardRef, scrollEmojisRef }) {
setBoardType(dom);
};

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);
navigation.removeListener(cons.events.navigation.ROOM_SELECTED, updateAvailableEmoji);
navigation.removeListener(cons.events.navigation.EMOJIBOARD_OPENED, onOpen);
};
Expand Down
7 changes: 7 additions & 0 deletions src/client/action/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ export function consoleRemoveData(content) {
});
}

export function updateEmojiList(content) {
appDispatcher.dispatch({
type: cons.actions.navigation.UPDATE_EMOJI_LIST,
content,
});
}

export function consoleNewData(content) {
appDispatcher.dispatch({
type: cons.actions.navigation.CONSOLE_NEW_DATA,
Expand Down
2 changes: 2 additions & 0 deletions src/client/state/cons.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const cons = {
},
actions: {
navigation: {
UPDATE_EMOJI_LIST: 'UPDATE_EMOJI_LIST',
SELECT_ROOM_MODE: 'SELECT_ROOM_MODE',
SELECT_TAB: 'SELECT_TAB',
SELECT_SPACE: 'SELECT_SPACE',
Expand Down Expand Up @@ -98,6 +99,7 @@ const cons = {
TAB_SELECTED: 'TAB_SELECTED',
SPACE_SELECTED: 'SPACE_SELECTED',
ROOM_SELECTED: 'ROOM_SELECTED',
UPDATED_EMOJI_LIST: 'UPDATED_EMOJI_LIST',
SPACE_SETTINGS_OPENED: 'SPACE_SETTINGS_OPENED',
SPACE_MANAGE_OPENED: 'SPACE_MANAGE_OPENED',
SPACE_ADDEXISTING_OPENED: 'SPACE_ADDEXISTING_OPENED',
Expand Down
4 changes: 4 additions & 0 deletions src/client/state/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ class Navigation extends EventEmitter {
this._selectTab(action.tabId);
},

[cons.actions.navigation.UPDATE_EMOJI_LIST]: () => {
this.emit(cons.events.navigation.UPDATED_EMOJI_LIST, action.roomId);
},

[cons.actions.navigation.CONSOLE_REMOVE_DATA]: () => {
this.emit(cons.events.navigation.CONSOLE_REMOVED_DATA, action.content);
},
Expand Down

0 comments on commit 1f7a959

Please sign in to comment.