fix(webui): refine mobile actions and avoid duplicate settings loads
This commit is contained in:
1 parent
f8d655d612
commit
c370e2a5a5
6 files changed
+50
-8
No files matched your search
@@ -1175,6 +1175,7 @@ function Shell({
|
|||||||
const skills = useSkills(getToken);
|
const skills = useSkills(getToken);
|
||||||
const pageVisible = usePageVisibility();
|
const pageVisible = usePageVisibility();
|
||||||
const [settingsSnapshot, setSettingsSnapshot] = useState<SettingsPayload | null>(null);
|
const [settingsSnapshot, setSettingsSnapshot] = useState<SettingsPayload | null>(null);
|
||||||
|
const [settingsLoading, setSettingsLoading] = useState(true);
|
||||||
const settingsRefreshGenerationRef = useRef(0);
|
const settingsRefreshGenerationRef = useRef(0);
|
||||||
const [pendingAutomationMessage, setPendingAutomationMessage] = useState<{
|
const [pendingAutomationMessage, setPendingAutomationMessage] = useState<{
|
||||||
id: string;
|
id: string;
|
||||||
@@ -1298,6 +1299,7 @@ function Shell({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
const requestGeneration = settingsRefreshGenerationRef.current;
|
const requestGeneration = settingsRefreshGenerationRef.current;
|
||||||
|
setSettingsLoading(true);
|
||||||
fetchSettings(getToken())
|
fetchSettings(getToken())
|
||||||
.then((payload) => {
|
.then((payload) => {
|
||||||
if (!cancelled && requestGeneration === settingsRefreshGenerationRef.current) {
|
if (!cancelled && requestGeneration === settingsRefreshGenerationRef.current) {
|
||||||
@@ -1308,6 +1310,9 @@ function Shell({
|
|||||||
if (!cancelled && requestGeneration === settingsRefreshGenerationRef.current) {
|
if (!cancelled && requestGeneration === settingsRefreshGenerationRef.current) {
|
||||||
setSettingsSnapshot(null);
|
setSettingsSnapshot(null);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
if (!cancelled) setSettingsLoading(false);
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
@@ -2906,6 +2911,7 @@ function Shell({
|
|||||||
workspaceError={workspaceError}
|
workspaceError={workspaceError}
|
||||||
onWorkspaceScopeChange={applyWorkspaceScope}
|
onWorkspaceScopeChange={applyWorkspaceScope}
|
||||||
settingsSnapshot={settingsSnapshot}
|
settingsSnapshot={settingsSnapshot}
|
||||||
|
settingsLoading={settingsLoading}
|
||||||
onOpenModelSettings={onOpenModelSettings}
|
onOpenModelSettings={onOpenModelSettings}
|
||||||
skills={skills}
|
skills={skills}
|
||||||
/>
|
/>
|
||||||
@@ -2968,6 +2974,7 @@ function Shell({
|
|||||||
client.setWorkspaceScope(paneSession.chatId, next);
|
client.setWorkspaceScope(paneSession.chatId, next);
|
||||||
}}
|
}}
|
||||||
settingsSnapshot={settingsSnapshot}
|
settingsSnapshot={settingsSnapshot}
|
||||||
|
settingsLoading={settingsLoading}
|
||||||
onOpenModelSettings={onOpenModelSettings}
|
onOpenModelSettings={onOpenModelSettings}
|
||||||
skills={skills}
|
skills={skills}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ export function MessageBlockMenuActions({
|
|||||||
"text-start text-[11px] leading-4",
|
"text-start text-[11px] leading-4",
|
||||||
"text-muted-foreground transition-colors hover:text-foreground",
|
"text-muted-foreground transition-colors hover:text-foreground",
|
||||||
"focus-visible:outline-none",
|
"focus-visible:outline-none",
|
||||||
sheet && "w-full rounded-control text-sm hover:bg-muted/70",
|
sheet && "w-full gap-2 rounded-control px-2 text-sm hover:bg-muted/70",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
@@ -260,6 +260,7 @@ export function MessageBlockMenuActions({
|
|||||||
"group-hover:bg-muted/70 group-active:scale-[0.96]",
|
"group-hover:bg-muted/70 group-active:scale-[0.96]",
|
||||||
"group-focus-visible:ring-2 group-focus-visible:ring-ring",
|
"group-focus-visible:ring-2 group-focus-visible:ring-ring",
|
||||||
"motion-reduce:transform-none",
|
"motion-reduce:transform-none",
|
||||||
|
sheet && "w-3.5",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Activity className="h-3.5 w-3.5" strokeWidth={1.5} aria-hidden />
|
<Activity className="h-3.5 w-3.5" strokeWidth={1.5} aria-hidden />
|
||||||
@@ -281,7 +282,7 @@ export function MessageBlockMenuActions({
|
|||||||
{timestampLabel || automationSourceLabel ? (
|
{timestampLabel || automationSourceLabel ? (
|
||||||
<div
|
<div
|
||||||
data-message-block-metadata
|
data-message-block-metadata
|
||||||
className={cn("mt-0.5 w-full border-t border-border/45 px-1.5 pt-1 leading-4", sheet ? "text-xs text-muted-foreground" : "text-[10px] text-muted-foreground/45")}
|
className={cn("mt-0.5 w-full border-t border-border/45 px-1.5 pt-1 leading-4", sheet ? "px-2 text-xs text-muted-foreground" : "text-[10px] text-muted-foreground/45")}
|
||||||
>
|
>
|
||||||
{timestampLabel ? (
|
{timestampLabel ? (
|
||||||
<time
|
<time
|
||||||
|
|||||||
@@ -432,12 +432,12 @@ function MessageBlockMenu({
|
|||||||
onViewLinks={links.length > 0 ? () => setLinksShown(true) : undefined}
|
onViewLinks={links.length > 0 ? () => setLinksShown(true) : undefined}
|
||||||
/>;
|
/>;
|
||||||
if (mobileActions) {
|
if (mobileActions) {
|
||||||
return <div data-message-mobile-actions className={cn("mt-1 flex items-center gap-0.5", message.role === "user" && "justify-end")}>
|
return <div data-message-mobile-actions className={cn("mt-1 flex items-center", message.role === "user" ? "me-2 justify-end" : "-ms-2")}>
|
||||||
<MessageCopyButton message={message} className="h-11 w-11" />
|
<MessageCopyButton message={message} className="h-11 w-8 [&_svg]:h-4 [&_svg]:w-4" />
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<button ref={triggerRef} type="button" data-message-block-menu-trigger aria-label={label}
|
<button ref={triggerRef} type="button" data-message-block-menu-trigger aria-label={label}
|
||||||
className="inline-flex h-11 w-11 items-center justify-center rounded-control text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
className="inline-flex h-11 w-8 items-center justify-center rounded-control text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
||||||
<MoreHorizontal className="h-4 w-4" strokeWidth={1.75} aria-hidden />
|
<MoreHorizontal className="h-4 w-4" strokeWidth={1.75} aria-hidden />
|
||||||
</button>
|
</button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
|
|||||||
@@ -447,6 +447,7 @@ interface ThreadShellProps {
|
|||||||
workspaceError?: string | null;
|
workspaceError?: string | null;
|
||||||
onWorkspaceScopeChange?: (scope: WorkspaceScopePayload) => void;
|
onWorkspaceScopeChange?: (scope: WorkspaceScopePayload) => void;
|
||||||
settingsSnapshot?: SettingsPayload | null;
|
settingsSnapshot?: SettingsPayload | null;
|
||||||
|
settingsLoading?: boolean;
|
||||||
onOpenModelSettings?: () => void;
|
onOpenModelSettings?: () => void;
|
||||||
skills?: SkillSummary[];
|
skills?: SkillSummary[];
|
||||||
}
|
}
|
||||||
@@ -657,6 +658,7 @@ export function ThreadShell({
|
|||||||
workspaceError = null,
|
workspaceError = null,
|
||||||
onWorkspaceScopeChange,
|
onWorkspaceScopeChange,
|
||||||
settingsSnapshot = null,
|
settingsSnapshot = null,
|
||||||
|
settingsLoading = false,
|
||||||
onOpenModelSettings,
|
onOpenModelSettings,
|
||||||
skills = [],
|
skills = [],
|
||||||
}: ThreadShellProps) {
|
}: ThreadShellProps) {
|
||||||
@@ -1094,8 +1096,8 @@ export function ThreadShell({
|
|||||||
setSettings(settingsSnapshot);
|
setSettings(settingsSnapshot);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void refreshModelSettings();
|
if (!settingsLoading) void refreshModelSettings();
|
||||||
}, [refreshModelSettings, settingsSnapshot]);
|
}, [refreshModelSettings, settingsLoading, settingsSnapshot]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return client.onRuntimeModelUpdate(() => {
|
return client.onRuntimeModelUpdate(() => {
|
||||||
|
|||||||
@@ -312,6 +312,7 @@ export function WorkspaceAccessMenu({
|
|||||||
onChange?: (scope: WorkspaceScopePayload) => void;
|
onChange?: (scope: WorkspaceScopePayload) => void;
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const dismissedByPointerRef = useRef(false);
|
||||||
const mode = scope.access_mode;
|
const mode = scope.access_mode;
|
||||||
const isFull = mode === "full";
|
const isFull = mode === "full";
|
||||||
const accessLabel = t(
|
const accessLabel = t(
|
||||||
@@ -358,7 +359,15 @@ export function WorkspaceAccessMenu({
|
|||||||
<ChevronDown className={cn("thread-composer-access-chevron ml-1.5 shrink-0", isHero ? "h-3 w-3" : "h-3 w-3")} />
|
<ChevronDown className={cn("thread-composer-access-chevron ml-1.5 shrink-0", isHero ? "h-3 w-3" : "h-3 w-3")} />
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="start" className="w-56">
|
<DropdownMenuContent
|
||||||
|
align="start"
|
||||||
|
className="w-56"
|
||||||
|
onPointerDownOutside={() => { dismissedByPointerRef.current = true; }}
|
||||||
|
onCloseAutoFocus={(event) => {
|
||||||
|
if (dismissedByPointerRef.current) event.preventDefault();
|
||||||
|
dismissedByPointerRef.current = false;
|
||||||
|
}}
|
||||||
|
>
|
||||||
<AccessMenuItem
|
<AccessMenuItem
|
||||||
icon={<Hand className="h-4 w-4" />}
|
icon={<Hand className="h-4 w-4" />}
|
||||||
label={t("thread.composer.workspace.default")}
|
label={t("thread.composer.workspace.default")}
|
||||||
|
|||||||
@@ -935,6 +935,29 @@ describe("ThreadShell", () => {
|
|||||||
expect(onGoHome).not.toHaveBeenCalled();
|
expect(onGoHome).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each([true, false])("waits for parent settings and retries only on failure (success: %s)", async (success) => {
|
||||||
|
const client = makeClient();
|
||||||
|
const settings = modelSettings("deepseek-v4-pro", "deepseek");
|
||||||
|
const settingsRequest = vi.fn(() => Promise.resolve(httpJson(settings)));
|
||||||
|
vi.stubGlobal("fetch", vi.fn((input: RequestInfo | URL) => (
|
||||||
|
String(input).endsWith("/api/settings")
|
||||||
|
? settingsRequest()
|
||||||
|
: Promise.resolve(httpJson({}))
|
||||||
|
)));
|
||||||
|
const view = (loading: boolean, snapshot: SettingsPayload | null) => wrap(
|
||||||
|
client,
|
||||||
|
<ThreadShell session={null} title="New topic" onToggleSidebar={() => {}}
|
||||||
|
settingsLoading={loading} settingsSnapshot={snapshot} />,
|
||||||
|
);
|
||||||
|
const { rerender } = render(view(true, null));
|
||||||
|
await act(async () => {});
|
||||||
|
expect(settingsRequest).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
rerender(view(false, success ? settings : null));
|
||||||
|
expect(await screen.findByTestId("composer-model-logo-deepseek")).toBeInTheDocument();
|
||||||
|
expect(settingsRequest).toHaveBeenCalledTimes(success ? 0 : 1);
|
||||||
|
});
|
||||||
|
|
||||||
it("updates the composer model logo when settings snapshot changes", async () => {
|
it("updates the composer model logo when settings snapshot changes", async () => {
|
||||||
const client = makeClient();
|
const client = makeClient();
|
||||||
const { rerender } = render(
|
const { rerender } = render(
|
||||||
|
|||||||
Reference in new issue
Block a user