GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mobile): ignore a ChatGPT action tap while the last one is in flight · pingdotgg/t3code@f243061

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/mobile/src/features/threads
    • UsageLimitRecoveryCard.test.tsx
    • UsageLimitRecoveryCard.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/UsageLimitRecoveryCard.test.tsx
+24-2Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ type ButtonProps = { label: string; disabled?: boolean; onPress: () => void };
1414

1515
vi.mock("react-native", () => ({
1616
Linking: { openURL: vi.fn() },
17-
Pressable: ({ children, onPress }: { children: ReactNode; onPress: () => void }) => (
18-
<button type="button" onClick={onPress}>
17+
Pressable: ({ children, disabled, onPress }: ButtonProps & { children: ReactNode }) => (
18+
<button type="button" disabled={disabled} onClick={onPress}>
1919
{children}
2020
</button>
2121
),
@@ -109,6 +109,28 @@ describe("UsageLimitRecoveryCard", () => {
109109
expect(container.textContent).not.toContain("Could not copy the request");
110110
});
111111

112+
it("ignores a second copy while the first is still in flight", async () => {
113+
const first = Promise.withResolvers<boolean>();
114+
vi.mocked(Clipboard.setStringAsync).mockReset().mockReturnValueOnce(first.promise);
115+
const container = document.createElement("div");
116+
const root = createRoot(container);
117+
using _root = { [Symbol.dispose]: () => act(() => root.unmount()) };
118+
act(() =>
119+
root.render(
120+
<UsageLimitRecoveryCard
121+
thread={failedThread(null, CHATGPT_WORKSPACE_USAGE_LIMIT_CODE)}
122+
environmentId={"env-1" as EnvironmentId}
123+
/>,
124+
),
125+
);
126+
const copy = () => container.querySelector("button")!.click();
127+
act(() => copy());
128+
act(() => copy());
129+
expect(Clipboard.setStringAsync).toHaveBeenCalledTimes(1);
130+
await act(async () => first.resolve(true));
131+
expect(container.textContent).toContain("Request copied");
132+
});
133+
112134
it("disables Snooze once a reset more than 24.8 days away passes", () => {
113135
using _timers = { [Symbol.dispose]: () => vi.useRealTimers() };
114136
vi.useFakeTimers({ now: 0 });
Collapse file

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

Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/UsageLimitRecoveryCard.tsx
+15-8Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export function UsageLimitRecoveryCard({
3939
const scheduled =
4040
recovery?.runId === runId && recovery?.resetAt === resetAt && recovery?.autoResume;
4141
const [copied, setCopied] = useState(false);
42+
const [actionPending, setActionPending] = useState(false);
4243
const code = thread.runtime?.lastErrorCode;
4344
// OpenAI's partner guidelines specify the ChatGPT notice and its action.
4445
const workspaceLimit = code === CHATGPT_WORKSPACE_USAGE_LIMIT_CODE;
@@ -92,20 +93,24 @@ export function UsageLimitRecoveryCard({
9293
run: () => {
9394
setError(null);
9495
setCopied(false);
95-
void Clipboard.setStringAsync(CHATGPT_WORKSPACE_ADMIN_REQUEST).then(
96-
() => setCopied(true),
97-
() => setError("Could not copy the request. Try again."),
98-
);
96+
setActionPending(true);
97+
void Clipboard.setStringAsync(CHATGPT_WORKSPACE_ADMIN_REQUEST)
98+
.then(
99+
() => setCopied(true),
100+
() => setError("Could not copy the request. Try again."),
101+
)
102+
.finally(() => setActionPending(false));
99103
},
100104
}
101105
: {
102106
label: "Manage usage",
103107
role: "link" as const,
104108
run: () => {
105109
setError(null);
106-
void Linking.openURL(CHATGPT_USAGE_URL).catch(() =>
107-
setError("Could not open ChatGPT. Go to chatgpt.com → Settings → Usage."),
108-
);
110+
setActionPending(true);
111+
void Linking.openURL(CHATGPT_USAGE_URL)
112+
.catch(() => setError("Could not open ChatGPT. Go to chatgpt.com → Settings → Usage."))
113+
.finally(() => setActionPending(false));
109114
},
110115
};
111116
return (
@@ -130,7 +135,9 @@ export function UsageLimitRecoveryCard({
130135
</Text>
131136
<Pressable
132137
accessibilityRole={action.role}
133-
hitSlop={12}
138+
accessibilityState={{ disabled: actionPending }}
139+
disabled={actionPending}
140+
hitSlop={14}
134141
className="mt-1 self-start active:opacity-70"
135142
onPress={action.run}
136143
>

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.