Skip to content

Commit bca8f96

Browse files
committed
adds docs for usePinHandler
1 parent b0d30f5 commit bca8f96

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/docs/usePinHandler.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
A custom hook to handle message pinning. It provides the permission status of the connected user and a function to toggle pinned status on the message.
2+
3+
| Parameter | Type | Description |
4+
| ------------------------------------ | -------------------------------------------------------- | --------------------------------------------------------------- |
5+
| `message` | [object](https://getstream.io/chat/docs/#message_format) | The message to be handled. |
6+
| `permissions` | object | The user roles allowed to pin messages in various channel types |
7+
| `notifications` | object | An object containing the following properties: |
8+
| `notifications.notify` | func | A function that adds notification text to message |
9+
| `notifications.getErrorNotification` | func | A function that returns an error message |
10+
11+
It returns the following object:
12+
13+
| Parameter | Type | Description |
14+
| ----------- | ------- | -------------------------------------------------- |
15+
| `canPin` | boolean | Whether or not the connected user can pin messages |
16+
| `handlePin` | func | Function to toggle the pinned status of a message |
17+
18+
```json
19+
import { usePinHandler } from 'stream-chat-react';
20+
const MyCustomMessageComponent = (props) => {
21+
const { addNotification, getPinMessageErrorNotification, message, pinPermissions } = props;
22+
const { canPin, handlePin } = usePinHandler(message, pinPermissions, {
23+
notify: addNotification,
24+
getErrorNotification: getPinMessageErrorNotification,
25+
});
26+
const handleClick = () => {
27+
if (canPin) handlePin(message);
28+
}
29+
return (
30+
<div className={message.pinned ? 'pinned' : ''} onClick={handleClick}>
31+
<p>{message.text}</p>
32+
</div>
33+
);
34+
};
35+
```

styleguide.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ module.exports = {
8181
name: 'useOpenThreadHandler',
8282
content: 'src/docs/useOpenThreadHandler.md',
8383
},
84+
{
85+
name: 'usePinHandler',
86+
content: 'src/docs/usePinHandler.md',
87+
},
8488
{
8589
name: 'useReactionHandler',
8690
content: 'src/docs/useReactionHandler.md',

0 commit comments

Comments
 (0)