Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 3 additions & 13 deletions apps/meteor/client/views/room/Header/icons/Favorite.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import type { IRoom, ISubscription } from '@rocket.chat/core-typings';
import { useEffectEvent } from '@rocket.chat/fuselage-hooks';
import { HeaderState } from '@rocket.chat/ui-client';
import { useSetting, useMethod, useTranslation, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import { useSetting, useMethod, useTranslation } from '@rocket.chat/ui-contexts';
import React, { memo } from 'react';

import { useUserIsSubscribed } from '../../contexts/RoomContext';

const Favorite = ({ room: { _id, f: favorite = false, t: type, name } }: { room: IRoom & { f?: ISubscription['f'] } }) => {
const t = useTranslation();
const subscribed = useUserIsSubscribed();
const dispatchToastMessage = useToastMessageDispatch();

const isFavoritesEnabled = useSetting('Favorite_Rooms') && ['c', 'p', 'd', 't'].includes(type);
const toggleFavorite = useMethod('toggleFavorite');
Expand All @@ -19,17 +18,7 @@ const Favorite = ({ room: { _id, f: favorite = false, t: type, name } }: { room:
return;
}

try {
toggleFavorite(_id, !favorite);
dispatchToastMessage({
type: 'success',
message: !favorite
? t('__roomName__was_added_to_favorites', { roomName: name })
: t('__roomName__was_removed_from_favorites', { roomName: name }),
});
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
toggleFavorite(_id, !favorite);
});

const favoriteLabel = favorite ? `${t('Unfavorite')} ${name}` : `${t('Favorite')} ${name}`;
Expand All @@ -41,6 +30,7 @@ const Favorite = ({ room: { _id, f: favorite = false, t: type, name } }: { room:
return (
<HeaderState
title={favoriteLabel}
aria-live='assertive'
icon={favorite ? 'star-filled' : 'star'}
onClick={handleFavoriteClick}
color={favorite ? 'status-font-on-warning' : null}
Expand Down
2 changes: 0 additions & 2 deletions packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
"__count__without__department__": "{{count}} without department",
"__count__without__tags__": "{{count}} without tags",
"__count__without__assignee__": "{{count}} without assignee",
"__roomName__was_added_to_favorites": "{{roomName}} was added to favorites",
"__roomName__was_was_removed_from_favorites": "{{roomName}} was removed from favorites",
"removed__username__as__role_": "removed {{username}} as {{role}}",
"set__username__as__role_": "set {{username}} as {{role}}",
"This_room_encryption_has_been_enabled_by__username_": "This room's encryption has been enabled by {{username}}",
Expand Down