diff --git a/src/components/GroupPlayer.tsx b/src/components/GroupPlayer.tsx index 82ae300..c7f12c3 100644 --- a/src/components/GroupPlayer.tsx +++ b/src/components/GroupPlayer.tsx @@ -34,9 +34,9 @@ const GroupPlayer = ({ group, player, isHost }: GroupPlayerProps) => { if (status === 'SUBSCRIBED') { channel.send({ type: 'broadcast', - event: 'update', + event: 'kick', payload: { - message: `${player.username} was kicked from the group!`, + player, }, }); } diff --git a/src/pages/Group.tsx b/src/pages/Group.tsx index 43f94c7..22f9652 100644 --- a/src/pages/Group.tsx +++ b/src/pages/Group.tsx @@ -57,6 +57,17 @@ const Group = () => { queryClient.invalidateQueries(['group', id]); toast(payload.message); }) + .on('broadcast', { event: 'kick' }, ({ payload }) => { + if (user && payload.player.id === user.id) { + toast('You were kicked from the group!'); + queryClient.invalidateQueries(['group', id]); + queryClient.invalidateQueries(['player', user.id]); + return; + } + + toast(`${payload.player.username} was kicked from the group!`); + queryClient.invalidateQueries(['group', id]); + }) .on( 'postgres_changes', {