configLoading redux state
on initial load, login and manual config refresh show the loading indicator
This commit is contained in:
parent
da28644fb7
commit
afb36cdbfd
4 changed files with 23 additions and 20 deletions
|
|
@ -7,7 +7,7 @@ import {
|
|||
ExclamationTriangleIcon,
|
||||
PlusIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useContext, useEffect, useMemo, useRef } from "react";
|
||||
import { useAuth } from "../../../context/Auth";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import {
|
||||
|
|
@ -32,7 +32,6 @@ import {
|
|||
|
||||
import type { ProfileDescription } from "core/config/ConfigHandler";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useWebviewListener } from "../../../hooks/useWebviewListener";
|
||||
import { cn } from "../../../util/cn";
|
||||
import { ROUTES } from "../../../util/navigation";
|
||||
import { useLump } from "../../mainInput/Lump/LumpContext";
|
||||
|
|
@ -156,7 +155,7 @@ export default function AssistantSelect() {
|
|||
const orgs = useAppSelector((store) => store.profiles.organizations);
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const { isToolbarExpanded } = useLump();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const configLoading = useAppSelector((store) => store.config.loading);
|
||||
const { profiles, session, login, selectedProfile, refreshProfiles } =
|
||||
useAuth();
|
||||
|
||||
|
|
@ -172,11 +171,6 @@ export default function AssistantSelect() {
|
|||
});
|
||||
close();
|
||||
}
|
||||
async function refreshProfilesWithLoading() {
|
||||
setLoading(true);
|
||||
await refreshProfiles();
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
let lastToggleTime = 0;
|
||||
|
|
@ -219,8 +213,6 @@ export default function AssistantSelect() {
|
|||
};
|
||||
}, [currentOrg, selectedProfile]);
|
||||
|
||||
useWebviewListener("sessionUpdate", refreshProfilesWithLoading, []);
|
||||
|
||||
const cycleOrgs = () => {
|
||||
if (!session) {
|
||||
void login(false);
|
||||
|
|
@ -279,7 +271,7 @@ export default function AssistantSelect() {
|
|||
style={{ fontSize: fontSize(-3) }}
|
||||
>
|
||||
<div className="flex flex-row items-center gap-1.5">
|
||||
{!loading ? (
|
||||
{configLoading ? (
|
||||
<span className="select-none">loading...</span>
|
||||
) : (
|
||||
<>
|
||||
|
|
@ -306,17 +298,15 @@ export default function AssistantSelect() {
|
|||
<span className="font-semibold">Assistants</span>
|
||||
<div
|
||||
className="flex cursor-pointer flex-row items-center gap-1 hover:brightness-125"
|
||||
onClick={async (e) => {
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
void refreshProfilesWithLoading().then(() =>
|
||||
buttonRef.current?.click(),
|
||||
);
|
||||
void refreshProfiles().then(() => buttonRef.current?.click());
|
||||
}}
|
||||
>
|
||||
<ArrowPathIcon
|
||||
className={cn(
|
||||
"text-description h-2.5 w-2.5",
|
||||
!loading && "animate-spin-slow",
|
||||
configLoading && "animate-spin-slow",
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import {
|
|||
setSelectedOrgId,
|
||||
} from "../redux/";
|
||||
import { useAppDispatch, useAppSelector } from "../redux/hooks";
|
||||
import { setConfigLoading } from "../redux/slices/configSlice";
|
||||
import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice";
|
||||
import { IdeMessengerContext } from "./IdeMessenger";
|
||||
|
||||
|
|
@ -53,7 +54,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
|
||||
const login: AuthContextType["login"] = (useOnboarding: boolean) => {
|
||||
return new Promise((resolve) => {
|
||||
ideMessenger
|
||||
void ideMessenger
|
||||
.request("getControlPlaneSessionInfo", {
|
||||
silent: false,
|
||||
useOnboarding,
|
||||
|
|
@ -113,17 +114,21 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||
"sessionUpdate",
|
||||
async (data) => {
|
||||
setSession(data.sessionInfo);
|
||||
void refreshProfiles();
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const refreshProfiles = useCallback(async () => {
|
||||
try {
|
||||
dispatch(setConfigLoading(true));
|
||||
await ideMessenger.request("config/refreshProfiles", undefined);
|
||||
ideMessenger.post("showToast", ["info", "Config refreshed"]);
|
||||
} catch (e) {
|
||||
console.error("Failed to refresh profiles", e);
|
||||
ideMessenger.post("showToast", ["error", "Failed to refresh config"]);
|
||||
} finally {
|
||||
dispatch(setConfigLoading(false));
|
||||
}
|
||||
}, [ideMessenger]);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import {
|
|||
} from "../redux";
|
||||
import { useAppDispatch, useAppSelector } from "../redux/hooks";
|
||||
import { selectCurrentToolCallApplyState } from "../redux/selectors/selectCurrentToolCall";
|
||||
import { setConfigResult } from "../redux/slices/configSlice";
|
||||
import { setConfigLoading, setConfigResult } from "../redux/slices/configSlice";
|
||||
import {
|
||||
setLastNonEditSessionEmpty,
|
||||
updateEditStateApplyState,
|
||||
|
|
@ -93,6 +93,7 @@ function ParallelListeners() {
|
|||
|
||||
const initialLoadAuthAndConfig = useCallback(
|
||||
async (initial: boolean) => {
|
||||
dispatch(setConfigLoading(true));
|
||||
const result = await ideMessenger.request(
|
||||
"config/getSerializedProfileInfo",
|
||||
undefined,
|
||||
|
|
@ -100,6 +101,7 @@ function ParallelListeners() {
|
|||
if (result.status === "success") {
|
||||
await handleConfigUpdate(initial, result.content);
|
||||
}
|
||||
dispatch(setConfigLoading(false));
|
||||
},
|
||||
[ideMessenger, handleConfigUpdate],
|
||||
);
|
||||
|
|
@ -242,7 +244,7 @@ function ParallelListeners() {
|
|||
dispatch(updateEditStateApplyState(state));
|
||||
|
||||
if (state.status === "closed") {
|
||||
dispatch(exitEdit({}));
|
||||
void dispatch(exitEdit({}));
|
||||
}
|
||||
} else {
|
||||
// chat or agent
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { DEFAULT_MAX_TOKENS } from "core/llm/constants";
|
|||
export type ConfigState = {
|
||||
configError: ConfigValidationError[] | undefined;
|
||||
config: BrowserSerializedContinueConfig;
|
||||
loading: boolean;
|
||||
};
|
||||
|
||||
export const EMPTY_CONFIG: BrowserSerializedContinueConfig = {
|
||||
|
|
@ -47,6 +48,7 @@ export const EMPTY_CONFIG: BrowserSerializedContinueConfig = {
|
|||
const initialState: ConfigState = {
|
||||
configError: undefined,
|
||||
config: EMPTY_CONFIG,
|
||||
loading: false,
|
||||
};
|
||||
|
||||
export const configSlice = createSlice({
|
||||
|
|
@ -82,6 +84,9 @@ export const configSlice = createSlice({
|
|||
) => {
|
||||
state.config = config;
|
||||
},
|
||||
setConfigLoading: (state, { payload: loading }: PayloadAction<boolean>) => {
|
||||
state.loading = loading;
|
||||
},
|
||||
},
|
||||
selectors: {
|
||||
selectSelectedChatModelContextLength: (state): number => {
|
||||
|
|
@ -99,7 +104,8 @@ export const configSlice = createSlice({
|
|||
},
|
||||
});
|
||||
|
||||
export const { updateConfig, setConfigResult } = configSlice.actions;
|
||||
export const { updateConfig, setConfigResult, setConfigLoading } =
|
||||
configSlice.actions;
|
||||
|
||||
export const {
|
||||
selectSelectedChatModelContextLength,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue