Skip to content

Commit e79a538

Browse files
committed
fix(client): compact usage-limit recovery actions
1 parent d6912e5 commit e79a538

5 files changed

Lines changed: 78 additions & 49 deletions

File tree

‎apps/mobile/src/features/threads/UsageLimitRecoveryCard.test.tsx‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@ import { act } from "react";
55
import { createRoot } from "react-dom/client";
66
import { describe, expect, it, vi } from "vite-plus/test";
77

8-
type ButtonProps = { label: string; disabled?: boolean; onPress: () => void };
8+
type PressableProps = { children: ReactNode; disabled?: boolean; onPress: () => void };
99

1010
vi.mock("react-native", () => ({
1111
View: ({ children }: { children: ReactNode }) => <div>{children}</div>,
12-
}));
13-
vi.mock("../../components/ui/AppText", () => ({
14-
AppText: ({ children }: { children: ReactNode }) => <span>{children}</span>,
15-
}));
16-
vi.mock("../../components/ui/Button", () => ({
17-
Button: ({ label, disabled, onPress }: ButtonProps) => (
12+
Pressable: ({ children, disabled, onPress }: PressableProps) => (
1813
<button type="button" disabled={disabled} onClick={onPress}>
19-
{label}
14+
{children}
2015
</button>
2116
),
2217
}));
18+
vi.mock("../../components/ui/AppText", () => ({
19+
AppText: ({ children }: { children: ReactNode }) => <span>{children}</span>,
20+
}));
2321
vi.mock("../../state/threads", () => ({ threadEnvironment: { updateMetadata: {} } }));
2422
vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => vi.fn() }));
2523

