Elffuss BraidHub

kikocis/continue public

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