use thunks for cycling profile id
This commit is contained in:
parent
185f0c5c79
commit
80f1c11d8d
6 changed files with 44 additions and 26 deletions
|
|
@ -1,17 +1,16 @@
|
|||
import { Popover } from "@headlessui/react";
|
||||
import { ChevronDownIcon } from "@heroicons/react/24/outline";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
import { defaultBorderRadius, lightGray, vscInputBackground } from "../..";
|
||||
import AddModelForm from "../../../forms/AddModelForm";
|
||||
import { useAppSelector } from "../../../redux/hooks";
|
||||
import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
|
||||
import {
|
||||
cycleDefaultModel,
|
||||
selectDefaultModel,
|
||||
} from "../../../redux/slices/configSlice";
|
||||
import { cycleSelectedProfileId } from "../../../redux/slices/sessionSlice";
|
||||
import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice";
|
||||
import { cycleProfile } from "../../../redux/thunks/cycleProfile";
|
||||
import { getFontSize, isMetaEquivalentKeyPressed } from "../../../util";
|
||||
import PopoverTransition from "../../mainInput/InputToolbar/PopoverTransition";
|
||||
import { AssistantSelect } from "./AssistantSelect";
|
||||
|
|
@ -50,7 +49,7 @@ const StyledPopoverPanel = styled(Popover.Panel)<{ $showabove: boolean }>`
|
|||
`;
|
||||
|
||||
function AssistantAndModelSelect() {
|
||||
const dispatch = useDispatch();
|
||||
const dispatch = useAppDispatch();
|
||||
const defaultModel = useAppSelector(selectDefaultModel);
|
||||
const [showAbove, setShowAbove] = useState(false);
|
||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||
|
|
@ -76,7 +75,7 @@ function AssistantAndModelSelect() {
|
|||
setShowAbove(spaceBelow < dropdownHeight && spaceAbove > spaceBelow);
|
||||
}
|
||||
|
||||
function onClickAddModel(e) {
|
||||
function onClickAddModel(e: any) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
|
|
@ -108,7 +107,7 @@ function AssistantAndModelSelect() {
|
|||
dispatch(cycleDefaultModel("next"));
|
||||
} else {
|
||||
if (now - lastToggleTime >= DEBOUNCE_MS) {
|
||||
dispatch(cycleSelectedProfileId());
|
||||
dispatch(cycleProfile());
|
||||
lastToggleTime = now;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ import {
|
|||
SparklesIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { useContext } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { lightGray } from "../..";
|
||||
import { useAuth } from "../../../context/Auth";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { setSelectedProfileId } from "../../../redux/slices/sessionSlice";
|
||||
import { useAppDispatch } from "../../../redux/hooks";
|
||||
import { setProfileId } from "../../../redux/thunks/setProfileId";
|
||||
import { getFontSize, getMetaKeyLabel } from "../../../util";
|
||||
import { Divider, Option, OptionDiv } from "./shared";
|
||||
|
||||
|
|
@ -18,12 +18,7 @@ export function AssistantSelect(props: AssistantSelectProps) {
|
|||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const { profiles, selectedProfile } = useAuth();
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const changeProfileId = (id: string) => {
|
||||
ideMessenger.post("didChangeSelectedProfile", { id });
|
||||
dispatch(setSelectedProfileId(id));
|
||||
};
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
function onNewAssistant() {
|
||||
ideMessenger.post("openUrl", "https://app.continue.dev/new");
|
||||
|
|
@ -45,7 +40,7 @@ export function AssistantSelect(props: AssistantSelectProps) {
|
|||
profileId: option.id,
|
||||
});
|
||||
}}
|
||||
onClick={() => changeProfileId(option.id)}
|
||||
onClick={() => dispatch(setProfileId(option.id))}
|
||||
>
|
||||
<div className="flex flex-grow items-center">
|
||||
{option.id === "local" ? (
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ export function Option({
|
|||
}: ModelOptionProps) {
|
||||
const [hovered, setHovered] = useState(false);
|
||||
|
||||
function handleOptionClick(e) {
|
||||
function handleOptionClick(e: any) {
|
||||
if (disabled) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
|
|
|||
|
|
@ -485,15 +485,6 @@ export const sessionSlice = createSlice({
|
|||
selectedProfileId: payload,
|
||||
};
|
||||
},
|
||||
cycleSelectedProfileId: (state) => {
|
||||
const profileIds = state.availableProfiles.map((profile) => profile.id);
|
||||
const curIndex = profileIds.indexOf(state.selectedProfileId);
|
||||
const nextIndex = (curIndex + 1) % profileIds.length;
|
||||
return {
|
||||
...state,
|
||||
selectedProfileId: profileIds[nextIndex],
|
||||
};
|
||||
},
|
||||
setAvailableProfiles: (
|
||||
state,
|
||||
{ payload }: PayloadAction<ProfileDescription[]>,
|
||||
|
|
@ -688,7 +679,6 @@ export const {
|
|||
removeCodeToEdit,
|
||||
setCalling,
|
||||
cancelToolCall,
|
||||
cycleSelectedProfileId,
|
||||
setAvailableProfiles,
|
||||
acceptToolCall,
|
||||
setToolGenerated,
|
||||
|
|
|
|||
21
gui/src/redux/thunks/cycleProfile.ts
Normal file
21
gui/src/redux/thunks/cycleProfile.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { ThunkApiType } from "../store";
|
||||
import { setProfileId } from "./setProfileId";
|
||||
|
||||
export const cycleProfile = createAsyncThunk<void, undefined, ThunkApiType>(
|
||||
"profile/cycle",
|
||||
async (_, { dispatch, getState, extra }) => {
|
||||
const state = getState();
|
||||
const profileIds = state.session.availableProfiles.map(
|
||||
(profile) => profile.id,
|
||||
);
|
||||
const curIndex = profileIds.indexOf(state.session.selectedProfileId);
|
||||
const nextIndex = (curIndex + 1) % profileIds.length;
|
||||
const nextId = profileIds[nextIndex];
|
||||
dispatch(setProfileId(nextId));
|
||||
|
||||
extra.ideMessenger.post("didChangeSelectedProfile", {
|
||||
id: nextId,
|
||||
});
|
||||
},
|
||||
);
|
||||
13
gui/src/redux/thunks/setProfileId.ts
Normal file
13
gui/src/redux/thunks/setProfileId.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { setSelectedProfileId } from "../slices/sessionSlice";
|
||||
import { ThunkApiType } from "../store";
|
||||
|
||||
export const setProfileId = createAsyncThunk<void, string, ThunkApiType>(
|
||||
"profile/setId",
|
||||
async (id, { dispatch, extra }) => {
|
||||
dispatch(setSelectedProfileId(id));
|
||||
extra.ideMessenger.post("didChangeSelectedProfile", {
|
||||
id,
|
||||
});
|
||||
},
|
||||
);
|
||||
Loading…
Add table
Reference in a new issue