Skip to content

Commit

Permalink
Fix some bugs from linagora#2374
Browse files Browse the repository at this point in the history
  • Loading branch information
RomaricMourgues committed Jul 1, 2022
1 parent 8e77a6c commit ef22aa2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 189 deletions.
32 changes: 17 additions & 15 deletions twake/frontend/src/app/features/channels/hooks/use-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,30 @@ export function useChannel(
setLoading(false);
};

const refresh = async () => {
setLoading(true);
const ch = await ChannelAPIClient.get(companyId, workspaceId, channelId);
if (ch && ch?.id) {
set(ch);
} else {
set({
id: channelId,
name: '',
visibility: 'private',
});
}
setLoading(false);
};

useGlobalEffect(
hookId,
async () => {
if (!channel) {
setLoading(true);
const ch = await ChannelAPIClient.get(companyId, workspaceId, channelId);
if (ch && ch?.id) {
set(ch);
} else {
set({
id: channelId,
name: '',
visibility: 'private',
});
}
setLoading(false);
}
if (!channel) refresh();
},
[],
);

return { channel, save, loading };
return { channel, save, loading, refresh };
}

export const useIsChannelMember = (channelId: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import Shortcuts, {
} from 'app/features/global/services/shortcut-service';
import AddUserButton from 'components/add-user-button/add-user-button';
import Workspaces from 'app/deprecated/workspaces/workspaces';
import ModalManager from 'app/components/modal/modal-manager';
import WorkspaceChannelList from './Modals/WorkspaceChannelList';
import ScrollWithHiddenComponents from 'app/components/scroll-hidden-components/scroll-with-hidden-components';
import HiddenNotificationsButton from 'app/components/scroll-hidden-components/hidden-notifications-button';
import AccessRightsService from 'app/features/workspace-members/services/workspace-members-access-rights-service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import ChannelCategory from '../Parts/Channel/ChannelCategory';
import ChannelIntermediate from '../Parts/Channel/ChannelIntermediate';

import ChannelWorkspaceEditor from 'app/views/client/channels-bar/Modals/ChannelWorkspaceEditor';
import WorkspaceChannelList from 'app/views/client/channels-bar/Modals/WorkspaceChannelList';

import Menu from 'components/menus/menu.js';
import Icon from 'app/components/icon/icon';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useFavoriteChannels } from 'app/features/channels/hooks/use-favorite-ch
import ChannelMembersAPIClient from 'app/features/channel-members/api/channel-members-api-client';

import './ChannelRow.scss';
import { useChannel } from 'app/features/channels/hooks/use-channel';

type PropsType = {
channel: ChannelType;
Expand All @@ -24,6 +25,7 @@ type PropsType = {
export default ({ channel, joined, active }: PropsType) => {
const { refresh: refreshFavoriteChannels } = useFavoriteChannels();
const userId: string = UsersService.getCurrentUserId();
const { refresh: refreshChannel } = useChannel(channel.id || '');

const ref = createRef<HTMLDivElement>();

Expand Down Expand Up @@ -61,6 +63,8 @@ export default ({ channel, joined, active }: PropsType) => {
channelId: channel.id,
}),
);

refreshChannel();
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { useRefreshDirectChannels } from 'app/features/channels/hooks/use-direct
import { useChannelNotifications } from 'app/features/users/hooks/use-notifications';
import consoleService from 'app/features/console/services/console-service';
import { copyToClipboard } from 'app/features/global/utils/CopyClipboard';
import { useChannel } from 'app/features/channels/hooks/use-channel';

type PropsType = {
channel: ChannelType;
Expand Down Expand Up @@ -63,6 +64,7 @@ const FullMenu = (props: PropsType): JSX.Element => {
const { user: currentUser } = useCurrentUser();
const { refresh: refreshFavoriteChannels } = useRefreshFavoriteChannels();
const { refresh: refreshDirectChannels } = useRefreshDirectChannels();
const { refresh: refreshChannel } = useChannel(props.channel.id || '');
const { Feature, FeatureNames } = useFeatureToggles();
const channelMember = props.channel.user_member || {};

Expand Down Expand Up @@ -148,6 +150,8 @@ const FullMenu = (props: PropsType): JSX.Element => {
refreshFavoriteChannels();
refreshDirectChannels();
}

refreshChannel();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { usePendingEmails } from 'app/features/pending-emails/hooks/use-pending-
import PendingEmailsAPIClient from 'app/features/pending-emails/api/pending-emails-api-client';

import './MemberChannelRow.scss';
import { useChannel } from 'app/features/channels/hooks/use-channel';

const { Text } = Typography;

Expand All @@ -39,6 +40,7 @@ const MemberChannelRow = (props: Props): JSX.Element => {
const workspaceId = useRouterWorkspace();
const [isMember, setIsMember] = useState<boolean>(false);
const [selected, setSelected] = useState<boolean>(false);
const { refresh: refreshChannel } = useChannel(props.channelId);
const { refresh: refreshChannelMembers } = useChannelMembers({
companyId,
workspaceId,
Expand Down Expand Up @@ -74,7 +76,7 @@ const MemberChannelRow = (props: Props): JSX.Element => {
await ChannelsReachableAPIClient.removeUser(companyId, workspaceId, channelId, userId)
.then(refreshChannelMembers)
.finally(() => setIsMember(false));

refreshChannel();
currentUserId === props.userId && ModalManager.close();
};

Expand Down

0 comments on commit ef22aa2

Please sign in to comment.