From cd2669596feef5556abe74ae8ce1eeeaa7e8194e Mon Sep 17 00:00:00 2001 From: Rishi Balakrishnan Date: Mon, 21 Sep 2026 09:55:50 -0400 Subject: [PATCH] fix(composer): apply Blacksky Only audience changes immediately (#198) --- package.json | 2 +- .../__tests__/composer-space-target.test.ts | 65 +++++++++++++++++++ src/view/com/composer/state/composer.ts | 6 +- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 086a71f93..4d119ddef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blacksky.community", - "version": "1.130.2", + "version": "1.130.3", "private": true, "packageManager": "pnpm@11.7.0", "engines": { diff --git a/src/view/com/composer/state/__tests__/composer-space-target.test.ts b/src/view/com/composer/state/__tests__/composer-space-target.test.ts index 09aa905fa..ffe7e1ee8 100644 --- a/src/view/com/composer/state/__tests__/composer-space-target.test.ts +++ b/src/view/com/composer/state/__tests__/composer-space-target.test.ts @@ -72,6 +72,71 @@ function stateWithVideo(): ComposerState { } describe('composer target changes', () => { + it.each([false, true])( + 'toggles Blacksky Only from %s and preserves a pending video', + blackskyOnly => { + const state = stateWithVideo() + state.thread.blackskyOnly = blackskyOnly + const media = state.thread.posts[0].embed.media + const next = composerReducer(state, {type: 'toggle_blacksky_only'}) + + expect(next.thread.blackskyOnly).toBe(!blackskyOnly) + expect(next.isDirty).toBe(true) + expect(next.thread.posts).toBe(state.thread.posts) + expect( + media?.type === 'video' && media.video.abortController.signal.aborted, + ).toBe(false) + expect(state.thread.blackskyOnly).toBe(blackskyOnly) + expect(state.isDirty).toBe(false) + }, + ) + + it.each(['public', 'blacksky'] as const)( + 'applies the explicit %s target without a video target transition', + target => { + const state = stateWithVideo() + state.thread.blackskyOnly = target === 'public' + const next = composerReducer(state, {type: 'set_post_target', target}) + + expect(next.thread.blackskyOnly).toBe(target === 'blacksky') + expect(next.isDirty).toBe(true) + expect(next.thread.posts).toBe(state.thread.posts) + }, + ) + + it('updates the selected private feed when both targets are space-backed', () => { + const state = stateWithVideo() + state.thread.communityFeed = privateTarget + state.thread.communityFeedUri = privateTarget.feed + const target = {...privateTarget, feed: `${privateTarget.feed}-other`} + const next = composerReducer(state, {type: 'set_post_target', target}) + + expect(next.thread.communityFeed).toBe(target) + expect(next.thread.communityFeedUri).toBe(target.feed) + expect(next.isDirty).toBe(true) + expect(next.thread.posts).toBe(state.thread.posts) + }) + + it('clears and aborts a pending video when leaving a space-backed feed', () => { + const state = stateWithVideo() + state.thread.communityFeed = privateTarget + state.thread.communityFeedUri = privateTarget.feed + const media = state.thread.posts[0].embed.media + const next = composerReducer(state, { + type: 'set_post_target', + target: 'public', + }) + + expect(next.thread.communityFeed).toBeUndefined() + expect(next.thread.communityFeedUri).toBeUndefined() + expect(next.thread.blackskyOnly).toBe(false) + expect(next.isDirty).toBe(true) + expect(next.thread.posts[0].embed.media).toBeUndefined() + expect( + media?.type === 'video' && media.video.abortController.signal.aborted, + ).toBe(true) + }) + it('clears and aborts a pending video when entering a space-backed feed', () => { const state = stateWithVideo() const next = composerReducer(state, { diff --git a/src/view/com/composer/state/composer.ts b/src/view/com/composer/state/composer.ts index 6378b84b6..eca87d6de 100644 --- a/src/view/com/composer/state/composer.ts +++ b/src/view/com/composer/state/composer.ts @@ -190,7 +190,11 @@ function clearVideosOnTargetChange( nextThread: ThreadDraft, ): ComposerState { if (hasSpaceVideoTarget(state.thread) === hasSpaceVideoTarget(nextThread)) { - return state + return { + ...state, + isDirty: true, + thread: nextThread, + } } const posts = state.thread.posts.map(post => -- knotmirror 0.0.1