Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(mobile): preserve independent settings updates
Akshar Patel53544b3651c5
diff --git a/apps/mobile/app/(tabs)/index.tsx b/apps/mobile/app/(tabs)/index.tsxindex 7008395e4..4651a10c7 100644--- a/apps/mobile/app/(tabs)/index.tsx+++ b/apps/mobile/app/(tabs)/index.tsx@@ -593,7 +593,9 @@ export default function CapsScreen() {public: isPublic,});setSettingsCap((current) =>- current?.id === updated.id ? updated : current,+ current?.id === updated.id+ ? { ...current, public: updated.public }+ : current,);await Promise.all([auth.refresh(), load()]);} catch (error) {@@ -640,7 +642,9 @@ export default function CapsScreen() {client: auth.client,onUpdated: async (updated) => {setSettingsCap((current) =>- current?.id === updated.id ? updated : current,+ current?.id === updated.id+ ? { ...current, protected: updated.protected }+ : current,);await Promise.all([auth.refresh(), load()]);},@@ -657,7 +661,9 @@ export default function CapsScreen() {client: auth.client,onUpdated: async (updated) => {setSettingsCap((current) =>- current?.id === updated.id ? updated : current,+ current?.id === updated.id+ ? { ...current, title: updated.title }+ : current,);await Promise.all([auth.refresh(), load()]);},diff --git a/apps/mobile/app/caps/[id].tsx b/apps/mobile/app/caps/[id].tsxindex b5ea9f550..45c5d46ca 100644--- a/apps/mobile/app/caps/[id].tsx+++ b/apps/mobile/app/caps/[id].tsx@@ -654,7 +654,11 @@ export default function CapDetailScreen() {const cap = await auth.client.updateCapSharing(detail.cap.id, {public: isPublic,});- setDetail((current) => (current ? { ...current, cap } : current));+ setDetail((current) =>+ current+ ? { ...current, cap: { ...current.cap, public: cap.public } }+ : current,+ );await auth.refresh();} catch (error) {Alert.alert(@@ -674,7 +678,11 @@ export default function CapDetailScreen() {cap: detail.cap,client: auth.client,onUpdated: async (cap) => {- setDetail((current) => (current ? { ...current, cap } : current));+ setDetail((current) =>+ current+ ? { ...current, cap: { ...current.cap, protected: cap.protected } }+ : current,+ );await auth.refresh();},});@@ -686,7 +694,11 @@ export default function CapDetailScreen() {cap: detail.cap,client: auth.client,onUpdated: async (cap) => {- setDetail((current) => (current ? { ...current, cap } : current));+ setDetail((current) =>+ current+ ? { ...current, cap: { ...current.cap, title: cap.title } }+ : current,+ );await auth.refresh();},});diff --git a/apps/mobile/src/screens/cap-detail.test.tsx b/apps/mobile/src/screens/cap-detail.test.tsxindex 0c7e1b9de..59fcde5b8 100644--- a/apps/mobile/src/screens/cap-detail.test.tsx+++ b/apps/mobile/src/screens/cap-detail.test.tsx@@ -1,5 +1,6 @@import { Comment, User, Video } from "@cap/web-domain";import React, { type ReactElement, type ReactNode } from "react";+import { ActionSheetIOS, Alert } from "react-native";import TestRenderer, {act,type ReactTestRenderer,@@ -32,6 +33,8 @@ type AuthStub = {blockUser: ReturnType<typeof vi.fn>;reportCap: ReturnType<typeof vi.fn>;updateCapSharing: ReturnType<typeof vi.fn>;+ updateCapTitle: ReturnType<typeof vi.fn>;+ updateCapPassword: ReturnType<typeof vi.fn>;};refresh: ReturnType<typeof vi.fn>;};@@ -172,6 +175,8 @@ const createAuth = (): AuthStub => ({blockUser: vi.fn(() => Promise.resolve({ success: true })),reportCap: vi.fn(() => Promise.resolve({ success: true })),updateCapSharing: vi.fn(),+ updateCapTitle: vi.fn(),+ updateCapPassword: vi.fn(),},refresh: vi.fn(() => Promise.resolve()),});@@ -187,6 +192,7 @@ vi.mock("react-native", async () => {ActionSheetIOS: actionSheet,Alert: {alert: vi.fn(),+ prompt: vi.fn(),},ActivityIndicator: createHost("ActivityIndicator"),Linking: {@@ -337,19 +343,11 @@ vi.mock("@/caps/CapSettingsSheet", async () => {};});-vi.mock("@/caps/passwordActions", () => ({- showCapPasswordActions: vi.fn(),-}));-vi.mock("@/caps/saveCapVideo", () => ({PhotosPermissionDeniedError: class PhotosPermissionDeniedError extends Error {},saveCapVideoToPhotos: vi.fn(),}));-vi.mock("@/caps/titleActions", () => ({- showCapTitleActions: vi.fn(),-}));-vi.mock("@/components/ActionButton", async () => {const React = await import("react");return {@@ -1051,3 +1049,136 @@ describe("Cap detail screen", () => {});});});++describe("overlapping Cap settings changes", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });+ it("keeps a removed password after an earlier rename response arrives", async () => {+ const rename = createDeferred<MobileCapDetail["cap"]>();+ const auth = createAuth();+ auth.client.updateCapTitle.mockReturnValueOnce(rename.promise);+ auth.client.updateCapPassword.mockResolvedValueOnce({+ ...detail.cap,+ title: "Roadmap review",+ protected: false,+ });+ authState.value = auth;+ const renderer = await renderComponent(+ React.createElement(CapDetailScreen),+ );+ const sheet = () =>+ renderer.root.findByProps({ testID: "cap-settings-sheet" });++ await act(async () => {+ sheet().props.onRename();+ const buttons = vi.mocked(Alert.prompt).mock.calls.at(-1)?.[2];+ if (!Array.isArray(buttons)) throw new Error("Rename prompt missing");+ expect(vi.mocked(Alert.prompt).mock.calls.at(-1)?.[3]).toBe("plain-text");+ const save = buttons[1]?.onPress as ((value: string) => void) | undefined;+ save?.("Roadmap review");+ });+ expect(auth.client.updateCapTitle).toHaveBeenCalledWith("video_123", {+ title: "Roadmap review",+ });++ await act(async () => {+ sheet().props.onPassword();+ const callback = vi+ .mocked(ActionSheetIOS.showActionSheetWithOptions)+ .mock.calls.at(-1)?.[1];+ if (!callback) throw new Error("Password actions missing");+ callback(1);+ });+ expect(auth.client.updateCapPassword).toHaveBeenCalledWith("video_123", {+ password: null,+ });+ expect(sheet().props.cap.protected).toBe(false);++ await act(async () => {+ rename.resolve({ ...detail.cap, title: "Roadmap review" });+ await rename.promise;+ });+ expect(sheet().props.cap.title).toBe("Roadmap review");+ expect(sheet().props.cap.protected).toBe(false);+ await act(async () => renderer.unmount());+ });++ it("keeps a new title after an earlier password response arrives", async () => {+ const password = createDeferred<MobileCapDetail["cap"]>();+ const auth = createAuth();+ auth.client.updateCapPassword.mockReturnValueOnce(password.promise);+ auth.client.updateCapTitle.mockResolvedValueOnce({+ ...detail.cap,+ title: "Roadmap review",+ protected: false,+ });+ authState.value = auth;+ const renderer = await renderComponent(+ React.createElement(CapDetailScreen),+ );+ const sheet = () =>+ renderer.root.findByProps({ testID: "cap-settings-sheet" });++ await act(async () => {+ sheet().props.onPassword();+ const callback = vi+ .mocked(ActionSheetIOS.showActionSheetWithOptions)+ .mock.calls.at(-1)?.[1];+ if (!callback) throw new Error("Password actions missing");+ callback(1);+ });+ await act(async () => {+ sheet().props.onRename();+ const buttons = vi.mocked(Alert.prompt).mock.calls.at(-1)?.[2];+ if (!Array.isArray(buttons)) throw new Error("Rename prompt missing");+ expect(vi.mocked(Alert.prompt).mock.calls.at(-1)?.[3]).toBe("plain-text");+ const save = buttons[1]?.onPress as ((value: string) => void) | undefined;+ save?.("Roadmap review");+ });+ expect(sheet().props.cap.title).toBe("Roadmap review");++ await act(async () => {+ password.resolve({ ...detail.cap, protected: false });+ await password.promise;+ });+ expect(sheet().props.cap.protected).toBe(false);+ expect(sheet().props.cap.title).toBe("Roadmap review");+ await act(async () => renderer.unmount());+ });++ it("keeps a new title after an earlier sharing response arrives", async () => {+ const sharing = createDeferred<MobileCapDetail["cap"]>();+ const auth = createAuth();+ auth.client.updateCapSharing.mockReturnValueOnce(sharing.promise);+ auth.client.updateCapTitle.mockResolvedValueOnce({+ ...detail.cap,+ title: "Roadmap review",+ public: false,+ });+ authState.value = auth;+ const renderer = await renderComponent(+ React.createElement(CapDetailScreen),+ );+ const sheet = () =>+ renderer.root.findByProps({ testID: "cap-settings-sheet" });++ await act(async () => sheet().props.onVisibilityChange(detail.cap, false));+ await act(async () => {+ sheet().props.onRename();+ const buttons = vi.mocked(Alert.prompt).mock.calls.at(-1)?.[2];+ if (!Array.isArray(buttons)) throw new Error("Rename prompt missing");+ expect(vi.mocked(Alert.prompt).mock.calls.at(-1)?.[3]).toBe("plain-text");+ const save = buttons[1]?.onPress as ((value: string) => void) | undefined;+ save?.("Roadmap review");+ });+ expect(sheet().props.cap.title).toBe("Roadmap review");+ await act(async () => {+ sharing.resolve({ ...detail.cap, public: false });+ await sharing.promise;+ });+ expect(sheet().props.cap.public).toBe(false);+ expect(sheet().props.cap.title).toBe("Roadmap review");+ await act(async () => renderer.unmount());+ });+});diff --git a/apps/mobile/src/screens/dashboard-upload-visibility.test.tsx b/apps/mobile/src/screens/dashboard-upload-visibility.test.tsxindex 483f173b1..ce9017ff6 100644--- a/apps/mobile/src/screens/dashboard-upload-visibility.test.tsx+++ b/apps/mobile/src/screens/dashboard-upload-visibility.test.tsx@@ -1,4 +1,6 @@+import { Video } from "@cap/web-domain";import React, { type ReactElement, type ReactNode } from "react";+import { ActionSheetIOS, Alert } from "react-native";import TestRenderer, {act,type ReactTestRenderer,@@ -6,6 +8,7 @@ import TestRenderer, {} from "react-test-renderer";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import type { MobileCapSummary } from "@/api/mobile";+import { CapSettingsSheet } from "@/caps/CapSettingsSheet";import CapsScreen from "../../app/(tabs)";import UploadScreen from "../../app/(tabs)/upload";@@ -71,6 +74,8 @@ type AuthStub = {rootFolders: unknown[];total?: number;}>;+ updateCapTitle: ReturnType<typeof vi.fn>;+ updateCapPassword: ReturnType<typeof vi.fn>;updateCapSharing: (id: string,input: { public: boolean },@@ -127,6 +132,8 @@ const createAuth = (): AuthStub => ({rootFolders: [],total: 0,}),+ updateCapTitle: vi.fn(),+ updateCapPassword: vi.fn(),updateCapSharing: vi.fn((id: string, input: { public: boolean }) =>Promise.resolve({id,@@ -2934,4 +2941,99 @@ describe("upload and dashboard visibility", () => {await Promise.resolve();});});++ it.each(["title", "password", "public"] as const)(+ "keeps other settings when the earlier %s response arrives in the library sheet",+ async (first) => {+ const cap: MobileCapSummary = {+ id: Video.VideoId.make("video_settings"),+ title: "Launch review",+ shareUrl: "https://cap.so/s/video_settings",+ createdAt: "2026-05-18T10:00:00.000Z",+ updatedAt: "2026-05-18T10:30:00.000Z",+ ownerName: "Richie",+ durationSeconds: 125,+ thumbnailUrl: null,+ folderId: null,+ public: true,+ protected: true,+ viewCount: 7,+ commentCount: 2,+ reactionCount: 3,+ upload: null,+ };+ const auth = createAuth();+ const earlier = createDeferred<MobileCapSummary>();+ let serverCap = cap;+ auth.client.listCaps = vi.fn(async () => ({+ caps: [serverCap],+ folders: [],+ pagination: { hasNextPage: false, page: 1, totalPages: 1 },+ rootFolders: [],+ }));+ auth.client.updateCapTitle = vi.fn(() =>+ first === "title" ? earlier.promise : Promise.resolve(serverCap),+ );+ auth.client.updateCapPassword = vi.fn(() =>+ first === "password" ? earlier.promise : Promise.resolve(serverCap),+ );+ auth.client.updateCapSharing = vi.fn(() => earlier.promise);+ authState.value = auth;+ const renderer = await renderComponent(React.createElement(CapsScreen));+ const card = renderer.root.findAllByProps({ cap })[0];+ if (!card) throw new Error("Cap card missing");+ await act(async () => card.props.onMenuPress(cap));+ const sheet = () => renderer.root.findByType(CapSettingsSheet);+ const rename = () => {+ sheet().props.onRename(sheet().props.cap);+ const buttons = vi.mocked(Alert.prompt).mock.calls.at(-1)?.[2];+ if (!Array.isArray(buttons)) throw new Error("Rename prompt missing");+ expect(vi.mocked(Alert.prompt).mock.calls.at(-1)?.[3]).toBe("plain-text");+ const save = buttons[1]?.onPress as ((value: string) => void) | undefined;+ save?.("Roadmap review");+ };+ const removePassword = () => {+ sheet().props.onPassword(sheet().props.cap);+ const callback = vi+ .mocked(ActionSheetIOS.showActionSheetWithOptions)+ .mock.calls.at(-1)?.[1];+ if (!callback) throw new Error("Password actions missing");+ callback(1);+ };++ await act(async () => {+ if (first === "title") rename();+ if (first === "password") removePassword();+ if (first === "public") sheet().props.onVisibilityChange(cap, false);+ });+ serverCap = {+ ...cap,+ title: "Roadmap review",+ protected: first === "public",+ public: first !== "public",+ };+ await act(async () => {+ if (first === "title") removePassword();+ else rename();+ });+ await act(async () => {+ earlier.resolve(+ first === "title"+ ? { ...cap, title: "Roadmap review" }+ : first === "password"+ ? { ...cap, protected: false }+ : { ...cap, public: false },+ );+ await earlier.promise;+ });++ expect(sheet().props.cap.title).toBe("Roadmap review");+ expect(sheet().props.cap.protected).toBe(first === "public");+ expect(sheet().props.cap.public).toBe(first !== "public");+ expect(getTextNodes(renderer.toJSON())).toContain(+ first === "public" ? "Protected" : "Off",+ );+ await act(async () => renderer.unmount());+ },+ );});