move toolbar to lumpprovider

This commit is contained in:
Patrick Erichsen 2025-04-04 13:52:41 -07:00
parent e88485348c
commit 8bdcb16140
5 changed files with 35 additions and 25 deletions

View file

@ -9,11 +9,10 @@ import {
WrenchScrewdriverIcon,
} from "@heroicons/react/24/outline";
import { vscBadgeBackground, vscBadgeForeground } from "../..";
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
import { toggleBlockSettingsToolbar } from "../../../redux/slices/uiSlice";
import { fontSize } from "../../../util";
import AssistantSelect from "../../modelSelection/platform/AssistantSelect";
import HoverItem from "../InputToolbar/HoverItem";
import { useLump } from "./LumpContext";
interface BlockSettingsToolbarIcon {
tooltip: string;
@ -87,15 +86,13 @@ interface BlockSettingsTopToolbarProps {
}
export function BlockSettingsTopToolbar(props: BlockSettingsTopToolbarProps) {
const isExpanded = useAppSelector(
(state) => state.ui.isBlockSettingsToolbarExpanded,
);
const dispatch = useAppDispatch();
const { isToolbarExpanded, toggleToolbar } = useLump();
const handleEllipsisClick = () => {
if (isExpanded) {
if (isToolbarExpanded) {
props.setSelectedSection(null);
}
dispatch(toggleBlockSettingsToolbar());
toggleToolbar();
};
return (
@ -103,14 +100,14 @@ export function BlockSettingsTopToolbar(props: BlockSettingsTopToolbarProps) {
<div className="xs:flex hidden items-center justify-center text-gray-400">
<BlockSettingsToolbarIcon
className="-ml-1.5"
icon={isExpanded ? ChevronLeftIcon : EllipsisHorizontalIcon}
tooltip={isExpanded ? "Collapse sections" : "Expand sections"}
icon={isToolbarExpanded ? ChevronLeftIcon : EllipsisHorizontalIcon}
tooltip={isToolbarExpanded ? "Collapse sections" : "Expand sections"}
isSelected={false}
onClick={handleEllipsisClick}
/>
<div
className="flex overflow-hidden transition-all duration-200"
style={{ width: isExpanded ? `160px` : "0px" }}
style={{ width: isToolbarExpanded ? `160px` : "0px" }}
>
<div className="flex">
{sections.map((section) => (

View file

@ -6,8 +6,10 @@ import { createContext, ReactNode, useContext } from "react";
interface LumpContextType {
isLumpVisible: boolean;
selectedSection: string | null;
isToolbarExpanded: boolean;
hideLump: () => void;
setSelectedSection: (section: string | null) => void;
toggleToolbar: () => void;
}
const LumpContext = createContext<LumpContextType | undefined>(undefined);
@ -16,8 +18,10 @@ interface LumpProviderProps {
children: ReactNode;
isLumpVisible: boolean;
selectedSection: string | null;
isToolbarExpanded: boolean;
hideLump: () => void;
setSelectedSection: (section: string | null) => void;
toggleToolbar: () => void;
}
/**
@ -27,12 +31,21 @@ export function LumpProvider({
children,
isLumpVisible,
selectedSection,
isToolbarExpanded,
hideLump,
setSelectedSection,
toggleToolbar,
}: LumpProviderProps) {
return (
<LumpContext.Provider
value={{ isLumpVisible, selectedSection, hideLump, setSelectedSection }}
value={{
isLumpVisible,
selectedSection,
isToolbarExpanded,
hideLump,
setSelectedSection,
toggleToolbar,
}}
>
{children}
</LumpContext.Provider>

View file

@ -38,6 +38,7 @@ export function Lump() {
const [selectedSection, setSelectedSection] = useState<string | null>(null);
const [displayedSection, setDisplayedSection] = useState<string | null>(null);
const [isVisible, setIsVisible] = useState(false);
const [isToolbarExpanded, setIsToolbarExpanded] = useState(true);
const isStreaming = useAppSelector((state) => state.session.isStreaming);
// Handle keyboard escape
@ -55,6 +56,11 @@ export function Lump() {
setSelectedSection(null);
}, []);
// Function to toggle toolbar expanded state
const toggleToolbar = useCallback(() => {
setIsToolbarExpanded((prev) => !prev);
}, []);
// Reset when streaming starts
if (isStreaming && selectedSection) {
setSelectedSection(null);
@ -84,8 +90,10 @@ export function Lump() {
<LumpProvider
isLumpVisible={isVisible}
selectedSection={selectedSection}
isToolbarExpanded={isToolbarExpanded}
hideLump={hideLump}
setSelectedSection={setSelectedSection}
toggleToolbar={toggleToolbar}
>
<LumpDiv>
<div className="mt-0.5 px-2">

View file

@ -11,7 +11,7 @@ import { useContext, useEffect, useMemo, useRef } from "react";
import { useAuth } from "../../../context/Auth";
import { IdeMessengerContext } from "../../../context/IdeMessenger";
import { cycleProfile, selectProfileThunk } from "../../../redux";
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
import { useAppDispatch } from "../../../redux/hooks";
import {
fontSize,
getMetaKeyLabel,
@ -31,6 +31,7 @@ import { useNavigate } from "react-router-dom";
import { vscCommandCenterInactiveBorder } from "../..";
import { ROUTES } from "../../../util/navigation";
import { ToolTip } from "../../gui/Tooltip";
import { useLump } from "../../mainInput/Lump/LumpContext";
import { useFontSize } from "../../ui/font";
import AssistantIcon from "./AssistantIcon";
@ -143,9 +144,7 @@ export default function AssistantSelect() {
const buttonRef = useRef<HTMLButtonElement>(null);
const { selectedProfile, selectedOrganization } = useAuth();
const ideMessenger = useContext(IdeMessengerContext);
const isLumpToolbarExpanded = useAppSelector(
(state) => state.ui.isBlockSettingsToolbarExpanded,
);
const { isToolbarExpanded } = useLump();
const { profiles, session, login } = useAuth();
const navigate = useNavigate();
@ -205,7 +204,7 @@ export default function AssistantSelect() {
>
<PlusIcon className="h-3 w-3 flex-shrink-0 select-none" />
<span
className={`line-clamp-1 select-none ${isLumpToolbarExpanded ? "xs:hidden sm:line-clamp-1" : ""}`}
className={`line-clamp-1 select-none ${isToolbarExpanded ? "xs:hidden sm:line-clamp-1" : ""}`}
>
Create your first assistant
</span>
@ -227,7 +226,7 @@ export default function AssistantSelect() {
<AssistantIcon size={3} assistant={selectedProfile} />
</div>
<span
className={`line-clamp-1 select-none ${isLumpToolbarExpanded ? "xs:hidden sm:line-clamp-1" : ""}`}
className={`line-clamp-1 select-none ${isToolbarExpanded ? "xs:hidden sm:line-clamp-1" : ""}`}
>
{selectedProfile.title}
</span>

View file

@ -25,7 +25,6 @@ type UIState = {
toolSettings: { [toolName: string]: ToolSetting };
toolGroupSettings: { [toolGroupName: string]: ToolGroupSetting };
ttsActive: boolean;
isBlockSettingsToolbarExpanded: boolean;
};
export const DEFAULT_TOOL_SETTING: ToolSetting = "allowedWithPermission";
@ -56,7 +55,6 @@ export const uiSlice = createSlice({
toolGroupSettings: {
BUILT_IN_GROUP_NAME: "include",
},
isBlockSettingsToolbarExpanded: true,
} as UIState,
reducers: {
setOnboardingCard: (
@ -124,10 +122,6 @@ export const uiSlice = createSlice({
setTTSActive: (state, { payload }: PayloadAction<boolean>) => {
state.ttsActive = payload;
},
toggleBlockSettingsToolbar: (state) => {
state.isBlockSettingsToolbarExpanded =
!state.isBlockSettingsToolbarExpanded;
},
},
});
@ -142,7 +136,6 @@ export const {
toggleToolGroupSetting,
addTool,
setTTSActive,
toggleBlockSettingsToolbar,
} = uiSlice.actions;
export default uiSlice.reducer;