Elffuss BraidHub

kikocis/continue public

9f9d0321be58 · 1.1 KiBRawPermalink
1import { SlashCommandDescription } from "core";
2import { usePostHog } from "posthog-js/react";
3import {
4 bookmarkSlashCommand,
5 selectBookmarkedSlashCommands,
6 unbookmarkSlashCommand,
7} from "../redux";
8import { useAppDispatch, useAppSelector } from "../redux/hooks";
9
10export function useBookmarkedSlashCommands() {
11 const dispatch = useAppDispatch();
12 const posthog = usePostHog();
13 const bookmarkedCommands = useAppSelector(selectBookmarkedSlashCommands);
14
15 const isCommandBookmarked = (commandName: string): boolean => {
16 return bookmarkedCommands.includes(commandName);
17 };
18
19 const toggleBookmark = (command: SlashCommandDescription) => {
20 const isBookmarked = isCommandBookmarked(command.name);
21
22 posthog.capture("toggle_bookmarked_slash_command", {
23 isBookmarked,
24 });
25
26 if (isBookmarked) {
27 dispatch(
28 unbookmarkSlashCommand({
29 commandName: command.name,
30 }),
31 );
32 } else {
33 dispatch(
34 bookmarkSlashCommand({
35 commandName: command.name,
36 }),
37 );
38 }
39 };
40
41 return {
42 isCommandBookmarked,
43 toggleBookmark,
44 };
45}