mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-20 11:48:03 +02:00
feat(#111): Use existing last actions for auto open tabs
This commit is contained in:
parent
51cb930b6a
commit
8a19189dcd
@ -17,15 +17,15 @@ import {
|
|||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import { openCollectionEvent, collectionAddEnvFileEvent } from 'providers/ReduxStore/slices/collections/actions';
|
import { openCollectionEvent, collectionAddEnvFileEvent } from 'providers/ReduxStore/slices/collections/actions';
|
||||||
import { isElectron } from 'utils/common/platform';
|
import { isElectron } from 'utils/common/platform';
|
||||||
import { updateNewRequest } from 'providers/ReduxStore/slices/collections/index';
|
|
||||||
import { addTab } from 'providers/ReduxStore/slices/tabs';
|
import { addTab } from 'providers/ReduxStore/slices/tabs';
|
||||||
import { getDefaultRequestPaneTab } from 'utils/collections/index';
|
import { findCollectionByUid, getDefaultRequestPaneTab } from 'utils/collections/index';
|
||||||
import { hideHomePage } from 'providers/ReduxStore/slices/app';
|
import { hideHomePage } from 'providers/ReduxStore/slices/app';
|
||||||
|
import { updateLastAction } from 'providers/ReduxStore/slices/collections/index';
|
||||||
|
|
||||||
const useCollectionTreeSync = () => {
|
const useCollectionTreeSync = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const tabs = useSelector((state) => state.tabs.tabs);
|
const tabs = useSelector((state) => state.tabs.tabs);
|
||||||
const newRequestName = useSelector((state) => state.collections.newRequestName);
|
const collections = useSelector((state) => state.collections.collections);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isElectron()) {
|
if (!isElectron()) {
|
||||||
@ -57,22 +57,25 @@ const useCollectionTreeSync = () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// Remove the newRequestName so no random stuff happens
|
const collectionUid = val.meta.collectionUid;
|
||||||
dispatch(
|
const lastAction = findCollectionByUid(collections, collectionUid)?.lastAction;
|
||||||
updateNewRequest({ newRequestName: null })
|
|
||||||
);
|
|
||||||
// When the request was just created open it in a new tab
|
// When the request was just created open it in a new tab
|
||||||
if (newRequestName === val.data.name) {
|
if (lastAction && lastAction.type === 'ADD_REQUEST') {
|
||||||
|
dispatch(updateLastAction({ lastAction: null, collectionUid }));
|
||||||
|
|
||||||
|
if (lastAction.payload === val.data.name) {
|
||||||
dispatch(
|
dispatch(
|
||||||
addTab({
|
addTab({
|
||||||
uid: val.data.uid,
|
uid: val.data.uid,
|
||||||
collectionUid: val.meta.collectionUid,
|
collectionUid: collectionUid,
|
||||||
requestPaneTab: getDefaultRequestPaneTab(val.data)
|
requestPaneTab: getDefaultRequestPaneTab(val.data)
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
dispatch(hideHomePage());
|
dispatch(hideHomePage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (type === 'change') {
|
if (type === 'change') {
|
||||||
dispatch(
|
dispatch(
|
||||||
collectionChangeFileEvent({
|
collectionChangeFileEvent({
|
||||||
@ -164,7 +167,7 @@ const useCollectionTreeSync = () => {
|
|||||||
removeListener10();
|
removeListener10();
|
||||||
removeListener11();
|
removeListener11();
|
||||||
};
|
};
|
||||||
}, [isElectron, tabs, newRequestName]);
|
}, [isElectron, tabs, collections]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isElectron()) {
|
if (!isElectron()) {
|
||||||
|
@ -597,7 +597,7 @@ export const newHttpRequest = (params) => (dispatch, getState) => {
|
|||||||
|
|
||||||
ipcRenderer.invoke('renderer:new-request', fullName, item).then(resolve).catch(reject);
|
ipcRenderer.invoke('renderer:new-request', fullName, item).then(resolve).catch(reject);
|
||||||
// Add the new request name here so it can be opened in a new tab in useCollectionTreeSync.js
|
// Add the new request name here so it can be opened in a new tab in useCollectionTreeSync.js
|
||||||
dispatch(updateNewRequest({ newRequestName: item.name }))
|
dispatch(updateLastAction({ lastAction: { type: 'ADD_REQUEST', payload: item.name }, collectionUid }));
|
||||||
} else {
|
} else {
|
||||||
return reject(new Error('Duplicate request names are not allowed under the same folder'));
|
return reject(new Error('Duplicate request names are not allowed under the same folder'));
|
||||||
}
|
}
|
||||||
@ -616,7 +616,7 @@ export const newHttpRequest = (params) => (dispatch, getState) => {
|
|||||||
|
|
||||||
ipcRenderer.invoke('renderer:new-request', fullName, item).then(resolve).catch(reject);
|
ipcRenderer.invoke('renderer:new-request', fullName, item).then(resolve).catch(reject);
|
||||||
// Add the new request name here so it can be opened in a new tab in useCollectionTreeSync.js
|
// Add the new request name here so it can be opened in a new tab in useCollectionTreeSync.js
|
||||||
dispatch(updateNewRequest({ newRequestName: item.name }))
|
dispatch(updateLastAction({ lastAction: { type: 'ADD_REQUEST', payload: item.name }, collectionUid }));
|
||||||
} else {
|
} else {
|
||||||
return reject(new Error('Duplicate request names are not allowed under the same folder'));
|
return reject(new Error('Duplicate request names are not allowed under the same folder'));
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,7 @@ const PATH_SEPARATOR = path.sep;
|
|||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
collections: [],
|
collections: [],
|
||||||
collectionSortOrder: 'default',
|
collectionSortOrder: 'default'
|
||||||
newRequestName: null
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const collectionsSlice = createSlice({
|
export const collectionsSlice = createSlice({
|
||||||
@ -130,10 +129,6 @@ export const collectionsSlice = createSlice({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateNewRequest: (state, action) => {
|
|
||||||
const { newRequestName } = action.payload;
|
|
||||||
state.newRequestName = newRequestName;
|
|
||||||
},
|
|
||||||
newItem: (state, action) => {
|
newItem: (state, action) => {
|
||||||
const collection = findCollectionByUid(state.collections, action.payload.collectionUid);
|
const collection = findCollectionByUid(state.collections, action.payload.collectionUid);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user