-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathActions.tsx
38 lines (35 loc) · 1021 Bytes
/
Actions.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Button, Flex, useMatches } from "@mantine/core";
import { useEffect, useRef } from "react";
import { useNavigate } from "react-router";
import { useRefManager } from "@/contexts/RefManager";
import { useClient } from "@/hooks/useClient";
import { IconMessagePlus } from "@/icons/IconMessagePlus";
export const Actions: React.FC = () => {
const { client } = useClient();
const navigate = useNavigate();
const { setRef } = useRefManager();
const ref = useRef<HTMLButtonElement>(null);
const label: React.ReactNode = useMatches({
base: <IconMessagePlus size={24} />,
sm: "New conversation",
});
const px = useMatches({
base: "xs",
sm: "md",
});
const handleClick = () => {
void navigate("/conversations/new");
};
useEffect(() => {
setRef("new-conversation-button", ref);
}, []);
return (
client && (
<Flex align="center" gap="xs">
<Button px={px} onClick={handleClick} ref={ref}>
{label}
</Button>
</Flex>
)
);
};