Skip to content

Commit

Permalink
emojiboard fix try again
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminDreasond committed Aug 11, 2023
1 parent 5365d6b commit 648f518
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
9 changes: 3 additions & 6 deletions src/app/molecules/image-pack/ImagePack.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ function useRoomImagePack(roomId, stateKey) {
), [room, stateKey]);

const sendPackContent = (content) => {
mx.sendStateEvent(roomId, 'im.ponies.room_emotes', content, stateKey).then(() => {
const roomData = getSelectRoom();
updateEmojiList(roomData && roomData.roomId ? roomData.roomId : undefined);
});
mx.sendStateEvent(roomId, 'im.ponies.room_emotes', content, stateKey).then(() => updateEmojiList(roomId));
};

return {
Expand All @@ -111,7 +108,7 @@ function useUserImagePack() {
), []);

const sendPackContent = (content) => {
mx.setAccountData('im.ponies.user_emotes', content);
mx.setAccountData('im.ponies.user_emotes', content).then(() => updateEmojiList(getSelectRoom()));
};

return {
Expand Down Expand Up @@ -295,7 +292,7 @@ function ImagePack({ roomId, stateKey, handlePackDelete }) {
onEditProfile={canChange ? handleEditProfile : null}
/>
{canChange && (
<ImagePackUpload onUpload={handleAddItem} />
<ImagePackUpload onUpload={handleAddItem} roomId={roomId} />
)}

{images.length === 0 ? null : (
Expand Down
10 changes: 7 additions & 3 deletions src/app/molecules/image-pack/ImagePackUpload.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import IconButton from '../../atoms/button/IconButton';
import { updateEmojiList } from '../../../client/action/navigation';
import { getSelectRoom } from '../../../util/selectedRoom';

function ImagePackUpload({ onUpload }) {
function ImagePackUpload({ onUpload, roomId, }) {
const mx = initMatrix.matrixClient;
const inputRef = useRef(null);
const shortcodeRef = useRef(null);
Expand All @@ -36,8 +36,11 @@ function ImagePackUpload({ onUpload }) {
setImgFile(null);
shortcodeRef.current.value = '';

const room = getSelectRoom();
updateEmojiList(room && room.roomId ? room.roomId : null);
if (!roomId) {
updateEmojiList(getSelectRoom());
} else {
updateEmojiList(roomId);
}

};

Expand Down Expand Up @@ -73,6 +76,7 @@ function ImagePackUpload({ onUpload }) {
);
}
ImagePackUpload.propTypes = {
roomId: PropTypes.string,
onUpload: PropTypes.func.isRequired,
};

Expand Down
3 changes: 0 additions & 3 deletions src/app/organisms/navigation/DrawerHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import IconButton from '../../atoms/button/IconButton';
import { MenuItem, MenuHeader } from '../../atoms/context-menu/ContextMenu';
import SpaceOptions from '../../molecules/space-options/SpaceOptions';

import { setSelectSpace } from '../../../util/selectedRoom';

const HashPlusIC = './img/ic/outlined/hash-plus.svg';
const HashGlobeIC = './img/ic/outlined/hash-globe.svg';
const HashSearchIC = './img/ic/outlined/hash-search.svg';
Expand Down Expand Up @@ -105,7 +103,6 @@ function DrawerHeader({ selectedTab, spaceId, room, banner }) {
const isDMTab = selectedTab === cons.tabs.DIRECTS;

const spaceName = isDMTab ? null : (room?.name || null);
setSelectSpace(room);

const openSpaceOptions = (e) => {
e.preventDefault();
Expand Down
7 changes: 5 additions & 2 deletions src/client/action/navigation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setSelectRoom, setSelectSpace } from '../../util/selectedRoom';
import appDispatcher from '../dispatcher';
import cons from '../state/cons';

Expand All @@ -16,13 +17,15 @@ export function selectRoomMode(roomType) {
}

export function selectSpace(roomId) {
setSelectSpace(roomId);
appDispatcher.dispatch({
type: cons.actions.navigation.SELECT_SPACE,
roomId,
});
}

export function selectRoom(roomId, eventId) {
setSelectRoom(roomId);
appDispatcher.dispatch({
type: cons.actions.navigation.SELECT_ROOM,
roomId,
Expand Down Expand Up @@ -207,10 +210,10 @@ export function consoleRemoveData(content) {
});
}

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

Expand Down
8 changes: 4 additions & 4 deletions src/util/selectedRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ function getDataFolderRaw(dataFolder, where) {
}

let room;
export function setSelectRoom(body) {
room = body;
export function setSelectRoom(value) {
room = value;
};

export function getSelectRoom() {
return room;
};

let space;
export function setSelectSpace(body) {
space = body;
export function setSelectSpace(value) {
space = value;
};

export function getSelectSpace() {
Expand Down

0 comments on commit 648f518

Please sign in to comment.