fix(mobile): harden redesigned interactions
This commit is contained in:
10 files changed
+104
-42
No files matched your search
@@ -55,6 +55,7 @@ export function ModelPickerSheet(props: {
|
||||
readonly groups: ReadonlyArray<ProviderGroup>;
|
||||
readonly selectedModel: ModelSelection | null;
|
||||
readonly favoriteModelKeys: ReadonlySet<string>;
|
||||
readonly favoritesEnabled: boolean;
|
||||
readonly onClose: () => void;
|
||||
readonly onSelectModel: (option: ModelOption) => void;
|
||||
readonly onToggleFavorite: (option: ModelOption) => void;
|
||||
@@ -252,9 +253,12 @@ export function ModelPickerSheet(props: {
|
||||
<Pressable
|
||||
accessibilityLabel={favorite ? "Remove from favorites" : "Add to favorites"}
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ disabled: !props.favoritesEnabled }}
|
||||
className="ml-3 h-11 w-11 items-center justify-center active:opacity-60"
|
||||
disabled={!props.favoritesEnabled}
|
||||
hitSlop={4}
|
||||
onPress={() => props.onToggleFavorite(item.option)}
|
||||
style={{ opacity: props.favoritesEnabled ? 1 : 0.45 }}
|
||||
>
|
||||
<SymbolView
|
||||
name={favorite ? "star.fill" : "star"}
|
||||
|
||||
@@ -56,6 +56,7 @@ export function HomeHeader(props: {
|
||||
|
||||
const focusSearch = useCallback(() => {
|
||||
setSearchVisible(true);
|
||||
searchInputRef.current?.focus();
|
||||
return true;
|
||||
}, []);
|
||||
useHardwareKeyboardCommand("focusSearch", focusSearch);
|
||||
|
||||
@@ -33,29 +33,33 @@ export function WorkspaceConnectionStatus(props: {
|
||||
const tintColor = presentation.tone === "amber" ? "#fbbf24" : "#f87171";
|
||||
const label = `${presentation.label} ${presentation.detail}`;
|
||||
return (
|
||||
<View
|
||||
accessibilityLabel={label}
|
||||
accessibilityRole="summary"
|
||||
className="h-12 min-w-0 flex-row items-center gap-2.5"
|
||||
>
|
||||
<SymbolView
|
||||
name={
|
||||
presentation.tone === "amber" ? "point.3.connected.trianglepath.dotted" : "wifi.slash"
|
||||
}
|
||||
size={17}
|
||||
tintColor={tintColor}
|
||||
type="monochrome"
|
||||
/>
|
||||
<Text
|
||||
className="min-w-0 shrink text-base font-t3-bold"
|
||||
numberOfLines={1}
|
||||
style={{ color: tintColor }}
|
||||
<View className="h-12 min-w-0 flex-row items-center gap-2.5">
|
||||
<Pressable
|
||||
accessibilityHint="Opens environment settings"
|
||||
accessibilityLabel={label}
|
||||
accessibilityRole="button"
|
||||
className="min-w-0 flex-1 flex-row items-center gap-2.5 self-stretch"
|
||||
onPress={props.onPress}
|
||||
>
|
||||
{presentation.label}{" "}
|
||||
<Text className="text-sm font-t3-medium" style={{ color: tintColor, opacity: 0.72 }}>
|
||||
{presentation.detail}
|
||||
<SymbolView
|
||||
name={
|
||||
presentation.tone === "amber" ? "point.3.connected.trianglepath.dotted" : "wifi.slash"
|
||||
}
|
||||
size={17}
|
||||
tintColor={tintColor}
|
||||
type="monochrome"
|
||||
/>
|
||||
<Text
|
||||
className="min-w-0 shrink text-base font-t3-bold"
|
||||
numberOfLines={1}
|
||||
style={{ color: tintColor }}
|
||||
>
|
||||
{presentation.label}{" "}
|
||||
<Text className="text-sm font-t3-medium" style={{ color: tintColor, opacity: 0.72 }}>
|
||||
{presentation.detail}
|
||||
</Text>
|
||||
</Text>
|
||||
</Text>
|
||||
</Pressable>
|
||||
{presentation.tone === "red" && props.onReconnect ? (
|
||||
<Pressable
|
||||
accessibilityLabel={`Reconnect ${presentation.label}`}
|
||||
|
||||
@@ -83,7 +83,7 @@ export function NewTaskDraftScreen(props: {
|
||||
const selectedEnvironmentServerConfig = useEnvironmentServerConfig(
|
||||
selectedProject?.environmentId ?? null,
|
||||
);
|
||||
const { favoriteModelKeys, toggleFavorite } = useModelFavorites(
|
||||
const { favoriteModelKeys, favoritesReady, toggleFavorite } = useModelFavorites(
|
||||
selectedProject?.environmentId ?? null,
|
||||
);
|
||||
const environmentConnected =
|
||||
@@ -1070,6 +1070,7 @@ export function NewTaskDraftScreen(props: {
|
||||
</KeyboardAvoidingView>
|
||||
<ModelPickerSheet
|
||||
favoriteModelKeys={favoriteModelKeys}
|
||||
favoritesEnabled={favoritesReady}
|
||||
groups={flow.providerGroups}
|
||||
onClose={() => setModelPickerVisible(false)}
|
||||
onSelectModel={(option) => flow.setSelectedModelKey(option.key)}
|
||||
|
||||
@@ -49,13 +49,14 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
|
||||
const isLastQuestion = questionIndex >= props.pendingUserInput.questions.length - 1;
|
||||
const canGoBack = questionIndex > 0 && !isResponding;
|
||||
const canAdvance = hasDraftAnswer(draft);
|
||||
const canContinue = isLastQuestion ? props.answers !== null : canAdvance;
|
||||
|
||||
if (!activeQuestion) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleAdvance = () => {
|
||||
if (!canAdvance || isResponding) {
|
||||
if (!canContinue || isResponding) {
|
||||
return;
|
||||
}
|
||||
if (!isLastQuestion) {
|
||||
@@ -177,18 +178,18 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
|
||||
<Pressable
|
||||
accessibilityLabel={isLastQuestion ? "Submit answers" : "Next question"}
|
||||
accessibilityRole="button"
|
||||
accessibilityState={{ disabled: !canAdvance || isResponding }}
|
||||
accessibilityState={{ disabled: !canContinue || isResponding }}
|
||||
className={cn(
|
||||
"min-h-11 items-center justify-center rounded-full px-5",
|
||||
canAdvance && !isResponding ? "bg-blue-600" : "bg-subtle-strong",
|
||||
canContinue && !isResponding ? "bg-blue-600" : "bg-subtle-strong",
|
||||
)}
|
||||
disabled={!canAdvance || isResponding}
|
||||
disabled={!canContinue || isResponding}
|
||||
onPress={handleAdvance}
|
||||
>
|
||||
<Text
|
||||
className={cn(
|
||||
"font-t3-bold text-base",
|
||||
canAdvance && !isResponding ? "text-white" : "text-foreground-tertiary",
|
||||
canContinue && !isResponding ? "text-white" : "text-foreground-tertiary",
|
||||
)}
|
||||
>
|
||||
{isLastQuestion ? "Submit answers" : "Next question"}
|
||||
|
||||
@@ -603,7 +603,9 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
}),
|
||||
[currentModelOption?.capabilities, currentModelSelection.options],
|
||||
);
|
||||
const { favoriteModelKeys, toggleFavorite } = useModelFavorites(props.environmentId);
|
||||
const { favoriteModelKeys, favoritesReady, toggleFavorite } = useModelFavorites(
|
||||
props.environmentId,
|
||||
);
|
||||
|
||||
// ── Options menu ─────────────────────────────────────────
|
||||
const optionsMenuActions = useMemo(
|
||||
@@ -909,6 +911,7 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
|
||||
/>
|
||||
<ModelPickerSheet
|
||||
favoriteModelKeys={favoriteModelKeys}
|
||||
favoritesEnabled={favoritesReady}
|
||||
groups={providerGroups}
|
||||
onClose={() => setModelPickerVisible(false)}
|
||||
onSelectModel={(option) => props.onUpdateModelSelection(option.selection)}
|
||||
|
||||
@@ -204,7 +204,8 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
|
||||
})();
|
||||
const selectedThreadFeed = props.selectedThreadFeed;
|
||||
const composerChrome = composerExpanded ? COMPOSER_EXPANDED_CHROME : COMPOSER_COLLAPSED_CHROME;
|
||||
const requestChrome = props.activePendingUserInput ? 430 : 270;
|
||||
const requestChrome =
|
||||
(props.activePendingApproval ? 270 : 0) + (props.activePendingUserInput ? 430 : 0);
|
||||
const composerOverlapHeight = activePendingRequest
|
||||
? requestChrome + Math.max(insets.bottom, 12)
|
||||
: composerChrome + composerBottomInset;
|
||||
@@ -404,7 +405,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
|
||||
<View className="w-full self-center" style={{ maxWidth: contentMaxWidth }}>
|
||||
{activePendingRequest ? (
|
||||
<Animated.View
|
||||
className="shrink-0 px-2.5 pt-1.5"
|
||||
className="shrink-0 gap-2 px-2.5 pt-1.5"
|
||||
entering={FadeInDown.duration(220)}
|
||||
exiting={FadeOut.duration(140)}
|
||||
style={{ paddingBottom: Math.max(insets.bottom, 10) }}
|
||||
@@ -416,7 +417,8 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
|
||||
respondingApprovalId={props.respondingApprovalId}
|
||||
onRespond={props.onRespondToApproval}
|
||||
/>
|
||||
) : props.activePendingUserInput ? (
|
||||
) : null}
|
||||
{props.activePendingUserInput ? (
|
||||
<PendingUserInputCard
|
||||
key={props.activePendingUserInput.requestId}
|
||||
pendingUserInput={props.activePendingUserInput}
|
||||
|
||||
@@ -4,15 +4,15 @@ import { useCallback, useMemo } from "react";
|
||||
import { AsyncResult } from "effect/unstable/reactivity";
|
||||
|
||||
import type { ModelOption } from "../../lib/modelOptions";
|
||||
import type { Preferences } from "../../persistence/mobile-preferences";
|
||||
import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
|
||||
|
||||
/** Persists model favorites on this device without inventing a server setting. */
|
||||
export function useModelFavorites(environmentId: EnvironmentId | null) {
|
||||
const preferencesResult = useAtomValue(mobilePreferencesAtom);
|
||||
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
|
||||
const storedKeys = AsyncResult.isSuccess(preferencesResult)
|
||||
? (preferencesResult.value.favoriteModelKeys ?? [])
|
||||
: [];
|
||||
const favoritesReady = AsyncResult.isSuccess(preferencesResult);
|
||||
const storedKeys = favoritesReady ? (preferencesResult.value.favoriteModelKeys ?? []) : [];
|
||||
const environmentPrefix = environmentId === null ? null : `${environmentId}:`;
|
||||
|
||||
const favoriteModelKeys = useMemo(() => {
|
||||
@@ -26,15 +26,19 @@ export function useModelFavorites(environmentId: EnvironmentId | null) {
|
||||
|
||||
const toggleFavorite = useCallback(
|
||||
(option: ModelOption) => {
|
||||
if (environmentPrefix === null) return;
|
||||
if (environmentPrefix === null || !favoritesReady) return;
|
||||
const scopedKey = `${environmentPrefix}${option.key}`;
|
||||
const nextKeys = storedKeys.includes(scopedKey)
|
||||
? storedKeys.filter((key) => key !== scopedKey)
|
||||
: [...storedKeys, scopedKey];
|
||||
savePreferences({ favoriteModelKeys: nextKeys });
|
||||
savePreferences((current: Preferences) => {
|
||||
const currentKeys = current.favoriteModelKeys ?? [];
|
||||
return {
|
||||
favoriteModelKeys: currentKeys.includes(scopedKey)
|
||||
? currentKeys.filter((key) => key !== scopedKey)
|
||||
: [...currentKeys, scopedKey],
|
||||
};
|
||||
});
|
||||
},
|
||||
[environmentPrefix, savePreferences, storedKeys],
|
||||
[environmentPrefix, favoritesReady, savePreferences],
|
||||
);
|
||||
|
||||
return { favoriteModelKeys, toggleFavorite };
|
||||
return { favoriteModelKeys, favoritesReady, toggleFavorite };
|
||||
}
|
||||
@@ -124,6 +124,36 @@ describe("mobile preferences state", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("applies functional preference updates against the latest optimistic value", () =>
|
||||
Effect.gen(function* () {
|
||||
const state = makePreferencesState({
|
||||
load: Effect.succeed({ favoriteModelKeys: ["env:codex:gpt-5"] }),
|
||||
savePatch: (patch) => Effect.succeed(patch),
|
||||
});
|
||||
const registry = AtomRegistry.make();
|
||||
const unmountPreferences = registry.mount(state.preferencesAtom);
|
||||
const unmountUpdate = registry.mount(state.updatePreferencesAtom);
|
||||
|
||||
yield* AtomRegistry.getResult(registry, state.preferencesAtom, {
|
||||
suspendOnWaiting: true,
|
||||
});
|
||||
registry.set(state.updatePreferencesAtom, (current) => ({
|
||||
favoriteModelKeys: [...(current.favoriteModelKeys ?? []), "env:claude:opus"],
|
||||
}));
|
||||
registry.set(state.updatePreferencesAtom, (current) => ({
|
||||
favoriteModelKeys: [...(current.favoriteModelKeys ?? []), "other:codex:gpt-6"],
|
||||
}));
|
||||
|
||||
expect(Option.getOrThrow(AsyncResult.value(registry.get(state.preferencesAtom)))).toEqual({
|
||||
favoriteModelKeys: ["env:codex:gpt-5", "env:claude:opus", "other:codex:gpt-6"],
|
||||
});
|
||||
|
||||
unmountUpdate();
|
||||
unmountPreferences();
|
||||
registry.dispose();
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("falls back to empty preferences when secure storage cannot be read", () =>
|
||||
Effect.gen(function* () {
|
||||
const state = makePreferencesState({
|
||||
|
||||
@@ -15,6 +15,10 @@ interface OptimisticPreferences {
|
||||
readonly versions: Partial<Record<keyof Preferences, number>>;
|
||||
}
|
||||
|
||||
export type PreferencesUpdate =
|
||||
| Partial<Preferences>
|
||||
| ((current: Preferences) => Partial<Preferences>);
|
||||
|
||||
/**
|
||||
* Owns the device preference blob for the lifetime of the app registry.
|
||||
* Optimistic patches are kept separately so writes made while persistence is
|
||||
@@ -57,7 +61,15 @@ export function createMobilePreferencesState(runtime: Atom.AtomRuntime<MobilePre
|
||||
|
||||
const updatePreferencesAtom = runtime
|
||||
.fn(
|
||||
(patch: Partial<Preferences>, get) => {
|
||||
(update: PreferencesUpdate, get) => {
|
||||
const preferences = get(preferencesAtom);
|
||||
let patch: Partial<Preferences>;
|
||||
if (typeof update === "function") {
|
||||
if (!AsyncResult.isSuccess(preferences)) return Effect.void;
|
||||
patch = update(preferences.value);
|
||||
} else {
|
||||
patch = update;
|
||||
}
|
||||
const version = ++nextPatchVersion;
|
||||
const current = get(optimisticPatchAtom);
|
||||
const versions = { ...current.versions };
|
||||
|
||||
Reference in new issue
Block a user