Skip to content

release 0.15.0#18

Merged
ccvlad merged 5 commits intomainfrom
rc-0.15.0
Feb 26, 2025
Merged

release 0.15.0#18
ccvlad merged 5 commits intomainfrom
rc-0.15.0

Conversation

@ccvlad
Copy link
Collaborator

@ccvlad ccvlad commented Feb 25, 2025

0.15.0

Features

  • Implemented blockList users API via useBlockList hook.
import React, { useEffect } from "react";
import { useChat } from "@connectycube/use-chat";

const MyComponent: React.FC<MyComponentProps> = ({userId}) => {
  const { blockedUsers, isBlockedUser, blockUser, unblockUser } = useChat();

  useEffect(() => {
    console.log(`Blocked user ids: ${blockedUsers}`);
  }, [blockedUsers]);

  useEffect(() => {
    console.log(`User (${userId}) blocked: ${isBlockedUser(userId)}`);
  }, [blockedUsers, userId]);

  return (
    //...
    <button onClick={() => blockUser(userId)}>{"Block"}</button>
    <button onClick={() => unblockUser(userId)}>{"Unblock"}</button>
    //...
  );
}

package.json Outdated
"name": "@connectycube/use-chat",
"description": "A React hook for state management in ConnectyCube-powered chat solutions",
"version": "0.14.4",
"version": "0.15.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.15.0


const addToState = (userId: number): void => {
setState((state) => {
state.add(userId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React state should be treated as immutable. In your code, you're directly mutating the existing Set by calling its .add() method, and then returning the same reference. This can lead to issues because React relies on detecting changes via new object references. If the state reference remains unchanged, React might not trigger a re-render.

Let's replaced to

const addToState = (userId: number): void => {
 setState(prevState => {
   const newState = new Set(prevState);
   newState.add(userId);
   return newState;
 });
};

This ensures that you are not mutating the previous state directly and that React will properly update the component when the state changes.


const deleteFromState = (userId: number): void => {
setState((state) => {
state.delete(userId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

}

if (action === BlockAction.ALLOW && !isBlocked(user_id)) {
console.warn("[useChat][useBlockList][update]: user is not blocked");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.warn(`[useChat][useBlockList][update]: user ${user_id} is not blocked`);

}

if (action === BlockAction.DENY && isBlocked(user_id)) {
console.warn("[useChat][useBlockList][update]: user is already blocked");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.warn(`[useChat][useBlockList][update]: user ${user_id} is already blocked`);

@ccvlad ccvlad changed the title RC-0.15.0 release 0.15.0 Feb 26, 2025
CHANGELOG.md Outdated

### Features

- Implemented blockList users API via `useBlockList` hook.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End user does not work directly with useBlockList , so this can be replaced to

- Implemented Block users API 

@ccvlad ccvlad merged commit 50e1c72 into main Feb 26, 2025
1 check passed
@ccvlad ccvlad deleted the rc-0.15.0 branch May 1, 2025 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants