({
return (
- {renderItem(info)}
+
+ {renderItem(info)}
+
);
}
diff --git a/packages/app/src/components/host-status-dot.tsx b/packages/app/src/components/host-status-dot.tsx
index 4f7d16dc4..2a6af8961 100644
--- a/packages/app/src/components/host-status-dot.tsx
+++ b/packages/app/src/components/host-status-dot.tsx
@@ -5,6 +5,8 @@ import {
useHostRuntimeConnectionStatus,
} from "@/runtime/host-runtime";
+export const HOST_STATUS_DOT_SIZE = 8;
+
export function HostStatusDot({ serverId }: { serverId: string }) {
const status = useHostRuntimeConnectionStatus(serverId);
@@ -19,8 +21,8 @@ function statusStyle(status: HostRuntimeConnectionStatus) {
const styles = StyleSheet.create((theme) => ({
dot: {
- width: 8,
- height: 8,
+ width: HOST_STATUS_DOT_SIZE,
+ height: HOST_STATUS_DOT_SIZE,
borderRadius: theme.borderRadius.full,
},
dotOnline: {
diff --git a/packages/app/src/components/hosts/host-filter.tsx b/packages/app/src/components/hosts/host-filter.tsx
index d073dc943..9a810f2ca 100644
--- a/packages/app/src/components/hosts/host-filter.tsx
+++ b/packages/app/src/components/hosts/host-filter.tsx
@@ -1,8 +1,12 @@
import { useCallback, useMemo, useRef, useState, type ReactElement } from "react";
-import { Pressable, Text, View, type PressableStateCallbackType } from "react-native";
-import { ChevronDown, Server } from "lucide-react-native";
+import { Text, View } from "react-native";
+import { Server } from "lucide-react-native";
import { StyleSheet, withUnistyles } from "react-native-unistyles";
-import type { Theme } from "@/styles/theme";
+import { HOST_STATUS_DOT_SIZE } from "@/components/host-status-dot";
+import { ComboboxTrigger } from "@/components/ui/combobox-trigger";
+import { mapLayout } from "@/components/ui/control-sizing";
+import { density } from "@/styles/density";
+import { ICON_SIZE, type Theme } from "@/styles/theme";
import {
ALL_HOSTS_OPTION_ID,
getHostPickerLabel,
@@ -12,7 +16,8 @@ import {
} from "@/components/hosts/host-picker";
const ThemedServer = withUnistyles(Server);
-const ThemedChevronDown = withUnistyles(ChevronDown);
+// The height a hung trigger keeps: one line of its base-size label.
+const LABEL_LINE = 20;
const mutedColorMapping = (theme: Theme) => ({ color: theme.colors.foregroundMuted });
export interface HostFilterProps {
@@ -24,20 +29,28 @@ export interface HostFilterProps {
* manager edits a single host's catalog, so "all" is not an answer it could carry out.
*/
includeAllHost?: boolean;
+ /**
+ * Hang the trigger into the surrounding padding, for a trigger that leads a column such as a
+ * modal body: its leading glyph's ink sits on the content rail and it adds only a label line to
+ * the column, so the column's own gap sets the rhythm. The frame still grows outward on hover.
+ */
+ hang?: boolean;
triggerTestID?: string;
hostOptionTestID?: (serverId: string) => string;
}
/**
- * The "All hosts / " host pill shared by History, Schedules, Usage, the label manager and
+ * The "All hosts / " host picker shared by History, Schedules, Usage, the label manager and
* plugin screens: an anchored HostPicker, hidden by the caller when only one host exists. Without
- * `includeAllHost` it picks the one host a surface shows.
+ * `includeAllHost` it picks the one host a surface shows. Its trigger is the Settings host
+ * trigger; a long host name truncates instead of pushing the row.
*/
export function HostFilter({
hosts,
selectedHost,
onSelectHost,
includeAllHost = true,
+ hang = false,
triggerTestID,
hostOptionTestID,
}: HostFilterProps): ReactElement {
@@ -50,12 +63,21 @@ export function HostFilter({
);
const handleFilterOpen = useCallback(() => setIsFilterOpen(true), []);
+ const showsAllHosts = selectedHost === ALL_HOSTS_OPTION_ID;
+ const slotStyle = useMemo(
+ () => [
+ styles.triggerSlot,
+ hang && styles.triggerSlotHang,
+ hang && (showsAllHosts ? styles.glyphHang : styles.dotHang),
+ ],
+ [hang, showsAllHosts],
+ );
- const filterTriggerStyle = useCallback(
- ({ pressed, hovered = false }: PressableStateCallbackType & { hovered?: boolean }) => [
- styles.filterTrigger,
- Boolean(hovered) && styles.filterTriggerHovered,
- pressed && styles.filterTriggerPressed,
+ const triggerStyle = useCallback(
+ ({ pressed, hovered }: { pressed: boolean; hovered: boolean }) => [
+ styles.trigger,
+ hovered && styles.triggerHovered,
+ pressed && styles.triggerPressed,
],
[],
);
@@ -74,54 +96,73 @@ export function HostFilter({
desktopPlacement="bottom-start"
hostOptionTestID={hostOptionTestID}
>
-
-
+
- {selectedHost === ALL_HOSTS_OPTION_ID ? (
-
+ {showsAllHosts ? (
+
) : (
)}
-
+
{selectedHostLabel}
-
-
+
);
}
const styles = StyleSheet.create((theme) => ({
- filterTriggerWrap: {
- alignSelf: "flex-start",
+ // A row around the trigger keeps it as wide as its label in a column, and centred like any other
+ // item in a row.
+ triggerSlot: {
+ flexDirection: "row",
+ flexShrink: 1,
+ minWidth: 0,
+ maxWidth: "100%",
},
- filterTrigger: {
+ // Hangs the frame's height down to a label line.
+ triggerSlotHang: {
+ marginVertical: mapLayout(density.tightRowHeight, (height) => (LABEL_LINE - height) / 2),
+ },
+ // Hangs the padding, so the server glyph's box sits on the rail.
+ glyphHang: {
+ marginLeft: -theme.spacing[2],
+ },
+ // Hangs the padding and the dot's inset in its icon slot, so the dot's ink sits on the rail.
+ dotHang: {
+ marginLeft: -(theme.spacing[2] + (ICON_SIZE.sm - HOST_STATUS_DOT_SIZE) / 2),
+ },
+ // The Settings host trigger: a borderless row that fills on hover and press.
+ trigger: {
+ flexShrink: 1,
+ minWidth: 0,
+ maxWidth: "100%",
flexDirection: "row",
alignItems: "center",
- gap: theme.spacing[1.5],
- alignSelf: "flex-start",
- paddingVertical: theme.spacing[1.5],
- paddingHorizontal: theme.spacing[3],
- borderRadius: theme.borderRadius.md,
- backgroundColor: theme.colors.surface1,
- borderWidth: theme.borderWidth[1],
- borderColor: theme.colors.border,
+ minHeight: density.tightRowHeight,
+ paddingVertical: theme.spacing[1],
+ paddingHorizontal: theme.spacing[2],
+ borderRadius: theme.borderRadius.lg,
},
- filterTriggerHovered: {
+ triggerHovered: {
backgroundColor: theme.colors.surface2,
},
- filterTriggerPressed: {
- backgroundColor: theme.colors.surface3,
+ triggerPressed: {
+ backgroundColor: theme.colors.surface2,
},
- filterTriggerText: {
+ label: {
+ flexShrink: 1,
+ minWidth: 0,
color: theme.colors.foreground,
fontSize: theme.fontSize.base,
- fontWeight: theme.fontWeight.medium,
+ fontWeight: theme.fontWeight.normal,
},
}));
diff --git a/packages/app/src/components/import-session-sheet.test.tsx b/packages/app/src/components/import-session-sheet.test.tsx
index 35c475e82..167de2a0e 100644
--- a/packages/app/src/components/import-session-sheet.test.tsx
+++ b/packages/app/src/components/import-session-sheet.test.tsx
@@ -164,6 +164,25 @@ vi.mock("@/components/adaptive-modal-sheet", () => ({
{children}
) : null,
+ SheetHeaderIconButton: ({
+ label,
+ onPress,
+ busy,
+ testID,
+ }: {
+ label: string;
+ onPress: () => void;
+ busy?: boolean;
+ testID?: string;
+ }) => (
+
+ ),
}));
vi.mock("react-native", async () => {
diff --git a/packages/app/src/components/import-session-sheet.tsx b/packages/app/src/components/import-session-sheet.tsx
index aa7294bf4..f97ae79cc 100644
--- a/packages/app/src/components/import-session-sheet.tsx
+++ b/packages/app/src/components/import-session-sheet.tsx
@@ -9,7 +9,11 @@ import type {
import type { AgentProvider } from "@getpaseo/protocol/agent-types";
import { ChevronDown, Inbox, Layers, RotateCw } from "lucide-react-native";
import { StyleSheet, useUnistyles } from "react-native-unistyles";
-import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
+import {
+ AdaptiveModalSheet,
+ SheetHeaderIconButton,
+ type SheetHeader,
+} from "@/components/adaptive-modal-sheet";
import { Button } from "@/components/ui/button";
import { ImportSessionList } from "@/components/import-session-list";
import { LoadingSpinner } from "@/components/ui/loading-spinner";
@@ -216,36 +220,6 @@ function ProviderErrorBannerRow({
);
}
-function RefreshAction({ isRefreshing, onPress }: { isRefreshing: boolean; onPress: () => void }) {
- const { theme } = useUnistyles();
- const { t } = useTranslation();
- const pressableStyle = useCallback(
- ({ pressed }: PressableStateCallbackType) => [
- styles.refreshButton,
- pressed && styles.refreshButtonPressed,
- ],
- [],
- );
- return (
-
-
- {isRefreshing ? (
-
- ) : (
-
- )}
-
-
- );
-}
-
function ScopeSubtitle({
hostLabel,
isScoped,
@@ -775,7 +749,15 @@ export function ImportSessionSheet({
},
}
: {}),
- actions: ,
+ actions: (
+
+ ),
}),
[handleRefresh, handleShowAll, hostLabel, isRefreshing, scopeCwd, supportsSearch, t, visible],
);
@@ -1099,18 +1081,4 @@ const styles = StyleSheet.create((theme) => ({
fontSize: theme.fontSize.base,
textAlign: "center",
},
- refreshButton: {
- padding: theme.spacing[2],
- marginRight: theme.spacing[1],
- borderRadius: theme.borderRadius.lg,
- },
- refreshButtonPressed: {
- backgroundColor: theme.colors.surface2,
- },
- refreshIconSlot: {
- width: 16,
- height: 16,
- alignItems: "center",
- justifyContent: "center",
- },
}));
diff --git a/packages/app/src/components/model-browser.tsx b/packages/app/src/components/model-browser.tsx
index 509e7a23b..70a0a9745 100644
--- a/packages/app/src/components/model-browser.tsx
+++ b/packages/app/src/components/model-browser.tsx
@@ -35,7 +35,7 @@ import {
type AgentProfilePickerRow as AgentProfilePickerRowModel,
type AgentProfileSeed,
} from "@/agent-profiles";
-import type { SheetHeader } from "@/components/adaptive-modal-sheet";
+import { SheetHeaderIconButton, type SheetHeader } from "@/components/adaptive-modal-sheet";
import { Button } from "@/components/ui/button";
import { LoadingSpinner } from "@/components/ui/loading-spinner";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
@@ -74,14 +74,13 @@ const ThemedLoadingSpinner = withUnistyles(LoadingSpinner);
const ThemedPencil = withUnistyles(Pencil);
const ThemedPlus = withUnistyles(Plus);
const ThemedSearch = withUnistyles(Search);
-const ThemedSettings = withUnistyles(Settings);
function ProviderSettingsAction({
- accessibilityLabel,
+ label,
provider,
serverId,
}: {
- accessibilityLabel: string;
+ label: string;
provider: string;
serverId: string | null;
}) {
@@ -92,17 +91,13 @@ function ProviderSettingsAction({
}, [overlayParentLayer, provider, serverId]);
return (
-
-
-
+ />
);
}
@@ -188,10 +183,6 @@ const foregroundExtraMutedMapping = (theme: Theme) => ({
color: theme.colors.foregroundExtraMuted,
});
-const headerSettingsMapping = (disabled: boolean) => (theme: Theme) => ({
- color: disabled ? theme.colors.border : theme.colors.foregroundMuted,
-});
-
interface ModelBrowserInput {
providers: ProviderSelectorProvider[];
selectedProvider: string;
@@ -278,11 +269,6 @@ export function ModelProviderGlyph({
return ;
}
-function HeaderSettingsIcon({ disabled }: { disabled: boolean }) {
- const uniProps = useMemo(() => headerSettingsMapping(disabled), [disabled]);
- return ;
-}
-
function iconButtonStyle({ hovered, pressed }: PressableStateCallbackType & { hovered?: boolean }) {
return [
styles.rowIconButton,
@@ -395,15 +381,11 @@ export function useModelBrowser({
),
back: singleProviderView ? undefined : { onPress: showAll },
actions: (
-
-
-
+
),
search: {
onChange: handleSearchQueryChange,
@@ -1586,11 +1568,6 @@ export function ModelBrowser({
}
const styles = StyleSheet.create((theme) => ({
- headerActionRow: {
- flexDirection: "row",
- alignItems: "center",
- gap: theme.spacing[1],
- },
profilesContainer: {
backgroundColor: theme.colors.surface1,
borderBottomWidth: 1,
diff --git a/packages/app/src/components/provider-diagnostic-sheet.tsx b/packages/app/src/components/provider-diagnostic-sheet.tsx
index 60231e4e4..904ba17e8 100644
--- a/packages/app/src/components/provider-diagnostic-sheet.tsx
+++ b/packages/app/src/components/provider-diagnostic-sheet.tsx
@@ -8,6 +8,7 @@ import { StyleSheet, useUnistyles } from "react-native-unistyles";
import {
AdaptiveModalSheet,
AdaptiveTextInput,
+ SheetHeaderIconButton,
type SheetHeader,
} from "@/components/adaptive-modal-sheet";
import { Button } from "@/components/ui/button";
@@ -275,28 +276,10 @@ function DiagnosticSubSheet({
}
}, [visible, fetchDiagnostic]);
- const refreshButtonStyle = useCallback(
- ({ hovered, pressed }: PressableStateCallbackType & { hovered?: boolean }) => [
- sheetStyles.iconButton,
- (Boolean(hovered) || pressed) && sheetStyles.iconButtonHovered,
- loading ? sheetStyles.disabled : null,
- ],
- [loading],
- );
-
const handleRefreshPress = useCallback(() => {
void fetchDiagnostic();
}, [fetchDiagnostic]);
- const copyButtonStyle = useCallback(
- ({ hovered, pressed }: PressableStateCallbackType & { hovered?: boolean }) => [
- sheetStyles.iconButton,
- (Boolean(hovered) || pressed) && Boolean(diagnostic) && sheetStyles.iconButtonHovered,
- diagnostic ? null : sheetStyles.disabled,
- ],
- [diagnostic],
- );
-
const handleCopyPress = useCallback(() => {
if (!diagnostic) return;
void Clipboard.setStringAsync(diagnostic)
@@ -308,49 +291,27 @@ function DiagnosticSubSheet({
() => ({
title: t("settings.providers.diagnostic.title"),
actions: (
-
-
+
-
-
-
+
- {loading ? (
-
- ) : (
-
- )}
-
-
+ onPress={handleRefreshPress}
+ busy={loading}
+ />
+ >
),
}),
- [
- copyButtonStyle,
- diagnostic,
- handleCopyPress,
- handleRefreshPress,
- loading,
- refreshButtonStyle,
- t,
- theme.colors.foregroundMuted,
- theme.iconSize.sm,
- ],
+ [diagnostic, handleCopyPress, handleRefreshPress, loading, t],
);
let body: React.ReactNode;
@@ -762,11 +723,6 @@ const sheetStyles = StyleSheet.create((theme) => ({
iconButtonHovered: {
backgroundColor: theme.colors.surface2,
},
- headerActions: {
- flexDirection: "row",
- alignItems: "center",
- gap: theme.spacing[1],
- },
disabled: {
opacity: 0.5,
},
diff --git a/packages/app/src/components/sortable-inline-list.web.tsx b/packages/app/src/components/sortable-inline-list.web.tsx
index 133cd408d..8f0a84fed 100644
--- a/packages/app/src/components/sortable-inline-list.web.tsx
+++ b/packages/app/src/components/sortable-inline-list.web.tsx
@@ -127,7 +127,7 @@ export function SortableInlineList({
data: T[];
keyExtractor: (item: T, index: number) => string;
renderItem: (info: DraggableRenderItemInfo) => ReactElement;
- onDragEnd?: (data: T[]) => void;
+ onDragEnd?: (data: T[], movedKey: string) => void;
useDragHandle?: boolean;
disabled?: boolean;
activationDistance?: number;
diff --git a/packages/app/src/components/tool-call-sheet.tsx b/packages/app/src/components/tool-call-sheet.tsx
index 33009ee37..c37b88221 100644
--- a/packages/app/src/components/tool-call-sheet.tsx
+++ b/packages/app/src/components/tool-call-sheet.tsx
@@ -1,16 +1,16 @@
import React, { createContext, useContext, useCallback, useMemo } from "react";
import type { ReactNode } from "react";
-import { View, Text, Pressable } from "react-native";
+import { View } from "react-native";
import { StyleSheet, withUnistyles } from "react-native-unistyles";
-import { useTranslation } from "react-i18next";
import { BottomSheetScrollView } from "@gorhom/bottom-sheet";
-import { X } from "lucide-react-native";
import type { ToolCallDetail } from "@getpaseo/protocol/agent-types";
import {
IsolatedBottomSheetModal,
type ContextBridge,
useIsolatedBottomSheetVisibility,
} from "@/components/ui/isolated-bottom-sheet-modal";
+import { SheetHeaderView, type SheetHeader } from "@/components/adaptive-modal-sheet";
+import { ICON_SIZE } from "@/styles/theme";
import type { ToolCallIconComponent } from "@/utils/tool-call-icon";
import { ToolCallDetailsContent } from "./tool-call-details";
@@ -66,9 +66,6 @@ function ToolCallHeaderIcon({ icon: Icon, size, color }: ToolCallHeaderIconProps
const ThemedToolCallHeaderIcon = withUnistyles(ToolCallHeaderIcon, (theme) => ({
color: theme.colors.foreground,
}));
-const ThemedCloseIcon = withUnistyles(X, (theme) => ({
- color: theme.colors.foregroundMuted,
-}));
export const ToolCallSheetModal = withUnistyles(IsolatedBottomSheetModal, (theme) => ({
backgroundStyle: {
@@ -148,7 +145,6 @@ interface ToolCallSheetContentProps {
}
function ToolCallSheetContent({ data, onClose }: ToolCallSheetContentProps) {
- const { t } = useTranslation();
const {
toolName,
displayName,
@@ -157,27 +153,17 @@ function ToolCallSheetContent({ data, onClose }: ToolCallSheetContentProps) {
icon: IconComponent,
showLoadingSkeleton,
} = data;
+ const header = useMemo(
+ () => ({
+ title: displayName,
+ leading: ,
+ }),
+ [IconComponent, displayName],
+ );
return (
- {/* Header */}
-
-
-
-
- {displayName}
-
-
-
-
-
-
+
{/* Content */}
@@ -200,30 +186,6 @@ const styles = StyleSheet.create((theme) => ({
flex: 1,
backgroundColor: theme.colors.surface2,
},
- header: {
- flexDirection: "row",
- alignItems: "center",
- justifyContent: "space-between",
- paddingHorizontal: theme.spacing[4],
- paddingVertical: theme.spacing[3],
- borderBottomWidth: theme.borderWidth[1],
- borderBottomColor: theme.colors.border,
- },
- headerLeft: {
- flexDirection: "row",
- alignItems: "center",
- gap: theme.spacing[2],
- flex: 1,
- },
- headerTitle: {
- fontSize: theme.fontSize.base,
- fontWeight: theme.fontWeight.semibold,
- color: theme.colors.foreground,
- flex: 1,
- },
- closeButton: {
- padding: theme.spacing[2],
- },
content: {
flex: 1,
minHeight: 0,
diff --git a/packages/app/src/components/ui/bottom-sheet-scope.tsx b/packages/app/src/components/ui/bottom-sheet-scope.tsx
index cbdaedac5..b4831f58f 100644
--- a/packages/app/src/components/ui/bottom-sheet-scope.tsx
+++ b/packages/app/src/components/ui/bottom-sheet-scope.tsx
@@ -1,11 +1,47 @@
-import React, { createContext, useContext, type ReactNode } from "react";
+import React, {
+ createContext,
+ useContext,
+ useMemo,
+ type MutableRefObject,
+ type ReactNode,
+} from "react";
+import type { GestureType } from "react-native-gesture-handler";
-const BottomSheetScopeContext = createContext(false);
+/**
+ * Ref for a drag gesture inside the sheet's content, set through the gesture's `withRef`. Keep it
+ * out of worklet closures: Reanimated freezes captured objects in dev, and RNGH can then no longer
+ * set `.current`.
+ */
+export type SheetContentDragGesture = MutableRefObject;
-export function BottomSheetScope({ children }: { children: ReactNode }) {
- return {children};
+/**
+ * Registers a child's drag with the sheet, so the sheet's content pan waits for it to fail and the
+ * child keeps the touch instead of moving the sheet. Returns the unregister. Call it after the
+ * gesture has attached: RNGH resolves the ref to a handler tag when the sheet builds its pan, and
+ * drops a ref that is still empty.
+ */
+export type AttachSheetContentDrag = (gesture: SheetContentDragGesture) => () => void;
+
+interface BottomSheetScopeValue {
+ attachContentDrag: AttachSheetContentDrag;
+}
+
+const BottomSheetScopeContext = createContext(null);
+
+export function BottomSheetScope({
+ attachContentDrag,
+ children,
+}: BottomSheetScopeValue & { children: ReactNode }) {
+ const value = useMemo(() => ({ attachContentDrag }), [attachContentDrag]);
+ return (
+ {children}
+ );
}
export function useIsInsideBottomSheet(): boolean {
- return useContext(BottomSheetScopeContext);
+ return useContext(BottomSheetScopeContext) !== null;
+}
+
+export function useAttachSheetContentDrag(): AttachSheetContentDrag | undefined {
+ return useContext(BottomSheetScopeContext)?.attachContentDrag;
}
diff --git a/packages/app/src/components/ui/dismiss-backdrop.tsx b/packages/app/src/components/ui/dismiss-backdrop.tsx
new file mode 100644
index 000000000..7157b8d5a
--- /dev/null
+++ b/packages/app/src/components/ui/dismiss-backdrop.tsx
@@ -0,0 +1,6 @@
+import { Pressable, StyleSheet } from "react-native";
+
+/** The invisible layer behind a dialog that closes it when pressed outside the dialog. */
+export function DismissBackdrop({ label, onPress }: { label: string; onPress: () => void }) {
+ return ;
+}
diff --git a/packages/app/src/components/ui/icon-button-chrome.ts b/packages/app/src/components/ui/icon-button-chrome.ts
index 42ba47a80..da738df59 100644
--- a/packages/app/src/components/ui/icon-button-chrome.ts
+++ b/packages/app/src/components/ui/icon-button-chrome.ts
@@ -8,6 +8,7 @@ import {
TOUCH_ICON_SIZE,
type SizingValue,
} from "@/components/ui/control-geometry";
+import type { LayoutValue } from "@/components/ui/control-sizing";
import { ICON_SIZE } from "@/styles/theme";
export { extraMutedIconColorMapping, mutedIconColorMapping } from "@/components/ui/icon-color";
@@ -102,6 +103,25 @@ export function iconButtonChromeGlyphSize(size: IconButtonChromeSize, compact =
return GLYPH_SIZES[size][controlSizingForLayout(compact)];
}
+/** The glyph for an icon button, sized by its container's chrome the way its frame is. */
+export function useIconButtonChromeGlyphSize(size: IconButtonChromeSize, compact = false): number {
+ const scope = useContext(IconButtonChromeContext);
+ return iconButtonChromeGlyphSize(scope === "header-island" ? "large" : size, compact);
+}
+
+/**
+ * The margin that pulls a button out by how far its frame reaches past its glyph. A row that hangs
+ * its edge buttons by it keeps their glyphs, not their frames, on the row's content rail.
+ */
+export function iconButtonChromeHang(size: IconButtonChromeSize): LayoutValue {
+ const frame = ICON_BUTTON_SIZES[size];
+ const glyph = GLYPH_SIZES[size];
+ return bySizing({
+ touch: (glyph.touch - frame.touch) / 2,
+ pointer: (glyph.pointer - frame.pointer) / 2,
+ });
+}
+
export function smallIconButtonChromeFrameSize(compact = false): number {
return ICON_BUTTON_SIZES.small[controlSizingForLayout(compact)];
}
diff --git a/packages/app/src/components/ui/isolated-bottom-sheet-modal/index.test.tsx b/packages/app/src/components/ui/isolated-bottom-sheet-modal/index.test.tsx
index 6637c5e33..17aa4a5b7 100644
--- a/packages/app/src/components/ui/isolated-bottom-sheet-modal/index.test.tsx
+++ b/packages/app/src/components/ui/isolated-bottom-sheet-modal/index.test.tsx
@@ -41,25 +41,41 @@ vi.mock("@gorhom/portal", () => ({
PortalHost: () => React.createElement("div", { "data-host": true }),
}));
+/** Every `waitFor` Gorhom received, in render order. Gorhom rebuilds its content pan per value. */
+const sheetWaitFor = vi.hoisted(() => [] as unknown[]);
+
vi.mock("@gorhom/bottom-sheet", async () => {
const { Portal } = await import("@gorhom/portal");
return {
BottomSheetModalProvider: ({ children }: { children?: React.ReactNode }) =>
React.createElement("div", { "data-bottom-sheet-provider": true }, children),
BottomSheetModal: React.forwardRef(
- ({ children, stackBehavior }: { children?: React.ReactNode; stackBehavior?: string }, _ref) =>
- React.createElement(
+ (
+ {
+ children,
+ stackBehavior,
+ waitFor,
+ }: { children?: React.ReactNode; stackBehavior?: string; waitFor?: unknown },
+ _ref,
+ ) => {
+ sheetWaitFor.push(waitFor);
+ return React.createElement(
Portal,
null,
React.createElement("div", { "data-stack-behavior": stackBehavior }, children),
- ),
+ );
+ },
),
};
});
import { IsolatedBottomSheetModal, type ContextBridge } from ".";
import { useAnimatedLayout } from "@gorhom/bottom-sheet/src/hooks/useAnimatedLayout";
-import { useIsInsideBottomSheet } from "@/components/ui/bottom-sheet-scope";
+import {
+ useAttachSheetContentDrag,
+ useIsInsideBottomSheet,
+ type SheetContentDragGesture,
+} from "@/components/ui/bottom-sheet-scope";
/** Renders whatever the portal is currently holding, from its own place in the tree. */
function PortalHostProbe() {
@@ -233,3 +249,51 @@ describe("bottom sheet layout subscription", () => {
}
});
});
+
+describe("IsolatedBottomSheetModal content drag", () => {
+ let container: HTMLDivElement;
+ let root: Root;
+
+ beforeEach(() => {
+ container = document.createElement("div");
+ document.body.appendChild(container);
+ root = createRoot(container);
+ sheetWaitFor.length = 0;
+ });
+
+ afterEach(() => {
+ act(() => root.unmount());
+ container.remove();
+ portalStore.reset();
+ });
+
+ const dragGesture: SheetContentDragGesture = { current: undefined };
+
+ function ContentDrag() {
+ const attach = useAttachSheetContentDrag();
+ React.useEffect(() => attach?.(dragGesture), [attach]);
+ return null;
+ }
+
+ function renderSheet(content: React.ReactNode) {
+ act(() => {
+ root.render(
+ <>
+ {content}
+
+ >,
+ );
+ });
+ }
+
+ it("makes the sheet wait for a content drag that mounts after it, until it unmounts", () => {
+ renderSheet(null);
+ expect(sheetWaitFor.at(-1)).toBeUndefined();
+
+ renderSheet();
+ expect(sheetWaitFor.at(-1)).toBe(dragGesture);
+
+ renderSheet(null);
+ expect(sheetWaitFor.at(-1)).toBeUndefined();
+ });
+});
diff --git a/packages/app/src/components/ui/isolated-bottom-sheet-modal/index.tsx b/packages/app/src/components/ui/isolated-bottom-sheet-modal/index.tsx
index 2498ed2a7..fcde3a6e3 100644
--- a/packages/app/src/components/ui/isolated-bottom-sheet-modal/index.tsx
+++ b/packages/app/src/components/ui/isolated-bottom-sheet-modal/index.tsx
@@ -4,7 +4,15 @@ import {
type BottomSheetBackdropProps,
} from "@gorhom/bottom-sheet";
import React from "react";
-import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from "react";
+import {
+ forwardRef,
+ useCallback,
+ useEffect,
+ useImperativeHandle,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
import { useDismissibleOverlay } from "@/components/ui/overlay-dismissal";
import type { ElementRef, ReactNode } from "react";
import { systemBackPress } from "./back-press";
@@ -12,7 +20,11 @@ import {
type BottomSheetController,
createBottomSheetVisibilityTracker,
} from "./visibility-tracker";
-import { BottomSheetScope } from "@/components/ui/bottom-sheet-scope";
+import {
+ BottomSheetScope,
+ type AttachSheetContentDrag,
+ type SheetContentDragGesture,
+} from "@/components/ui/bottom-sheet-scope";
import { SheetBackdrop } from "./sheet-backdrop";
type GorhomBottomSheetModalMethods = ElementRef;
@@ -95,6 +107,14 @@ export const IsolatedBottomSheetModal = forwardRef<
enableDismissOnClose = true,
...bottomSheetProps
} = props;
+ // State, not a ref the child fills in: Gorhom builds its pan once per `waitFor`, and RNGH reads
+ // the ref's handler tag only then. Registering hands Gorhom a new `waitFor`, so a drag that
+ // mounts after the sheet (content still loading) still gets the relation.
+ const [contentDragGesture, setContentDragGesture] = useState();
+ const attachContentDrag = useCallback((gesture) => {
+ setContentDragGesture(gesture);
+ return () => setContentDragGesture((current) => (current === gesture ? undefined : current));
+ }, []);
const renderBackdrop = useCallback(
(backdropProps: BottomSheetBackdropProps) => (
- {contextBridge ? contextBridge(children) : children}
+
+ {contextBridge ? contextBridge(children) : children}
+
);
diff --git a/packages/app/src/components/ui/scroll-view.tsx b/packages/app/src/components/ui/scroll-view.tsx
index d6abed39d..9cba9551f 100644
--- a/packages/app/src/components/ui/scroll-view.tsx
+++ b/packages/app/src/components/ui/scroll-view.tsx
@@ -1,4 +1,4 @@
-import { forwardRef, type Ref } from "react";
+import { createContext, forwardRef, useContext, useMemo, useState, type Ref } from "react";
import {
ScrollView as NativeScrollView,
FlatList as NativeFlatList,
@@ -12,7 +12,11 @@ import {
type NativeViewGestureHandlerProps,
} from "react-native-gesture-handler";
import { isNative } from "@/constants/platform";
-import { useIsInsideBottomSheet } from "./bottom-sheet-scope";
+import {
+ useAttachSheetContentDrag,
+ useIsInsideBottomSheet,
+ type AttachSheetContentDrag,
+} from "./bottom-sheet-scope";
// Both libraries forward to the RN FlatList instance. Their published ref types
// disagree about getScrollResponder (Gorhom) and include the component function
@@ -34,9 +38,43 @@ export const ScrollView = forwardRef(
);
}
+ return ;
+ },
+);
+
+/**
+ * What a child that drags inside a sheet needs to keep the touch: it registers its drag gesture
+ * through `attach` so the sheet's pan waits for it, and `setActive(true)` stops the sheet's
+ * scroll until the drag ends. Outside a sheet scroll there is no `attach` and `setActive` does
+ * nothing.
+ */
+export interface ContentDrag {
+ attach: AttachSheetContentDrag | undefined;
+ setActive: (active: boolean) => void;
+}
+
+const ContentDragContext = createContext(null);
+
+const NO_CONTENT_DRAG: ContentDrag = { attach: undefined, setActive: () => {} };
+
+export function useContentDrag(): ContentDrag {
+ return useContext(ContentDragContext) ?? NO_CONTENT_DRAG;
+}
+
+const SheetScrollView = forwardRef(
+ function SheetScrollView(props, ref) {
+ const attach = useAttachSheetContentDrag();
+ const [dragging, setDragging] = useState(false);
+ const contentDrag = useMemo(() => ({ attach, setActive: setDragging }), [attach]);
return (
-
- {props.children}
+
+
+ {props.children}
+
);
},
diff --git a/packages/app/src/components/ui/text-input/text-input.native.test.tsx b/packages/app/src/components/ui/text-input/text-input.native.test.tsx
index b52d7b992..c28badd21 100644
--- a/packages/app/src/components/ui/text-input/text-input.native.test.tsx
+++ b/packages/app/src/components/ui/text-input/text-input.native.test.tsx
@@ -66,13 +66,15 @@ function createHandleRecorder() {
return { handleRef, received, assignHandle };
}
+const attachNoContentDrag = () => () => {};
+
describe("EditingTextInputNative", () => {
it("uses the bottom-sheet input only inside a bottom sheet", () => {
act(() => {
root?.render(
<>
-
+
>,
diff --git a/packages/app/src/git/jump-to-file/index.tsx b/packages/app/src/git/jump-to-file/index.tsx
index f3363b91e..1746d02a7 100644
--- a/packages/app/src/git/jump-to-file/index.tsx
+++ b/packages/app/src/git/jump-to-file/index.tsx
@@ -6,7 +6,6 @@ import { StyleSheet, withUnistyles } from "react-native-unistyles";
import { FolderTree } from "lucide-react-native";
import {
AdaptiveModalSheet,
- SHEET_HEADER_CLOSE_PADDING_SCALE,
SHEET_HORIZONTAL_PADDING_SCALE,
} from "@/components/adaptive-modal-sheet";
import {
@@ -27,14 +26,11 @@ import { ICON_SIZE, SPACING, type Theme } from "@/styles/theme";
// difference so a depth-0 file icon lands on the header glyph's rail.
const TREE_LEADING_INSET = SPACING[SHEET_HORIZONTAL_PADDING_SCALE] - treeRowPaddingLeft(0);
-// The header's close glyph sits at the content inset plus the button's own
-// padding, while a tree row ends its trailing glyph at
-// `WORKSPACE_PANE_TRAILING_GLYPH_RAIL`. The body carries the difference so row
-// change icons land on the header X's rail.
+// The header's close glyph ends on the sheet's content inset, while a tree row
+// ends its trailing glyph at `WORKSPACE_PANE_TRAILING_GLYPH_RAIL`. The body
+// carries the difference so row change icons land on the header X's rail.
const TREE_TRAILING_INSET =
- SPACING[SHEET_HORIZONTAL_PADDING_SCALE] +
- SPACING[SHEET_HEADER_CLOSE_PADDING_SCALE] -
- WORKSPACE_PANE_TRAILING_GLYPH_RAIL;
+ SPACING[SHEET_HORIZONTAL_PADDING_SCALE] - WORKSPACE_PANE_TRAILING_GLYPH_RAIL;
const ThemedFolderTree = withUnistyles(FolderTree);
diff --git a/packages/app/src/hooks/use-settings/storage.test.ts b/packages/app/src/hooks/use-settings/storage.test.ts
index 0b169b521..8f426f9f2 100644
--- a/packages/app/src/hooks/use-settings/storage.test.ts
+++ b/packages/app/src/hooks/use-settings/storage.test.ts
@@ -330,6 +330,8 @@ describe("loadAppSettingsFromStorage", () => {
displayAs: "used",
pins: null,
serverId: null,
+ cardOrder: [],
+ cardsOff: [],
});
const deps = makeDeps({
@@ -354,6 +356,8 @@ describe("loadAppSettingsFromStorage", () => {
{ sourceId: "claude", windowId: "five-hour" },
],
serverId: "server",
+ cardOrder: [],
+ cardsOff: [],
});
});
@@ -369,6 +373,8 @@ describe("loadAppSettingsFromStorage", () => {
displayAs: "remaining",
pins: [],
serverId: "server",
+ cardOrder: [],
+ cardsOff: [],
});
});
@@ -389,6 +395,8 @@ describe("loadAppSettingsFromStorage", () => {
displayAs: "used",
pins: [{ sourceId: "claude", windowId: "weekly" }],
serverId: null,
+ cardOrder: [],
+ cardsOff: [],
});
});
diff --git a/packages/app/src/i18n/resources/ar.ts b/packages/app/src/i18n/resources/ar.ts
index 532734b31..c712619f5 100644
--- a/packages/app/src/i18n/resources/ar.ts
+++ b/packages/app/src/i18n/resources/ar.ts
@@ -2226,6 +2226,8 @@ export const ar: TranslationResources = {
loginExpired: "انتهت صلاحية تسجيل الدخول {{relativeTime}}. {{remedy}}",
title: "استخدام الخطة",
refresh: "تحديث",
+ reorderCard: "إعادة ترتيب {{source}}",
+ showCard: "إظهار {{source}}",
refreshAll: "تحديث الكل",
refreshing: "جارٍ التحديث...",
loading: "جارٍ تحميل بيانات الاستخدام...",
diff --git a/packages/app/src/i18n/resources/en.ts b/packages/app/src/i18n/resources/en.ts
index 648cd4377..dd4c8ca10 100644
--- a/packages/app/src/i18n/resources/en.ts
+++ b/packages/app/src/i18n/resources/en.ts
@@ -2252,6 +2252,8 @@ export const en = {
loginExpired: "Login expired {{relativeTime}}. {{remedy}}",
title: "Plan usage",
refresh: "Refresh",
+ reorderCard: "Reorder {{source}}",
+ showCard: "Show {{source}}",
refreshAll: "Refresh all",
refreshing: "Refreshing...",
loading: "Loading usage...",
diff --git a/packages/app/src/i18n/resources/es.ts b/packages/app/src/i18n/resources/es.ts
index 1b8e9533f..dc675d309 100644
--- a/packages/app/src/i18n/resources/es.ts
+++ b/packages/app/src/i18n/resources/es.ts
@@ -2275,6 +2275,8 @@ export const es: TranslationResources = {
loginExpired: "La sesión caducó {{relativeTime}}. {{remedy}}",
title: "Uso del plan",
refresh: "Actualizar",
+ reorderCard: "Reordenar {{source}}",
+ showCard: "Mostrar {{source}}",
refreshAll: "Actualizar todo",
refreshing: "Actualizando...",
loading: "Cargando uso...",
diff --git a/packages/app/src/i18n/resources/fr.ts b/packages/app/src/i18n/resources/fr.ts
index 76e4e28bb..e796aa767 100644
--- a/packages/app/src/i18n/resources/fr.ts
+++ b/packages/app/src/i18n/resources/fr.ts
@@ -2276,6 +2276,8 @@ export const fr: TranslationResources = {
loginExpired: "Connexion expirée {{relativeTime}}. {{remedy}}",
title: "Utilisation du forfait",
refresh: "Actualiser",
+ reorderCard: "Réorganiser {{source}}",
+ showCard: "Afficher {{source}}",
refreshAll: "Tout actualiser",
refreshing: "Actualisation...",
loading: "Chargement de l’utilisation...",
diff --git a/packages/app/src/i18n/resources/ja.ts b/packages/app/src/i18n/resources/ja.ts
index d44920696..2b6c65588 100644
--- a/packages/app/src/i18n/resources/ja.ts
+++ b/packages/app/src/i18n/resources/ja.ts
@@ -2249,6 +2249,8 @@ export const ja: TranslationResources = {
loginExpired: "ログインは{{relativeTime}}に期限切れになりました。{{remedy}}",
title: "プラン使用量",
refresh: "更新",
+ reorderCard: "{{source}} を並べ替え",
+ showCard: "{{source}} を表示",
refreshAll: "すべて更新",
refreshing: "更新中...",
loading: "使用状況を読み込み中...",
diff --git a/packages/app/src/i18n/resources/ko.ts b/packages/app/src/i18n/resources/ko.ts
index fa532ab6e..fc1cfec2c 100644
--- a/packages/app/src/i18n/resources/ko.ts
+++ b/packages/app/src/i18n/resources/ko.ts
@@ -2237,6 +2237,8 @@ export const ko: TranslationResources = {
loginExpired: "로그인이 {{relativeTime}}에 만료되었습니다. {{remedy}}",
title: "플랜 사용량",
refresh: "새로 고침",
+ reorderCard: "{{source}} 순서 변경",
+ showCard: "{{source}} 표시",
refreshAll: "모두 새로 고침",
refreshing: "새로 고치는 중...",
loading: "사용량 불러오는 중...",
diff --git a/packages/app/src/i18n/resources/pt-BR.ts b/packages/app/src/i18n/resources/pt-BR.ts
index a1055a6c9..2e2a3d144 100644
--- a/packages/app/src/i18n/resources/pt-BR.ts
+++ b/packages/app/src/i18n/resources/pt-BR.ts
@@ -2260,6 +2260,8 @@ export const ptBR: TranslationResources = {
loginExpired: "O login expirou {{relativeTime}}. {{remedy}}",
title: "Uso do plano",
refresh: "Atualizar",
+ reorderCard: "Reordenar {{source}}",
+ showCard: "Mostrar {{source}}",
refreshAll: "Atualizar tudo",
refreshing: "Atualizando...",
loading: "Carregando uso...",
diff --git a/packages/app/src/i18n/resources/ru.ts b/packages/app/src/i18n/resources/ru.ts
index 404aa45d4..dd6c52eee 100644
--- a/packages/app/src/i18n/resources/ru.ts
+++ b/packages/app/src/i18n/resources/ru.ts
@@ -2261,6 +2261,8 @@ export const ru: TranslationResources = {
loginExpired: "Срок входа истёк {{relativeTime}}. {{remedy}}",
title: "Использование плана",
refresh: "Обновить",
+ reorderCard: "Переместить {{source}}",
+ showCard: "Показывать {{source}}",
refreshAll: "Обновить всё",
refreshing: "Обновление...",
loading: "Загрузка данных об использовании...",
diff --git a/packages/app/src/i18n/resources/zh-CN.ts b/packages/app/src/i18n/resources/zh-CN.ts
index 3ca978813..ae6592a73 100644
--- a/packages/app/src/i18n/resources/zh-CN.ts
+++ b/packages/app/src/i18n/resources/zh-CN.ts
@@ -2203,6 +2203,8 @@ export const zhCN: TranslationResources = {
loginExpired: "登录已于{{relativeTime}}过期。{{remedy}}",
title: "套餐用量",
refresh: "刷新",
+ reorderCard: "重新排序 {{source}}",
+ showCard: "显示 {{source}}",
refreshAll: "全部刷新",
refreshing: "刷新中...",
loading: "正在加载用量...",
diff --git a/packages/app/src/screens/settings/plugins-page.tsx b/packages/app/src/screens/settings/plugins-page.tsx
index fdaf260f8..946978e43 100644
--- a/packages/app/src/screens/settings/plugins-page.tsx
+++ b/packages/app/src/screens/settings/plugins-page.tsx
@@ -6,8 +6,12 @@ import { Text, View } from "react-native";
import { StyleSheet } from "react-native-unistyles";
import { useMutation } from "@tanstack/react-query";
import type { PluginListItem, PluginLogEntry } from "@getpaseo/protocol/messages";
-import { MoreHorizontal, Trash2 } from "lucide-react-native";
-import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
+import { MoreHorizontal, RotateCw, Trash2 } from "lucide-react-native";
+import {
+ AdaptiveModalSheet,
+ SheetHeaderIconButton,
+ type SheetHeader,
+} from "@/components/adaptive-modal-sheet";
import { SettingsCard, SettingsRow } from "@/components/settings";
import { Alert } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
@@ -218,11 +222,16 @@ function PluginLogsSheet({
() => ({
title: t("settings.plugins.logs.title", { name: pluginDisplayName(plugin) }),
actions: (
-
+
),
}),
[logs.isFetching, plugin, refresh, t],
diff --git a/packages/app/src/screens/workspace/sheet-pane/sheet-pane.tsx b/packages/app/src/screens/workspace/sheet-pane/sheet-pane.tsx
index 7b93f8474..9b3fa10c4 100644
--- a/packages/app/src/screens/workspace/sheet-pane/sheet-pane.tsx
+++ b/packages/app/src/screens/workspace/sheet-pane/sheet-pane.tsx
@@ -94,7 +94,7 @@ export function SheetPane({ sheet, onClose, onBack, opener = null, isTop }: Shee
actions: sheet.policy.openAsTab ? (
diff --git a/packages/app/src/tool-calls/detail-level/overview/sheet.tsx b/packages/app/src/tool-calls/detail-level/overview/sheet.tsx
index 2888f1f42..c42b7de51 100644
--- a/packages/app/src/tool-calls/detail-level/overview/sheet.tsx
+++ b/packages/app/src/tool-calls/detail-level/overview/sheet.tsx
@@ -1,16 +1,16 @@
-import { useCallback, useEffect, useRef, type ReactNode } from "react";
-import { Pressable, Text, View } from "react-native";
+import { useCallback, useEffect, useMemo, useRef, type ReactNode } from "react";
+import { View } from "react-native";
import { BottomSheetScrollView, type BottomSheetScrollViewMethods } from "@gorhom/bottom-sheet";
-import { Wrench, X } from "lucide-react-native";
+import { Wrench } from "lucide-react-native";
import { StyleSheet, withUnistyles } from "react-native-unistyles";
-import { useTranslation } from "react-i18next";
import {
type ContextBridge,
useIsolatedBottomSheetVisibility,
} from "@/components/ui/isolated-bottom-sheet-modal";
+import { SheetHeaderView, type SheetHeader } from "@/components/adaptive-modal-sheet";
import { ToolCallSheetModal, useToolCallSheetContextBridge } from "@/components/tool-call-sheet";
import { useToolCallExpansionContextBridge } from "@/tool-calls/expansion-context";
-import type { Theme } from "@/styles/theme";
+import { ICON_SIZE, type Theme } from "@/styles/theme";
interface OverviewToolCallGroupSheetProps {
visible: boolean;
@@ -21,9 +21,8 @@ interface OverviewToolCallGroupSheetProps {
const SNAP_POINTS = ["60%", "95%"];
const ThemedWrench = withUnistyles(Wrench);
-const ThemedX = withUnistyles(X);
const foregroundMapping = (theme: Theme) => ({ color: theme.colors.foreground });
-const foregroundMutedMapping = (theme: Theme) => ({ color: theme.colors.foregroundMuted });
+const headerIcon = ;
export function OverviewToolCallGroupSheet({
visible,
@@ -31,7 +30,6 @@ export function OverviewToolCallGroupSheet({
children,
onClose,
}: OverviewToolCallGroupSheetProps) {
- const { t } = useTranslation();
const scrollRef = useRef(null);
const sheetContextBridge = useToolCallSheetContextBridge();
const expansionContextBridge = useToolCallExpansionContextBridge();
@@ -39,6 +37,10 @@ export function OverviewToolCallGroupSheet({
(content) => sheetContextBridge(expansionContextBridge(content)),
[expansionContextBridge, sheetContextBridge],
);
+ const header = useMemo(
+ () => ({ title: summary, titleTestID: "tool-call-group-sheet-summary", leading: headerIcon }),
+ [summary],
+ );
const { sheetRef, handleSheetChange, handleSheetDismiss } = useIsolatedBottomSheetVisibility({
visible,
onClose,
@@ -68,27 +70,11 @@ export function OverviewToolCallGroupSheet({
enablePanDownToClose
>
-
-
-
-
- {summary}
-
-
-
-
-
-
+
{children}
@@ -102,30 +88,6 @@ const styles = StyleSheet.create((theme) => ({
flex: 1,
backgroundColor: theme.colors.surface2,
},
- header: {
- flexDirection: "row",
- alignItems: "center",
- justifyContent: "space-between",
- paddingHorizontal: theme.spacing[4],
- paddingVertical: theme.spacing[3],
- borderBottomWidth: theme.borderWidth[1],
- borderBottomColor: theme.colors.border,
- },
- headerLeft: {
- flexDirection: "row",
- alignItems: "center",
- gap: theme.spacing[2],
- flex: 1,
- },
- headerTitle: {
- fontSize: theme.fontSize.base,
- fontWeight: theme.fontWeight.medium,
- color: theme.colors.foreground,
- flex: 1,
- },
- closeButton: {
- padding: theme.spacing[2],
- },
content: {
flex: 1,
minHeight: 0,
diff --git a/packages/app/src/usage/agent-usage.tsx b/packages/app/src/usage/agent-usage.tsx
index bf10054db..98f1c9bf8 100644
--- a/packages/app/src/usage/agent-usage.tsx
+++ b/packages/app/src/usage/agent-usage.tsx
@@ -1,3 +1,4 @@
+import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { Text, View } from "react-native";
import { StyleSheet } from "react-native-unistyles";
@@ -8,7 +9,7 @@ import type { UsageReportEntry } from "./types";
/**
* The usage of the account an agent runs under, for its context window details: one card per
- * report as it streams in, without pins. Nothing on hosts that cannot report usage, or for an
+ * report in the user's card order, without pins. Nothing on hosts that cannot report usage, or for an
* agent with no account to report.
*/
export function AgentUsage({
@@ -55,7 +56,8 @@ function AgentUsageCards({
refreshable: boolean;
}) {
const { display } = useUsageDisplay(reports);
- return reports.map((entry) => (
+ const arranged = useMemo(() => display.arrange(reports), [display, reports]);
+ return arranged.map((entry) => (
void;
+ /** The handle is always there; it shows while the card is hovered or where there is no hover. */
+ handleVisible: boolean;
+}
const ThemedLoadingSpinner = withUnistyles(LoadingSpinner);
export function UsageCard({
@@ -41,6 +53,7 @@ export function UsageCard({
display,
pinnable,
refreshable,
+ arrangement,
compact = false,
}: {
serverId: string;
@@ -51,6 +64,8 @@ export function UsageCard({
pinnable: boolean;
/** Whether the header has a Refresh button. Without one the freshness shows on the card. */
refreshable: boolean;
+ /** Present where the user arranges cards. An off card collapses to its header. */
+ arrangement?: UsageCardArrangement;
compact?: boolean;
}) {
const { t } = useTranslation();
@@ -60,9 +75,9 @@ export function UsageCard({
const showsFreshnessInline = isNative || isCompact || !refreshable;
const usage = entry.report;
const status = statusText(usage, t);
- const footer = entry.account.label ?? null;
- const { windows, balances, details, planLabel, successfulAt, retained, messages } =
- resolveUsageReport(entry, t);
+ const collapsed = arrangement?.on === false;
+ const report = resolveUsageReport(entry, t);
+ const { planLabel, successfulAt, retained } = report;
const containerStyle = useMemo(
() => [styles.container, compact ? styles.containerCompact : styles.containerPadded],
@@ -79,20 +94,34 @@ export function UsageCard({
return (
-
+
+ {arrangement ? (
+
+ ) : null}
{entry.sourceLabel}
- {planLabel ? : null}
+ {collapsed && entry.account.label ? (
+ // The body that names the account is gone, and two off cards of one source must differ.
+
+ {entry.account.label}
+
+ ) : null}
+ {planLabel && !collapsed ? (
+
+ ) : null}
- {status ? (
+ {status && !collapsed ? (
{status}
) : null}
- {refreshable ? (
+ {refreshable && !collapsed ? (
) : null}
+ {arrangement ? (
+
+
+
+ ) : null}
+ {collapsed ? null : (
+
+ )}
+
+ );
+}
+
+function UsageCardBody({
+ entry,
+ display,
+ pinnable,
+ report,
+ showsFreshnessInline,
+ refreshState,
+}: {
+ entry: UsageReportEntry;
+ display: UsageDisplay;
+ pinnable: boolean;
+ report: ReturnType;
+ showsFreshnessInline: boolean;
+ refreshState: UsageRefresh;
+}) {
+ const { t } = useTranslation();
+ const { windows, balances, details, retained, successfulAt, messages } = report;
+ const footer = entry.account.label ?? null;
+ return (
+ <>
{messages.length > 0 ? (
{messages.join("\n")}
@@ -164,7 +240,24 @@ export function UsageCard({
{t("providerUsage.refreshFailed")}
) : null}
-
+ >
+ );
+}
+
+/**
+ * Drags the card. It hangs in the card's left padding, so the logo, name and body share one rail
+ * and revealing it on hover moves nothing.
+ */
+function UsageCardDragHandle({ name, visible }: { name: string; visible: boolean }) {
+ const { t } = useTranslation();
+ return (
+
+
+
);
}
@@ -279,6 +372,21 @@ function UsageFreshness({
);
}
+const DRAG_GRIP_SIZE = 14;
+
+// The handle fills the card's left padding beside the header.
+function dragHandleSlot(spacing: { 4: number }) {
+ return {
+ position: "absolute",
+ left: 0,
+ width: spacing[4],
+ top: 0,
+ bottom: 0,
+ alignItems: "center",
+ justifyContent: "center",
+ } as const;
+}
+
// The Refresh glyph lands on the card's right rail and the header keeps its text height;
// the button's larger hitbox overhangs both instead of pushing them.
function iconHitboxOverhang(compact: boolean) {
@@ -305,11 +413,28 @@ const styles = StyleSheet.create((theme) => ({
alignItems: "center",
gap: theme.spacing[2],
},
+ // The row reaches into the card's left padding and above and below its text, so the handle
+ // there is inside it: Android delivers no touches to a child where it overflows its parent.
+ headerWithHandle: {
+ position: "relative",
+ flexDirection: "row",
+ alignItems: "center",
+ gap: theme.spacing[2],
+ marginLeft: -theme.spacing[4],
+ paddingLeft: theme.spacing[4],
+ marginVertical: -theme.spacing[2],
+ paddingVertical: theme.spacing[2],
+ },
name: {
flexShrink: 1,
color: theme.colors.foreground,
fontSize: theme.fontSize.base,
},
+ collapsedAccount: {
+ flexShrink: 1,
+ color: theme.colors.foregroundMuted,
+ fontSize: theme.fontSize.sm,
+ },
headerSpacer: {
flex: 1,
},
@@ -379,6 +504,12 @@ const styles = StyleSheet.create((theme) => ({
color: theme.colors.popoverForeground,
fontSize: theme.fontSize.sm,
},
+ dragHandle: dragHandleSlot(theme.spacing),
+ dragHandleHidden: { ...dragHandleSlot(theme.spacing), opacity: 0 },
+ // The switch's reserved control height overhangs the header like the Refresh button's hitbox.
+ cardSwitch: {
+ marginVertical: -theme.spacing[2],
+ },
refreshButton: iconHitboxOverhang(false),
refreshButtonCompact: iconHitboxOverhang(true),
}));
diff --git a/packages/app/src/usage/cards.test.ts b/packages/app/src/usage/cards.test.ts
new file mode 100644
index 000000000..86e62b3d2
--- /dev/null
+++ b/packages/app/src/usage/cards.test.ts
@@ -0,0 +1,153 @@
+import { describe, expect, it } from "vitest";
+import {
+ arrangeUsageCards,
+ arrangeUsageReports,
+ DEFAULT_USAGE_PREFERENCES,
+ setUsageCardOn,
+ UsagePreferencesSchema,
+ usageReportsOn,
+ type UsagePreferences,
+} from "./preferences";
+import { resolvePinnedUsage } from "./pinned";
+import type { UsageReportEntry } from "./types";
+
+function report(sourceId: string, sourceLabel: string, account?: string): UsageReportEntry {
+ return {
+ id: `${sourceId}:${account ?? "default"}`,
+ sourceId,
+ sourceLabel,
+ account: account ? { label: account } : {},
+ fetchedAt: "2026-01-01T00:00:00.000Z",
+ report: {
+ status: "available",
+ windows: [{ id: "weekly", label: "Weekly", summary: true, usedPct: 40 }],
+ },
+ };
+}
+
+const codex = report("codex", "Codex");
+const claudeWork = report("claude", "Claude", "work");
+const claudePersonal = report("claude", "Claude", "personal");
+const copilot = report("copilot", "Copilot");
+const gemini = report("gemini", "Gemini");
+
+function ids(reports: readonly UsageReportEntry[]): string[] {
+ return reports.map((entry) => entry.id);
+}
+
+function arranged(cardOrder: string[]): UsagePreferences {
+ return { ...DEFAULT_USAGE_PREFERENCES, cardOrder };
+}
+
+describe("usage card order", () => {
+ it("shows cards by provider, then account, whatever order they arrive in", () => {
+ const expected = ["claude:personal", "claude:work", "codex:default", "copilot:default"];
+ for (const arrival of [
+ [codex, claudeWork, copilot, claudePersonal],
+ [copilot, claudePersonal, codex, claudeWork],
+ ]) {
+ expect(ids(arrangeUsageReports(arrival, DEFAULT_USAGE_PREFERENCES))).toEqual(expected);
+ }
+ });
+
+ it("puts the cards the user arranged first, in their order", () => {
+ const preferences = arranged(["copilot:default", "claude:work"]);
+
+ expect(
+ ids(arrangeUsageReports([claudeWork, codex, claudePersonal, copilot], preferences)),
+ ).toEqual(["copilot:default", "claude:work", "claude:personal", "codex:default"]);
+ });
+
+ it("lands a report from a new login in its default slot after the arranged cards", () => {
+ const preferences = arrangeUsageCards(DEFAULT_USAGE_PREFERENCES, {
+ moved: "codex:default",
+ after: ["codex:default", "claude:work"],
+ });
+ const newLogin = report("claude", "Claude", "agent");
+
+ expect(ids(arrangeUsageReports([newLogin, claudeWork, codex], preferences))).toEqual([
+ "codex:default",
+ "claude:work",
+ "claude:agent",
+ ]);
+ });
+
+ it("keeps another host's arrangement when a drop on this host moves a card both show", () => {
+ // Host A shows Codex, Claude and Gemini; host B shows Copilot and the same Claude account.
+ const hostA = [codex, claudeWork, gemini];
+ const hostB = [claudeWork, copilot];
+ const arrangedOnA = arrangeUsageCards(DEFAULT_USAGE_PREFERENCES, {
+ moved: "codex:default",
+ after: ["codex:default", "claude:work", "gemini:default"],
+ });
+
+ const after = ["copilot:default", "claude:work"];
+ const arrangedOnB = arrangeUsageCards(arrangedOnA, { moved: "copilot:default", after });
+
+ expect(ids(arrangeUsageReports(hostA, arrangedOnB))).toEqual([
+ "codex:default",
+ "claude:work",
+ "gemini:default",
+ ]);
+ expect(ids(arrangeUsageReports(hostB, arrangedOnB))).toEqual(after);
+ });
+
+ it("moves only the dragged card when it swaps with its neighbour", () => {
+ // Gemini sits between Codex and Copilot, but only another host shows it.
+ const preferences = arranged(["codex:default", "gemini:default", "copilot:default"]);
+ const swapped = arrangeUsageCards(preferences, {
+ moved: "codex:default",
+ after: ["copilot:default", "codex:default"],
+ });
+
+ expect(ids(arrangeUsageReports([codex, copilot], swapped))).toEqual([
+ "copilot:default",
+ "codex:default",
+ ]);
+ expect(ids(arrangeUsageReports([gemini, copilot], swapped))).toEqual([
+ "gemini:default",
+ "copilot:default",
+ ]);
+ });
+});
+
+describe("usage cards turned off", () => {
+ it("turns a card off and back on", () => {
+ const off = setUsageCardOn(DEFAULT_USAGE_PREFERENCES, "codex:default", false);
+ expect(off.cardsOff).toEqual(["codex:default"]);
+ expect(setUsageCardOn(off, "codex:default", true).cardsOff).toEqual([]);
+ });
+
+ it("leaves off cards out of the sidebar summary", () => {
+ const preferences = setUsageCardOn(DEFAULT_USAGE_PREFERENCES, "codex:default", false);
+
+ expect(ids(usageReportsOn([codex, claudeWork], preferences))).toEqual(["claude:work"]);
+ expect(
+ resolvePinnedUsage([codex, claudeWork], preferences).map((source) => source.key),
+ ).toEqual(["claude:work"]);
+ });
+
+ it("orders the sidebar summary like the cards", () => {
+ const preferences = arranged(["codex:default"]);
+
+ expect(
+ resolvePinnedUsage([claudeWork, codex], preferences).map((source) => source.key),
+ ).toEqual(["codex:default", "claude:work"]);
+ });
+});
+
+describe("stored card preferences", () => {
+ it("reads settings saved before cards could be arranged as no arrangement", () => {
+ expect(UsagePreferencesSchema.parse({ displayAs: "used", serverId: null })).toEqual(
+ DEFAULT_USAGE_PREFERENCES,
+ );
+ });
+
+ it("survives a save and reload, and ignores a malformed arrangement", () => {
+ const saved = setUsageCardOn(arranged(["codex:default"]), "claude:work", false);
+ expect(UsagePreferencesSchema.parse(JSON.parse(JSON.stringify(saved)))).toEqual(saved);
+ expect(
+ UsagePreferencesSchema.parse({ displayAs: "used", cardOrder: "bad", cardsOff: [1] }),
+ ).toEqual(DEFAULT_USAGE_PREFERENCES);
+ });
+});
diff --git a/packages/app/src/usage/controls.tsx b/packages/app/src/usage/controls.tsx
index f0a8c73f5..ffe51271e 100644
--- a/packages/app/src/usage/controls.tsx
+++ b/packages/app/src/usage/controls.tsx
@@ -16,47 +16,41 @@ export interface UsageHostSelection {
}
/**
- * The controls on the right of every usage title row: the host filter when there is more than one
- * host, Refresh all, and the Settings cog. A host that cannot report usage keeps only the host filter.
+ * The controls on the right of every usage title row: Refresh all and the Settings cog. A host
+ * that cannot report usage has none.
*/
export function UsageControls({
view,
serverId,
onRefresh,
- hostSelection,
}: {
view: UsageView;
serverId: string;
onRefresh: () => void;
- hostSelection?: UsageHostSelection;
}) {
const busy = view.kind === "loading" || (view.kind === "ready" && view.isRefreshing);
+ if (view.kind === "unavailable") return null;
return (
- {hasHostChoice(hostSelection) ? (
-
- ) : null}
- {view.kind === "unavailable" ? null : (
- <>
- {view.kind === "off" ? null : }
-
- >
- )}
+ {view.kind === "off" ? null : }
+
);
}
-function hasHostChoice(
- hostSelection: UsageHostSelection | undefined,
-): hostSelection is UsageHostSelection {
- return hostSelection !== undefined && hostSelection.hosts.length > 1;
+/** The host whose usage shows, when there is more than one to choose from. */
+function UsageHostFilter({ hostSelection }: { hostSelection: UsageHostSelection }) {
+ return (
+
+ );
}
function usageHostOptionTestID(serverId: string): string {
@@ -73,27 +67,28 @@ const styles = StyleSheet.create((theme) => ({
}));
/**
- * One host’s usage and title-row controls for the Usage modal.
- * Returns null when there is nothing to control, so headers leave no empty island.
+ * One host’s usage for the Usage modal: its title-row controls, null when there is nothing to
+ * control so the header leaves no empty island, and the host filter for the top of the body, null
+ * with a single host.
*/
export function useHostUsageWithControls(hostSelection: UsageHostSelection): {
view: UsageView;
refresh: () => void;
controls: ReactElement | null;
+ hostFilter: ReactElement | null;
} {
const { view, refresh } = useHostUsage(hostSelection.serverId);
- const hasControls = hasHostChoice(hostSelection) || view.kind !== "unavailable";
const controls = useMemo(
() =>
- hasControls ? (
-
- ) : null,
- [hasControls, hostSelection, refresh, view],
+ view.kind === "unavailable" ? null : (
+
+ ),
+ [hostSelection.serverId, refresh, view],
);
- return { view, refresh, controls };
+ const hostFilter = useMemo(
+ () =>
+ hostSelection.hosts.length > 1 ? : null,
+ [hostSelection],
+ );
+ return { view, refresh, controls, hostFilter };
}
diff --git a/packages/app/src/usage/display.ts b/packages/app/src/usage/display.ts
index c62ed78fd..f54c16883 100644
--- a/packages/app/src/usage/display.ts
+++ b/packages/app/src/usage/display.ts
@@ -1,21 +1,32 @@
import { useCallback, useMemo } from "react";
import { useAppSettings } from "@/hooks/use-settings";
import {
+ arrangeUsageCards,
+ arrangeUsageReports,
+ isUsageCardOff,
isUsagePinned,
+ setUsageCardOn,
setUsageDisplayAs,
toggleUsagePin,
+ type UsageCardDrop,
type UsageDisplayAs,
type UsagePin,
type UsagePreferences,
} from "./preferences";
import type { UsageReportEntry } from "./types";
-/** What usage views need from the preferences: how to read percents, and the pins. */
+/** What usage views need from the preferences: how to read percents, the pins, and the cards. */
export interface UsageDisplay {
displayAs: UsageDisplayAs;
setDisplayAs: (displayAs: UsageDisplayAs) => void;
isPinned: (pin: UsagePin) => boolean;
togglePin: (pin: UsagePin) => void;
+ /** Reports in the order their cards show. */
+ arrange: (reports: readonly UsageReportEntry[]) => UsageReportEntry[];
+ /** Saves the order of the shown cards after the user drops one. */
+ arrangeCards: (drop: UsageCardDrop) => void;
+ isCardOn: (reportId: string) => boolean;
+ setCardOn: (reportId: string, on: boolean) => void;
}
interface UsagePreferencesState {
@@ -41,14 +52,30 @@ export function useUsageDisplay(reports: readonly UsageReportEntry[]): UsagePref
},
[updateSettings, reports],
);
+ const arrangeCards = useCallback(
+ (drop: UsageCardDrop) => {
+ void updateSettings((current) => ({ usage: arrangeUsageCards(current.usage, drop) }));
+ },
+ [updateSettings],
+ );
+ const setCardOn = useCallback(
+ (reportId: string, on: boolean) => {
+ void updateSettings((current) => ({ usage: setUsageCardOn(current.usage, reportId, on) }));
+ },
+ [updateSettings],
+ );
const display = useMemo(
() => ({
displayAs: preferences.displayAs,
setDisplayAs,
isPinned: (pin) => isUsagePinned(preferences, pin, reports),
togglePin,
+ arrange: (shown) => arrangeUsageReports(shown, preferences),
+ arrangeCards,
+ isCardOn: (reportId) => !isUsageCardOff(preferences, reportId),
+ setCardOn,
}),
- [preferences, reports, setDisplayAs, togglePin],
+ [arrangeCards, preferences, reports, setCardOn, setDisplayAs, togglePin],
);
return { preferences, display };
}
diff --git a/packages/app/src/usage/format.ts b/packages/app/src/usage/format.ts
index 867976a58..16386810f 100644
--- a/packages/app/src/usage/format.ts
+++ b/packages/app/src/usage/format.ts
@@ -2,7 +2,7 @@ import type { TFunction } from "i18next";
import { i18n } from "@/i18n/i18next";
import { formatTimeOfDay } from "@/utils/time";
import type { UsageDisplayAs } from "./preferences";
-import type { UsageBalanceUnit } from "./types";
+import type { UsageBalanceUnit, UsageReportEntry } from "./types";
const providerUsageLabels = {
session: { label: "Session", key: "providerUsage.labels.session" },
@@ -13,6 +13,11 @@ const providerUsageLabels = {
monthly_credits: { label: "Monthly credits", key: "providerUsage.labels.monthlyCredits" },
} as const;
+/** The source, with the account when the report names one: "Claude (work)". */
+export function formatUsageAccountName(entry: UsageReportEntry): string {
+ return entry.account.label ? `${entry.sourceLabel} (${entry.account.label})` : entry.sourceLabel;
+}
+
export function formatProviderUsageLabel(id: string, label: string, t: TFunction = i18n.t): string {
const reviewPrefix = "Code review · ";
if (id.startsWith("code_review:") && label.startsWith(reviewPrefix)) {
diff --git a/packages/app/src/usage/list.tsx b/packages/app/src/usage/list.tsx
index 10e76ba57..e9218ae32 100644
--- a/packages/app/src/usage/list.tsx
+++ b/packages/app/src/usage/list.tsx
@@ -1,12 +1,24 @@
+import { useCallback, useMemo, useState } from "react";
import { View } from "react-native";
import { StyleSheet } from "react-native-unistyles";
+import { DraggableList } from "@/components/draggable-list";
+import type { DraggableRenderItemInfo } from "@/components/draggable-list.types";
+import { useIsCompactFormFactor } from "@/constants/layout";
+import { isNative } from "@/constants/platform";
import { settingsStyles } from "@/styles/settings";
import { UsageCard } from "./card";
import type { UsageDisplay } from "./display";
import { useUsageInSidebar } from "./in-sidebar";
import type { UsageReportEntry } from "./types";
-/** One card per report (source + account). Window rows pin while the sidebar summary is on. */
+function reportKey(entry: UsageReportEntry): string {
+ return entry.id;
+}
+
+/**
+ * One card per report (source + account), in the user's order. Each card drags by its handle and
+ * turns off from its switch. Window rows pin while the sidebar summary is on.
+ */
export function UsageList({
serverId,
reports,
@@ -17,25 +29,113 @@ export function UsageList({
display: UsageDisplay;
}) {
const { inSidebar } = useUsageInSidebar();
+ const { arrange, arrangeCards } = display;
+ const arranged = useMemo(() => arrange(reports), [arrange, reports]);
+ const handleDragEnd = useCallback(
+ (next: UsageReportEntry[], moved: string) =>
+ arrangeCards({ moved, after: next.map(reportKey) }),
+ [arrangeCards],
+ );
+ const renderItem = useCallback(
+ ({ item, isActive }: DraggableRenderItemInfo) => (
+
+
+
+ ),
+ [display, inSidebar, serverId],
+ );
return (
-
- {reports.map((entry) => (
-
-
-
- ))}
+
+ );
+}
+
+/**
+ * The card inside its hover target: the drag handle shows while the pointer is over the card or
+ * keyboard focus is inside it, and always where there is no hover.
+ */
+function UsageListCard({
+ serverId,
+ entry,
+ display,
+ pinnable,
+ dragging,
+}: {
+ serverId: string;
+ entry: UsageReportEntry;
+ display: UsageDisplay;
+ pinnable: boolean;
+ dragging: boolean;
+}) {
+ const isCompact = useIsCompactFormFactor();
+ const [isHovered, setIsHovered] = useState(false);
+ const handlePointerEnter = useCallback(() => setIsHovered(true), []);
+ const handlePointerLeave = useCallback(() => setIsHovered(false), []);
+ // Focus events bubble from the card's controls, so tabbing onto the handle reveals it.
+ const [hasFocus, setHasFocus] = useState(false);
+ const handleFocus = useCallback(() => setHasFocus(true), []);
+ const handleBlur = useCallback(() => setHasFocus(false), []);
+ const { isCardOn, setCardOn } = display;
+ const on = isCardOn(entry.id);
+ const handleSetOn = useCallback(
+ (next: boolean) => setCardOn(entry.id, next),
+ [entry.id, setCardOn],
+ );
+ const arrangement = useMemo(
+ () => ({
+ on,
+ onSetOn: handleSetOn,
+ handleVisible: isHovered || hasFocus || dragging || isNative || isCompact,
+ }),
+ [dragging, handleSetOn, hasFocus, isCompact, isHovered, on],
+ );
+ return (
+
+
+
+
);
}
const styles = StyleSheet.create((theme) => ({
+ // Each card carries the gap below it, so a native drag moves it with its slot; the list
+ // takes the last one back.
list: {
- gap: theme.spacing[3],
+ marginBottom: -theme.spacing[3],
+ },
+ item: {
+ paddingBottom: theme.spacing[3],
+ },
+ hoverTarget: {
+ position: "relative",
},
}));
diff --git a/packages/app/src/usage/options.tsx b/packages/app/src/usage/options.tsx
index cc674cb90..9e12517da 100644
--- a/packages/app/src/usage/options.tsx
+++ b/packages/app/src/usage/options.tsx
@@ -3,8 +3,11 @@ import { View } from "react-native";
import { Settings } from "lucide-react-native";
import { withUnistyles } from "react-native-unistyles";
import { DropdownMenu, DropdownMenuContent } from "@/components/ui/dropdown-menu";
-import { extraMutedIconColorMapping } from "@/components/ui/icon-button-chrome";
-import { ToolbarButton, paneContentToolbarIconSize } from "@/components/ui/pane-content-toolbar";
+import {
+ mutedIconColorMapping,
+ useIconButtonChromeGlyphSize,
+} from "@/components/ui/icon-button-chrome";
+import { ToolbarButton } from "@/components/ui/pane-content-toolbar";
import { useIsCompactFormFactor } from "@/constants/layout";
import { SettingsRow, SettingsSwitch } from "@/components/settings";
import { SegmentedControl, type SegmentedControlOption } from "@/components/ui/segmented-control";
@@ -32,6 +35,7 @@ export function UsageOptions({ serverId }: { serverId: string | null }) {
},
];
const compact = useIsCompactFormFactor();
+ const glyphSize = useIconButtonChromeGlyphSize("small", compact);
const { display } = useUsageDisplay([]);
const { inSidebar, setInSidebar } = useUsageInSidebar();
return (
@@ -42,10 +46,7 @@ export function UsageOptions({ serverId }: { serverId: string | null }) {
compact={compact}
testID="usage-options-menu"
>
-
+
{
@@ -114,7 +114,7 @@ describe("resolvePinnedUsage", () => {
]);
});
- it("groups pinned windows by source in report order, not pin order", () => {
+ it("lists pinned windows in card order, not pin order", () => {
const work = report({
sourceId: "claude",
sourceLabel: "Claude",
@@ -161,6 +161,28 @@ describe("resolvePinnedUsage", () => {
});
});
+ it("follows the arranged card order, even when it separates a source's accounts", () => {
+ const work = report({
+ sourceId: "claude",
+ sourceLabel: "Claude",
+ account: "work",
+ windows: [{ id: "weekly", label: "Weekly", usedPct: 90 }],
+ });
+ const sources = resolvePinnedUsage([claude, codex, work], {
+ ...preferences([
+ { sourceId: "claude", windowId: "weekly" },
+ { sourceId: "codex", windowId: "weekly" },
+ ]),
+ cardOrder: ["claude:default", "codex:default", "claude:work"],
+ });
+
+ expect(sources.map((source) => source.key)).toEqual([
+ "claude:default",
+ "codex:default",
+ "claude:work",
+ ]);
+ });
+
it("names a window by its label when the source gives no short label", () => {
const items = windows([codex], preferences([{ sourceId: "codex", windowId: "weekly" }]));
diff --git a/packages/app/src/usage/pinned.ts b/packages/app/src/usage/pinned.ts
index acce210a7..b725c3e08 100644
--- a/packages/app/src/usage/pinned.ts
+++ b/packages/app/src/usage/pinned.ts
@@ -1,8 +1,13 @@
import type { TFunction } from "i18next";
import { i18n } from "@/i18n/i18next";
-import { formatPct, formatDisplayPct, formatProviderUsageLabel } from "./format";
+import {
+ formatPct,
+ formatDisplayPct,
+ formatProviderUsageLabel,
+ formatUsageAccountName,
+} from "./format";
import { displayPercent, resolveUsageSnapshot } from "./model";
-import { effectiveUsagePins, type UsagePreferences } from "./preferences";
+import { effectiveUsagePins, usageReportsOn, type UsagePreferences } from "./preferences";
import { windowTone } from "./tone";
import type { UsageReportEntry, UsageTone } from "./types";
@@ -55,19 +60,12 @@ export function choosePinnedUsageLayout(input: {
}
function describe(entry: UsageReportEntry, windowLabel: string): string {
- const account = entry.account.label ? ` (${entry.account.label})` : "";
- return `${entry.sourceLabel}${account} ${windowLabel}`;
-}
-
-/** Reports with every account of a source together, sources in the order they first appear. */
-function groupBySource(reports: readonly UsageReportEntry[]): UsageReportEntry[] {
- const sourceIds = [...new Set(reports.map((entry) => entry.sourceId))];
- return sourceIds.flatMap((sourceId) => reports.filter((entry) => entry.sourceId === sourceId));
+ return `${formatUsageAccountName(entry)} ${windowLabel}`;
}
/**
- * The sidebar Usage item's summary: one group per account, grouped by source, each with its
- * windows in its report's order. Accounts with nothing to show are left out.
+ * The sidebar Usage item's summary: one group per account in card order, each with its windows in
+ * its report's order. Accounts turned off or with nothing to show are left out.
*/
export function resolvePinnedUsage(
reports: readonly UsageReportEntry[],
@@ -75,7 +73,7 @@ export function resolvePinnedUsage(
t: TFunction = i18n.t,
): PinnedUsageSource[] {
const pins = effectiveUsagePins(preferences, reports);
- return groupBySource(reports).flatMap((entry) => {
+ return usageReportsOn(reports, preferences).flatMap((entry) => {
const snapshot = resolveUsageSnapshot(entry);
if (!snapshot) return [];
const windows = snapshot.report.windows
diff --git a/packages/app/src/usage/preferences.test.ts b/packages/app/src/usage/preferences.test.ts
index 43dccc466..064920fb5 100644
--- a/packages/app/src/usage/preferences.test.ts
+++ b/packages/app/src/usage/preferences.test.ts
@@ -31,7 +31,7 @@ describe("usage preferences", () => {
it("unpins a pinned window and keeps the others in order", () => {
const three = [codexWeekly, claudeFiveHour, { sourceId: "claude", windowId: "weekly" }];
const unpinned = toggleUsagePin({
- preferences: { displayAs: "used", pins: three, serverId: null },
+ preferences: { ...DEFAULT_USAGE_PREFERENCES, pins: three },
pin: claudeFiveHour,
reports: [],
});
@@ -40,18 +40,18 @@ describe("usage preferences", () => {
});
it("switches between used and remaining without touching pins", () => {
- const preferences = { displayAs: "used" as const, pins: [codexWeekly], serverId: null };
+ const preferences = { ...DEFAULT_USAGE_PREFERENCES, pins: [codexWeekly] };
expect(setUsageDisplayAs(preferences, "remaining")).toEqual({
+ ...DEFAULT_USAGE_PREFERENCES,
displayAs: "remaining",
pins: [codexWeekly],
- serverId: null,
});
});
it("remembers the picked host without touching pins", () => {
expect(setUsageHost({ ...DEFAULT_USAGE_PREFERENCES, pins: [codexWeekly] }, "server")).toEqual({
- displayAs: "used",
+ ...DEFAULT_USAGE_PREFERENCES,
pins: [codexWeekly],
serverId: "server",
});
@@ -59,7 +59,7 @@ describe("usage preferences", () => {
it("reads preferences saved before hosts could be picked as no pick", () => {
expect(UsagePreferencesSchema.parse({ displayAs: "remaining", pinned: [codexWeekly] })).toEqual(
- { displayAs: "remaining", pins: [codexWeekly], serverId: null },
+ { ...DEFAULT_USAGE_PREFERENCES, displayAs: "remaining", pins: [codexWeekly] },
);
});
});
@@ -125,6 +125,6 @@ it("reads old selections without losing display or host and preserves an explici
] as const) {
expect(
UsagePreferencesSchema.parse({ displayAs: "remaining", serverId: "host", ...input }),
- ).toEqual({ displayAs: "remaining", serverId: "host", pins });
+ ).toEqual({ ...DEFAULT_USAGE_PREFERENCES, displayAs: "remaining", serverId: "host", pins });
}
});
diff --git a/packages/app/src/usage/preferences.ts b/packages/app/src/usage/preferences.ts
index b9c5c6fde..7ad7d5a3e 100644
--- a/packages/app/src/usage/preferences.ts
+++ b/packages/app/src/usage/preferences.ts
@@ -18,15 +18,22 @@ export interface UsagePreferences {
pins: UsagePin[] | null;
/** The host the user picked to show usage for; null until they pick one. */
serverId: string | null;
+ /** Report IDs the user arranged, in their order. Shared by every host. */
+ cardOrder: string[];
+ /** Report IDs the user turned off. Their cards collapse and leave the sidebar summary. */
+ cardsOff: string[];
}
export const DEFAULT_USAGE_PREFERENCES: UsagePreferences = {
displayAs: "used",
pins: null,
serverId: null,
+ cardOrder: [],
+ cardsOff: [],
};
const pinsSchema = z.array(z.object({ sourceId: z.string(), windowId: z.string() }));
+const reportIdsSchema = z.array(z.string()).optional().catch(undefined);
export const UsagePreferencesSchema = z
.object({
@@ -36,10 +43,18 @@ export const UsagePreferencesSchema = z
// Old [] meant defaults. Read it only when the new selection is absent.
pinned: pinsSchema.optional().catch([]),
serverId: z.string().nullable().catch(null),
+ cardOrder: reportIdsSchema,
+ cardsOff: reportIdsSchema,
})
- .transform(({ displayAs, pins, pinned, serverId }): UsagePreferences => {
+ .transform(({ displayAs, pins, pinned, serverId, cardOrder, cardsOff }): UsagePreferences => {
const legacyPins = pinned && pinned.length > 0 ? pinned : null;
- return { displayAs, pins: pins === undefined ? legacyPins : pins, serverId };
+ return {
+ displayAs,
+ pins: pins === undefined ? legacyPins : pins,
+ serverId,
+ cardOrder: cardOrder ?? [],
+ cardsOff: cardsOff ?? [],
+ };
})
.catch(DEFAULT_USAGE_PREFERENCES);
@@ -104,3 +119,84 @@ export function setUsageDisplayAs(
export function setUsageHost(preferences: UsagePreferences, serverId: string): UsagePreferences {
return { ...preferences, serverId };
}
+
+/** Reports the user has not arranged: by provider, then account, then ID. */
+function compareByDefaultOrder(a: UsageReportEntry, b: UsageReportEntry): number {
+ return (
+ a.sourceLabel.localeCompare(b.sourceLabel) ||
+ (a.account.label ?? "").localeCompare(b.account.label ?? "") ||
+ a.id.localeCompare(b.id)
+ );
+}
+
+/**
+ * Reports in the order their cards show: the ones the user arranged first, in their order, then
+ * the rest in the default order. Arrival order never matters, so a report that streams in late or
+ * appears for a new login lands in its own slot.
+ */
+export function arrangeUsageReports(
+ reports: readonly UsageReportEntry[],
+ preferences: UsagePreferences,
+): UsageReportEntry[] {
+ const rank = new Map(preferences.cardOrder.map((id, index) => [id, index]));
+ return [...reports].sort((a, b) => {
+ const rankA = rank.get(a.id);
+ const rankB = rank.get(b.id);
+ if (rankA !== undefined && rankB !== undefined) return rankA - rankB;
+ if (rankA !== undefined) return -1;
+ if (rankB !== undefined) return 1;
+ return compareByDefaultOrder(a, b);
+ });
+}
+
+/** Reports whose cards are on, in card order: what the sidebar summary reads. */
+export function usageReportsOn(
+ reports: readonly UsageReportEntry[],
+ preferences: UsagePreferences,
+): UsageReportEntry[] {
+ return arrangeUsageReports(reports, preferences).filter(
+ (entry) => !isUsageCardOff(preferences, entry.id),
+ );
+}
+
+/** A drop as the list reports it: the card the user moved and the shown cards' order after it. */
+export interface UsageCardDrop {
+ moved: string;
+ after: readonly string[];
+}
+
+/**
+ * The order after the user drops a card. Only the moved card changes place: it goes just before
+ * its new successor among the shown cards, or just after its new predecessor when it lands last.
+ * Shown cards not yet arranged are added at the end, in their shown order. Other arranged cards
+ * keep their places relative to each other. The order is shared by every host, so a drop that
+ * arranges a card another host also shows ranks it ahead of that host's unarranged cards.
+ */
+export function arrangeUsageCards(
+ preferences: UsagePreferences,
+ { moved, after }: UsageCardDrop,
+): UsagePreferences {
+ const arranged = new Set([...preferences.cardOrder, moved]);
+ const rest = [
+ ...preferences.cardOrder.filter((id) => id !== moved),
+ ...after.filter((id) => !arranged.has(id)),
+ ];
+ const index = after.indexOf(moved);
+ const successor = after[index + 1];
+ const at = successor === undefined ? rest.indexOf(after[index - 1]) + 1 : rest.indexOf(successor);
+ rest.splice(at, 0, moved);
+ return { ...preferences, cardOrder: rest };
+}
+
+export function isUsageCardOff(preferences: UsagePreferences, reportId: string): boolean {
+ return preferences.cardsOff.includes(reportId);
+}
+
+export function setUsageCardOn(
+ preferences: UsagePreferences,
+ reportId: string,
+ on: boolean,
+): UsagePreferences {
+ const others = preferences.cardsOff.filter((id) => id !== reportId);
+ return { ...preferences, cardsOff: on ? others : [...others, reportId] };
+}
diff --git a/packages/app/src/usage/refresh-button.tsx b/packages/app/src/usage/refresh-button.tsx
index 473e4442c..80a31389e 100644
--- a/packages/app/src/usage/refresh-button.tsx
+++ b/packages/app/src/usage/refresh-button.tsx
@@ -1,9 +1,12 @@
import { useTranslation } from "react-i18next";
import { RotateCw } from "lucide-react-native";
import { withUnistyles } from "react-native-unistyles";
-import { extraMutedIconColorMapping } from "@/components/ui/icon-button-chrome";
+import {
+ mutedIconColorMapping,
+ useIconButtonChromeGlyphSize,
+} from "@/components/ui/icon-button-chrome";
import { LoadingSpinner } from "@/components/ui/loading-spinner";
-import { ToolbarButton, paneContentToolbarIconSize } from "@/components/ui/pane-content-toolbar";
+import { ToolbarButton } from "@/components/ui/pane-content-toolbar";
import { useIsCompactFormFactor } from "@/constants/layout";
const ThemedRotateCw = withUnistyles(RotateCw);
@@ -16,7 +19,7 @@ const ThemedLoadingSpinner = withUnistyles(LoadingSpinner);
export function UsageRefreshButton({ busy, onRefresh }: { busy: boolean; onRefresh: () => void }) {
const { t } = useTranslation();
const compact = useIsCompactFormFactor();
- const iconSize = paneContentToolbarIconSize(compact);
+ const iconSize = useIconButtonChromeGlyphSize("small", compact);
return (
{busy ? (
-
+
) : (
-
+
)}
);
diff --git a/packages/app/src/usage/usage-modal.tsx b/packages/app/src/usage/usage-modal.tsx
index 4e049c0b5..f78b9ac3e 100644
--- a/packages/app/src/usage/usage-modal.tsx
+++ b/packages/app/src/usage/usage-modal.tsx
@@ -17,8 +17,8 @@ interface UsageModalProps {
/**
* Usage over the current screen: a dialog on wide layouts, a bottom sheet on compact ones. It
- * shows the usage host's reports with pins, and the host filter, Refresh all, and Settings in its
- * title row.
+ * shows the usage host's reports with pins, Refresh all and Settings in its title row, and the
+ * host filter at the top of its body.
*/
export function UsageModal(props: UsageModalProps) {
const { t } = useTranslation();
@@ -56,10 +56,10 @@ function HostUsageModal({
() => ({ hosts, serverId, onSelect: onSelectHost }),
[hosts, onSelectHost, serverId],
);
- const { view, refresh, controls } = useHostUsageWithControls(hostSelection);
+ const { view, refresh, controls, hostFilter } = useHostUsageWithControls(hostSelection);
const { display } = useUsageDisplay(view.kind === "ready" ? view.reports : []);
return (
-
+
@@ -72,8 +72,9 @@ function UsageModalFrame({
onClose,
onDismiss,
actions,
+ hostFilter,
children,
-}: UsageModalProps & { actions?: ReactNode; children: ReactNode }) {
+}: UsageModalProps & { actions?: ReactNode; hostFilter?: ReactNode; children: ReactNode }) {
const { t } = useTranslation();
const title = t(builtinSidebarNavLabelKey("usage"));
const header = useMemo(() => ({ title, actions }), [actions, title]);
@@ -87,6 +88,7 @@ function UsageModalFrame({
contextBridge={null}
testID="usage-modal"
>
+ {hostFilter}
{children}