Skip to content

Commit 55b1302

Browse files
committed
fix: move confirm
1 parent 9e073d8 commit 55b1302

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/store/reducers/executeQuery.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {api} from './api';
2121
const MAXIMUM_QUERIES_IN_HISTORY = 20;
2222

2323
const CHANGE_USER_INPUT = 'query/CHANGE_USER_INPUT';
24+
const REPLACE_USER_INPUT = 'query/REPLACE_USER_INPUT';
2425
const SET_QUERY_RESULT = 'query/SET_QUERY_RESULT';
2526
const SET_QUERY_TRACE_READY = 'query/SET_QUERY_TRACE_READY';
2627
const SAVE_QUERY_TO_HISTORY = 'query/SAVE_QUERY_TO_HISTORY';
@@ -57,6 +58,21 @@ const executeQuery: Reducer<ExecuteQueryState, ExecuteQueryAction> = (
5758
action,
5859
) => {
5960
switch (action.type) {
61+
case REPLACE_USER_INPUT: {
62+
if (action.data.input === state.input) {
63+
return state;
64+
}
65+
66+
if (window.confirm('Are you sure you want to replace the input?')) {
67+
return {
68+
...state,
69+
input: action.data.input,
70+
};
71+
}
72+
73+
return state;
74+
}
75+
6076
case CHANGE_USER_INPUT: {
6177
return {
6278
...state,
@@ -355,8 +371,8 @@ export const changeUserInput = ({input}: {input: string}) => {
355371

356372
export const replaceUserInput = ({input}: {input: string}) => {
357373
return {
358-
type: CHANGE_USER_INPUT,
359-
data: window.confirm('Input value will be lost. Continue?') ? {input} : undefined,
374+
type: REPLACE_USER_INPUT,
375+
data: {input},
360376
} as const;
361377
};
362378

src/types/store/executeQuery.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
changeUserInput,
33
goToNextQuery,
44
goToPreviousQuery,
5+
replaceUserInput,
56
saveQueryToHistory,
67
setQueryHistoryFilter,
78
setQueryResult,
@@ -62,6 +63,7 @@ export type ExecuteQueryAction =
6263
| ReturnType<typeof goToNextQuery>
6364
| ReturnType<typeof goToPreviousQuery>
6465
| ReturnType<typeof changeUserInput>
66+
| ReturnType<typeof replaceUserInput>
6567
| ReturnType<typeof setQueryResult>
6668
| ReturnType<typeof saveQueryToHistory>
6769
| ReturnType<typeof updateQueryInHistory>

0 commit comments

Comments
 (0)