Skip to content

Commit 26609f3

Browse files
committed
Refactor toggle_expanded_text_item to use a parameter object instead of separate arguments
1 parent 843c5e4 commit 26609f3

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

‎packages/ui/src/components/editor/panel/ResponsePreview/ResponsePreview.tsx‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ export const ResponsePreview: FC<Props> = (props) => {
5252
const scroll_top_ref = useRef(0)
5353
const scrollable_ref = useRef<any>(null)
5454

55-
const toggle_expanded_text_item = (
56-
index: number,
55+
const toggle_expanded_text_item = (params: {
56+
index: number
5757
element: HTMLDivElement
58-
) => {
58+
}) => {
5959
const scrollable_instance = scrollable_ref.current
6060
if (scrollable_instance) {
6161
const scroll_container = scrollable_instance.getScrollElement()
6262
if (scroll_container) {
6363
const scroll_container_rect = scroll_container.getBoundingClientRect()
64-
const element_rect = element.getBoundingClientRect()
64+
const element_rect = params.element.getBoundingClientRect()
6565

6666
if (element_rect.top < scroll_container_rect.top) {
6767
// Element's top edge is above the scrollable viewport's top edge.
@@ -78,10 +78,10 @@ export const ResponsePreview: FC<Props> = (props) => {
7878

7979
set_expanded_text_items((prev) => {
8080
const new_set = new Set(prev)
81-
if (new_set.has(index)) {
82-
new_set.delete(index)
81+
if (new_set.has(params.index)) {
82+
new_set.delete(params.index)
8383
} else {
84-
new_set.add(index)
84+
new_set.add(params.index)
8585
}
8686
return new_set
8787
})
@@ -275,14 +275,10 @@ export const ResponsePreview: FC<Props> = (props) => {
275275
</div>
276276
)}
277277

278-
{aggressive_fallback_count > 0 && (
278+
{aggressive_fallback_count > 1 && (
279279
<div
280280
className={cn(styles.info, styles['info--warning'])}
281-
title={`${
282-
files_in_preview.length > 1
283-
? `${aggressive_fallback_count} of ${files_in_preview.length} files`
284-
: 'The file'
285-
} applied with fallback method`}
281+
title={`${aggressive_fallback_count} of ${files_in_preview.length} files applied with fallback method`}
286282
>
287283
<div
288284
className={cn(
@@ -291,9 +287,7 @@ export const ResponsePreview: FC<Props> = (props) => {
291287
)}
292288
>
293289
<span className="codicon codicon-warning" />
294-
{files_in_preview.length > 1
295-
? `${aggressive_fallback_count} of ${files_in_preview.length} edits applied with fallback method`
296-
: 'The edit applied with fallback method'}
290+
{`${aggressive_fallback_count} of ${files_in_preview.length} files applied with fallback method`}
297291
</div>
298292
</div>
299293
)}
@@ -365,7 +359,7 @@ export const ResponsePreview: FC<Props> = (props) => {
365359
language={item.language}
366360
is_expanded={expanded_text_items.has(index)}
367361
on_toggle={(element) =>
368-
toggle_expanded_text_item(index, element)
362+
toggle_expanded_text_item({ index, element })
369363
}
370364
/>
371365
)
@@ -376,7 +370,7 @@ export const ResponsePreview: FC<Props> = (props) => {
376370
content={item.content}
377371
is_expanded={expanded_text_items.has(index)}
378372
on_toggle={(element) =>
379-
toggle_expanded_text_item(index, element)
373+
toggle_expanded_text_item({ index, element })
380374
}
381375
/>
382376
)

0 commit comments

Comments
 (0)