tahamajs's picture
download
raw
2.43 kB
// src/components/command-palette/hooks/useCommandActions.ts
import { useMemo } from "react";
import { useNavigate } from "react-router-dom";
import { useAuth } from "@/context/AuthContext";
import { useTheme } from "@/hooks/useTheme";
import { useModal } from "@/context/ModalContext";
import { useSearch } from "@/context/SearchContext";
import { useNotifications } from "@/context/NotificationContext";
import { CommandAction } from "../types";
import { Sun, Moon, Bell } from "lucide-react";
import {
createNavigationActions,
createContentActions,
createSocialActions,
createProjectActions,
createResearchActions,
createAdminActions,
} from "../actions";
import { toast } from "react-toastify";
export const useCommandActions = () => {
const navigate = useNavigate();
const { user } = useAuth();
const { toggleTheme, resolvedMode } = useTheme();
const { openModal, closeModal } = useModal();
const { setQuery, search } = useSearch();
const { markAllAsRead } = useNotifications();
const actions: CommandAction[] = useMemo(() => {
const allActions: CommandAction[] = [
...createNavigationActions(navigate),
...createContentActions(navigate, {
onSearch: () => {
navigate("/search");
setTimeout(() => setQuery(""), 100);
},
}),
...createSocialActions(navigate, user ?? undefined),
...createProjectActions(navigate, []),
...createResearchActions(navigate),
...createAdminActions(navigate, user?.role === "admin"),
];
// Theme toggle action
allActions.push({
id: "toggle-theme",
name: `${resolvedMode === "dark" ? "Light" : "Dark"} Mode`,
shortcut: ["t", "h"],
keywords: ["theme", "dark mode", "light mode", "appearance"],
section: "Preferences",
icon: resolvedMode === "dark" ? <Sun className="w-4 h-4" /> : <Moon className="w-4 h-4" />,
perform: toggleTheme,
});
// Mark all notifications as read
if (user) {
allActions.push({
id: "mark-all-read",
name: "Mark All Notifications as Read",
shortcut: ["n", "a"],
keywords: ["notifications", "mark read", "clear notifications"],
section: "Actions",
icon: <Bell className="w-4 h-4" />,
perform: markAllAsRead,
});
}
return allActions;
}, [navigate, user, toggleTheme, resolvedMode, markAllAsRead, setQuery]);
return actions;
};

Xet Storage Details

Size:
2.43 kB
·
Xet hash:
9ad253e2db5d0c0edd917013b2a898d196ae6a74752fbe53916cf68cc4870e53

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.