‎apps/mobile/src/features/threads/UsageLimitRecoveryCard.tsx‎

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { Button } from "../../components/ui/Button";
21
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
32
import { AsyncResult } from "effect/reactivity";
43
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
54
import { limitRecoveryOwnsSnooze } from "@t3tools/client-runtime/state/thread-execution";
65
import type { EnvironmentId } from "@t3tools/contracts";
76
import { useState } from "react";
8-
import { View } from "react-native";
7+
import { Pressable, View } from "react-native";
98
import { AppText as Text } from "../../components/ui/AppText";
109
import { useDeadlinePassed } from "../../lib/clock";
1110
import { threadEnvironment } from "../../state/threads";
@@ -78,34 +77,34 @@ export function UsageLimitRecoveryCard({
7877
}
7978
return (
8079
<View className="mx-3 mb-2 gap-2 rounded-xl border border-warning-foreground/25 bg-screen p-3">
81-
<Text className="text-sm text-warning-foreground">
82-
{displayAt
83-
? `Usage limit reached. ${canSchedule && scheduled ? "Resumes" : "Resets"} ${new Date(
84-
displayAt,
85-
).toLocaleString(undefined, {
86-
month: "short",
87-
day: "numeric",
88-
hour: "numeric",
89-
minute: "2-digit",
90-
})}.`
91-
: "Usage limit reached. The provider did not report a reset time. Retry manually when your limit is available."}
92-
</Text>
93-
{canSchedule ? (
94-
<View className="flex-row flex-wrap gap-2">
95-
<Button
96-
label={scheduled ? "Cancel auto-resume" : "Resume at reset"}
97-
tone="secondary"
98-
disabled={pending}
99-
onPress={() => void toggle("resume")}
100-
/>
101-
<Button
102-
label={snoozed ? "Wake now" : "Snooze until reset"}
103-
tone="secondary"
104-
disabled={pending || (!snoozed && resetPassed)}
105-
onPress={() => void toggle("snooze")}
106-
/>
107-
</View>
108-
) : null}
80+
<View className="flex-row flex-wrap items-baseline gap-x-4 gap-y-2">
81+
<Text className="shrink text-sm text-warning-foreground">
82+
{displayAt
83+
? `Usage limit reached. ${canSchedule && scheduled ? "Resumes" : "Resets"} ${new Date(
84+
displayAt,
85+
).toLocaleString(undefined, {
86+
month: "short",
87+
day: "numeric",
88+
hour: "numeric",
89+
minute: "2-digit",
90+
})}.`
91+
: "Usage limit reached. The provider did not report a reset time. Retry manually when your limit is available."}
92+
</Text>
93+
{canSchedule ? (
94+
<>
95+
<RecoveryAction
96+
label={scheduled ? "Cancel auto-resume" : "Resume at reset"}
97+
disabled={pending}
98+
onPress={() => void toggle("resume")}
99+
/>
100+
<RecoveryAction
101+
label={snoozed ? "Wake now" : "Snooze until reset"}
102+
disabled={pending || (!snoozed && resetPassed)}
103+
onPress={() => void toggle("snooze")}
104+
/>
105+
</>
106+
) : null}
107+
</View>
109108
{error ? (
110109
<Text accessibilityRole="alert" className="text-sm text-destructive">
111110
{error}
@@ -114,3 +113,30 @@ export function UsageLimitRecoveryCard({
114113
</View>
115114
);
116115
}
116+
117+
function RecoveryAction(props: {
118+
readonly label: string;
119+
readonly disabled: boolean;
120+
readonly onPress: () => void;
121+
}) {
122+
return (
123+
<Pressable
124+
accessibilityRole="button"
125+
accessibilityState={{ disabled: props.disabled }}
126+
disabled={props.disabled}
127+
hitSlop={{ top: 12, bottom: 12, left: 8, right: 8 }}
128+
onPress={props.onPress}
129+
className="active:opacity-70"
130+
>
131+
<Text
132+
className={
133+
props.disabled
134+
? "text-sm font-t3-medium text-foreground-muted"
135+
: "text-sm font-t3-medium text-primary"
136+
}
137+
>
138+
{props.label}
139+
</Text>
140+
</Pressable>
141+
);
142+
}

‎apps/web/src/components/chat/QueuedRunsControl.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,10 @@ export function QueuedRunsControl({
368368
})}
369369
</ol>
370370
{collapsible ? (
371-
<div className="self-end pe-1 text-xs pointer-coarse:[&_[data-slot=inline-button]]:relative pointer-coarse:[&_[data-slot=inline-button]]:after:absolute pointer-coarse:[&_[data-slot=inline-button]]:after:-inset-x-1.5 pointer-coarse:[&_[data-slot=inline-button]]:after:-inset-y-3.5">
371+
<div className="self-end pe-1 text-xs">
372372
<InlineButton
373373
tone="muted"
374+
touchTarget="expanded"
374375
aria-expanded={showAll}
375376
aria-controls={queueListId}
376377
// Keep the composer focused; keyboard activation still works.

‎apps/web/src/components/chat/UsageLimitRecoveryBanner.tsx‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useState } from "react";
1515
import { useDeadlinePassed } from "../../hooks/useDeadline";
1616
import { OpenAI } from "../Icons";
1717
import { ChatGptUsageButton } from "../settings/ChatGptUsageButton";
18-
import { Button } from "../ui/button";
18+
import { Button, InlineButton } from "../ui/button";
1919
import { formatUpcomingTimestamp } from "../../timestampFormat";
2020
import { toastManager } from "../ui/toast";
2121
import type { ComposerBannerStackItem } from "./ComposerBannerStack";
@@ -125,18 +125,17 @@ function RecoveryActions({ runId, resetAt, recovery, snoozedUntil, onChange }: R
125125
}
126126
// Inline errors would widen the actions column and crush the title.
127127
return (
128-
<>
129-
<Button size="xs" variant="ghost" disabled={pending} onClick={() => void toggle("resume")}>
128+
<span className="flex flex-wrap items-center gap-x-3 gap-y-1 px-1">
129+
<InlineButton touchTarget="expanded" disabled={pending} onClick={() => void toggle("resume")}>
130130
{pending ? "Saving..." : scheduled ? "Cancel auto-resume" : "Resume at reset"}
131-
</Button>
132-
<Button
133-
size="xs"
134-
variant="ghost"
131+
</InlineButton>
132+
<InlineButton
133+
touchTarget="expanded"
135134
disabled={pending || (!snoozed && resetPassed)}
136135
onClick={() => void toggle("snooze")}
137136
>
138137
{pending ? "Saving..." : snoozed ? "Wake now" : "Snooze until reset"}
139-
</Button>
140-
</>
138+
</InlineButton>
139+
</span>
141140
);
142141
}

‎apps/web/src/components/ui/button.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ const inlineButtonVariants = cva(
103103
{
104104
defaultVariants: { tone: "default" },
105105
variants: {
106+
touchTarget: {
107+
expanded:
108+
"pointer-coarse:relative pointer-coarse:after:absolute pointer-coarse:after:-inset-x-1.5 pointer-coarse:after:-inset-y-3.5",
109+
},
106110
tone: {
107111
default: "text-foreground",
108112
muted: "text-muted-foreground hover:text-foreground",
@@ -117,11 +121,12 @@ const inlineButtonVariants = cva(
117121
export function InlineButton({
118122
className,
119123
tone,
124+
touchTarget,
120125
render,
121126
...props
122127
}: useRender.ComponentProps<"button"> & VariantProps<typeof inlineButtonVariants>) {
123128
const defaultProps = {
124-
className: cn(inlineButtonVariants({ tone }), className),
129+
className: cn(inlineButtonVariants({ tone, touchTarget }), className),
125130
"data-slot": "inline-button",
126131
type: render ? undefined : ("button" as const),
127132
};

0 commit comments

Comments
 (0)