Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: toggle chat history with cmd+b #8360

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion front/components/navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { XMarkIcon } from "@dust-tt/sparkle";
import type { SubscriptionType, WorkspaceType } from "@dust-tt/types";
import { Dialog, Transition } from "@headlessui/react";
import { Bars3Icon } from "@heroicons/react/20/solid";
import React, { Fragment, useContext, useState } from "react";
import React, { Fragment, useContext, useEffect, useState } from "react";

import type { SidebarNavigation } from "@app/components/navigation/config";
import {
Expand Down Expand Up @@ -30,6 +30,18 @@ export function Navigation({
const { sidebarOpen, setSidebarOpen } = useContext(SidebarContext);
const [isNavigationBarOpen, setNavigationBarOpen] = useState(true);

useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key.toLowerCase() === "b" && (e.metaKey || e.ctrlKey)) {
e.preventDefault();
setSidebarOpen(!sidebarOpen);
}
};

document.addEventListener("keydown", handleKeyDown);
return () => document.removeEventListener("keydown", handleKeyDown);
}, [isNavigationBarOpen, setSidebarOpen, sidebarOpen]);

if (hideSidebar) {
return null;
}
Expand Down
14 changes: 12 additions & 2 deletions front/components/sparkle/SidebarContext.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React, { useState } from "react";
import React, { useCallback, useState } from "react";

export const SidebarContext = React.createContext<{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know why it's in /sparkle/ ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Navigation is going to move to Sparkle very soon.

sidebarOpen: boolean;
setSidebarOpen: (value: boolean) => void;
toggleSidebar: () => void;
}>({
sidebarOpen: false,
setSidebarOpen: (value) => {
throw new Error("SidebarContext not initialized: " + value);
},
toggleSidebar: () => {
throw new Error("SidebarContext not initialized");
},
});

export const SidebarProvider = ({
Expand All @@ -17,8 +21,14 @@ export const SidebarProvider = ({
}) => {
const [sidebarOpen, setSidebarOpen] = useState(false);

const toggleSidebar = useCallback(() => {
setSidebarOpen((prev) => !prev);
}, []);

return (
<SidebarContext.Provider value={{ sidebarOpen, setSidebarOpen }}>
<SidebarContext.Provider
value={{ sidebarOpen, setSidebarOpen, toggleSidebar }}
>
{children}
</SidebarContext.Provider>
);
Expand Down
Loading