GeezerVison is showing github.com — fix(mobile): removing a thumbnail with the card open no longer strand… · pingdotgg/t3code@9bb5ad2
File treeExpand file treeCollapse file tree Open diff view settings apps/mobile/src/features/threads
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/ThreadComposer.tsx +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -201,8 +201,11 @@ export function useCompactComposerEditor( | 201 | 201 | editorX.set(x); | 202 | 202 | editorWidth.set(width); | 203 | 203 | const compactWidth = Math.max(0, width - 8); | | 204 | + const attachmentCount = state.rowAttachmentCount; | 204 | 205 | setSlot((current) => | 205 | | - current.compactWidth === compactWidth ? current : { ...current, compactWidth }, | | 206 | + current.compactWidth === compactWidth && current.attachmentCount === attachmentCount | | 207 | + ? current | | 208 | + : { ...current, compactWidth, attachmentCount }, | 206 | 209 | ); | 207 | 210 | } | 208 | 211 | }, | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/compactComposerLayout.test.ts +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,13 +23,15 @@ function composer( | 23 | 23 | readonly contentSize?: { readonly width: number; readonly height: number }; | 24 | 24 | readonly compactWidth?: number; | 25 | 25 | readonly attachmentCount?: number; | | 26 | + readonly measuredAttachmentCount?: number; | 26 | 27 | } = {}, | 27 | 28 | ) { | 28 | 29 | const { isExpanded, modelIconOnly } = resolveCompactComposerLayout({ | 29 | 30 | slot: { | 30 | 31 | ...EMPTY_COMPACT_COMPOSER_SLOT, | 31 | 32 | rowWidth: input.rowWidth ?? NARROW, | 32 | 33 | compactWidth: input.compactWidth ?? 200, | | 34 | + attachmentCount: input.measuredAttachmentCount ?? input.attachmentCount ?? 0, | 33 | 35 | }, | 34 | 36 | isFocused: input.isFocused ?? false, | 35 | 37 | isAndroid: input.isAndroid ?? false, | @@ -118,4 +120,16 @@ describe("compact composer layout", () => { | 118 | 120 | slot = compactSlotAfterLabelLayout(slot, { ...label, width: 160 }); | 119 | 121 | expect(composer({ ...line, compactWidth: slot.compactWidth }).isExpanded).toBe(false); | 120 | 122 | }); | | 123 | + | | 124 | + it("re-measures a narrow row's slot when its thumbnail is removed with the card open", () => { | | 125 | + const line = { value: "a short line", contentSize: { width: 150, height: LINE_HEIGHT } }; | | 126 | + const measuredWithThumbnail = { compactWidth: 138, measuredAttachmentCount: 1 }; | | 127 | + expect(composer({ ...line, ...measuredWithThumbnail, attachmentCount: 1 }).isExpanded).toBe( | | 128 | + true, | | 129 | + ); | | 130 | + expect(composer({ ...line, ...measuredWithThumbnail, attachmentCount: 0 }).isExpanded).toBe( | | 131 | + false, | | 132 | + ); | | 133 | + expect(composer({ ...line, compactWidth: 172 }).isExpanded).toBe(false); | | 134 | + }); | 121 | 135 | }); |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/compactComposerLayout.ts +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,12 +8,15 @@ interface CompactComposerSlot { | 8 | 8 | readonly rowWidth: number; | 9 | 9 | /** The editor's collapsed width, or 0 until it is measured again. */ | 10 | 10 | readonly compactWidth: number; | | 11 | + /** Thumbnails in the row when `compactWidth` was measured; it is stale for any other count. */ | | 12 | + readonly attachmentCount: number; | 11 | 13 | readonly label: { readonly width: number; readonly isExpanded: boolean }; | 12 | 14 | } | 13 | 15 |
| 14 | 16 | export const EMPTY_COMPACT_COMPOSER_SLOT: CompactComposerSlot = { | 15 | 17 | rowWidth: 0, | 16 | 18 | compactWidth: 0, | | 19 | + attachmentCount: 0, | 17 | 20 | label: { width: 0, isExpanded: false }, | 18 | 21 | }; | 19 | 22 |
| @@ -64,7 +67,9 @@ export function resolveCompactComposerLayout(input: { | 64 | 67 | readonly modelIconOnly: boolean; | 65 | 68 | readonly labelShownAtRest: boolean; | 66 | 69 | } { | 67 | | - const { rowWidth, compactWidth } = input.slot; | | 70 | + const { rowWidth } = input.slot; | | 71 | + const compactWidth = | | 72 | + input.slot.attachmentCount === input.rowAttachmentCount ? input.slot.compactWidth : 0; | 68 | 73 | const isWide = isWideComposerRow(rowWidth); | 69 | 74 | const opensOnFocus = | 70 | 75 | rowWidth > 0 && | |
|