Skip to content

Commit c90e556

Browse files
committed
Implement tracking of previous prompt types to allow navigating back from the find-relevant-files modal
- the modal: [Fragment] should not have 'close' button/background action, but 'Go back'. When clicked should change prompt type to the previously chosen one.
1 parent 104e64a commit c90e556

1 file changed

Lines changed: 33 additions & 17 deletions

File tree

  • apps/editor/src/views/panel/frontend

apps/editor/src/views/panel/frontend/Panel.tsx

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect, useRef } from 'react'
1+
import { useState, useEffect } from 'react'
22
import { Main } from './Main'
33
import { Button as UiButton } from '@ui/components/editor/common/Button'
44
import { Page as UiPage } from '@ui/components/editor/panel/Page'
@@ -32,6 +32,7 @@ import { use_response_history } from './hooks/panel/use-response-history'
3232
import { use_preview_manager } from './hooks/panel/use-preview-manager'
3333
import { use_editor_sync } from './hooks/panel/use-editor-sync'
3434
import { use_web_configuration_editing } from './hooks/panel/use-web-configuration-editing'
35+
import { ApiPromptType, WebPromptType } from '@shared/types/prompt-types'
3536

3637
const vscode = acquireVsCodeApi()
3738

@@ -113,11 +114,7 @@ export const Panel = () => {
113114
handle_remove_response_history_item
114115
} = use_response_history(vscode)
115116

116-
const {
117-
tasks,
118-
handle_tasks_change,
119-
handle_task_delete,
120-
} = use_tasks(vscode)
117+
const { tasks, handle_tasks_change, handle_task_delete } = use_tasks(vscode)
121118

122119
const {
123120
updating_web_configuration,
@@ -149,14 +146,24 @@ export const Panel = () => {
149146
const { viewing_donations, set_viewing_donations, ...donations_state } =
150147
use_latest_donations()
151148

152-
const active_prompt_type = mode == MODE.WEB ? web_prompt_type : api_prompt_type
153-
const [is_find_files_modal_dismissed, set_is_find_files_modal_dismissed] = useState(false)
149+
const active_prompt_type =
150+
mode == MODE.WEB ? web_prompt_type : api_prompt_type
151+
const [previous_web_prompt_type, set_previous_web_prompt_type] =
152+
useState<WebPromptType>('edit-context')
153+
const [previous_api_prompt_type, set_previous_api_prompt_type] =
154+
useState<ApiPromptType>('edit-context')
155+
156+
useEffect(() => {
157+
if (web_prompt_type && web_prompt_type !== 'find-relevant-files') {
158+
set_previous_web_prompt_type(web_prompt_type)
159+
}
160+
}, [web_prompt_type])
154161

155162
useEffect(() => {
156-
if (active_prompt_type !== 'find-relevant-files' || token_count > 0) {
157-
set_is_find_files_modal_dismissed(false)
163+
if (api_prompt_type && api_prompt_type !== 'find-relevant-files') {
164+
set_previous_api_prompt_type(api_prompt_type)
158165
}
159-
}, [active_prompt_type, token_count])
166+
}, [api_prompt_type])
160167

161168
if (
162169
ask_about_context_instructions === undefined ||
@@ -384,7 +391,9 @@ export const Panel = () => {
384391
context_file_paths={context_file_paths}
385392
web_configurations_collapsed={web_configurations_collapsed}
386393
send_with_shift_enter={send_with_shift_enter}
387-
on_web_configurations_collapsed_change={handle_web_configurations_collapsed_change}
394+
on_web_configurations_collapsed_change={
395+
handle_web_configurations_collapsed_change
396+
}
388397
api_configurations_collapsed={api_configurations_collapsed}
389398
on_api_configurations_collapsed_change={
390399
handle_api_configurations_collapsed_change
@@ -504,7 +513,9 @@ export const Panel = () => {
504513
<UiPage
505514
on_back_click={edit_web_configuration_back_click_handler}
506515
footer_slot={
507-
<EditWebConfigurationFormFooter on_save={edit_web_configuration_save_handler} />
516+
<EditWebConfigurationFormFooter
517+
on_save={edit_web_configuration_save_handler}
518+
/>
508519
}
509520
title="Edit Web Configuration"
510521
header_slot={
@@ -802,18 +813,23 @@ export const Panel = () => {
802813
</div>
803814
)}
804815

805-
{active_prompt_type == 'find-relevant-files' && token_count == 0 && !is_find_files_modal_dismissed && (
816+
{active_prompt_type == 'find-relevant-files' && token_count == 0 && (
806817
<div className={styles.slot}>
807818
<UiModal
808819
title="Make rough context selection"
809820
icon="info"
810-
on_background_click={() => set_is_find_files_modal_dismissed(true)}
811821
footer_slot={
812822
<UiButton
813823
is_secondary
814-
on_click={() => set_is_find_files_modal_dismissed(true)}
824+
on_click={() => {
825+
if (mode == MODE.WEB) {
826+
handle_web_prompt_type_change(previous_web_prompt_type)
827+
} else {
828+
handle_api_prompt_type_change(previous_api_prompt_type)
829+
}
830+
}}
815831
>
816-
Close
832+
Go back
817833
</UiButton>
818834
}
819835
/>

0 commit comments

Comments
 (0)