Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/ui/client/lib/UserCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export const closeUserCard = () => {
if (!dom) {
return;
}
unregister();
unregister = undefined;
unregister = unregister && unregister();
};

const props = () => {
Expand Down
35 changes: 27 additions & 8 deletions client/channel/UserCard/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useMemo, useRef, useCallback } from 'react';
import React, { useEffect, useMemo, useRef } from 'react';
import { PositionAnimated, AnimatedVisibility, Menu, Option } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';

import { useEndpointDataExperimental, ENDPOINT_STATES } from '../../hooks/useEndpointDataExperimental';
import { useSetting } from '../../contexts/SettingsContext';
Expand All @@ -9,6 +10,21 @@ import { Backdrop } from '../../components/basic/Backdrop';
import * as UserStatus from '../../components/basic/UserStatus';
import { LocalTime } from '../../components/basic/UTCClock';
import { useUserInfoActions, useUserInfoActionsSpread } from '../hooks/useUserInfoActions';
import { useCurrentRoute } from '../../contexts/RouterContext';

export const useComponentDidUpdate = (
effect,
dependencies = [],
) => {
const hasMounted = useRef(false);
useEffect(() => {
if (!hasMounted.current) {
hasMounted.current = true;
return;
}
effect();
}, dependencies);
};

const UserCardWithData = ({ username, onClose, target, open, rid }) => {
const ref = useRef(target);
Expand All @@ -23,6 +39,12 @@ const UserCardWithData = ({ username, onClose, target, open, rid }) => {

ref.current = target;

const [route, params] = useCurrentRoute();

useComponentDidUpdate(() => {
onClose && onClose();
}, [route, JSON.stringify(params), onClose]);

const user = useMemo(() => {
const loading = state === ENDPOINT_STATES.LOADING;
const defaultValue = loading ? undefined : null;
Expand Down Expand Up @@ -55,13 +77,10 @@ const UserCardWithData = ({ username, onClose, target, open, rid }) => {
};
}, [data, username, showRealNames, state]);

const handleOpen = useCallback(
(e) => {
open && open(e);
onClose && onClose();
},
[open, onClose],
);
const handleOpen = useMutableCallback((e) => {
open && open(e);
onClose && onClose();
});

const { actions: actionsDefinition, menu: menuOptions } = useUserInfoActionsSpread(useUserInfoActions(user, rid));

Expand Down
8 changes: 5 additions & 3 deletions client/reactAdapters.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Blaze } from 'meteor/blaze';
import { HTML } from 'meteor/htmljs';
import { Random } from 'meteor/random';
import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { ReactiveVar } from 'meteor/reactive-var';
import { Template } from 'meteor/templating';
import { Tracker } from 'meteor/tracker';
import _ from 'underscore';

let rootNode;
let invalidatePortals = () => {};
Expand Down Expand Up @@ -43,9 +45,9 @@ const mountRoot = async () => {
const [portals, setPortals] = useState(() => Tracker.nonreactive(() => Array.from(portalsMap.values())));

useLayoutEffect(() => {
invalidatePortals = () => {
invalidatePortals = _.debounce(() => {
setPortals(Array.from(portalsMap.values()));
};
}, 1);
invalidatePortals();

return () => {
Expand Down Expand Up @@ -73,7 +75,7 @@ export const registerPortal = (key, portal) => {
mountRoot();
}

portalsMap.set(key, { portal, key: Date.now() });
portalsMap.set(key, { portal, key: Random.id() });
invalidatePortals();
return () => unregisterPortal(key);
};
Expand Down