8000 release 0.15.0 by ccvlad · Pull Request #18 · ConnectyCube/use-chat · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

release 0.15.0 #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 26, 2025
Merged

release 0.15.0 #18

merged 5 commits into from
Feb 26, 2025

Conversation

ccvlad
Copy link
Contributor
@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
@@ -1,7 +1,7 @@
{
"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
0