Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 53 additions & 27 deletions src/renderer/screens/DatabaseScreen/MainView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,53 +37,79 @@ export default function MainView() {
}
};

const onTabClosed = useCallback(
(closedTab: WindowTabItem) => {
// Close current tab will select other available tab
if (closedTab.key === selectedTab) {
const closedTabIndex = tabs.findIndex(
(tab) => closedTab.key === tab.key
);

const nextTabKey =
closedTabIndex + 1 >= tabs.length
? tabs[closedTabIndex - 1].key
: tabs[closedTabIndex + 1].key;

setSelectedTab(nextTabKey);
}

setTabs((prev) => prev.filter((tab) => tab.key !== closedTab.key));
},
[setSelectedTab, setTabs, selectedTab, tabs]
);

const { handleContextMenu } = useContextMenu(
(additionalData?: WindowTabItem) => {
console.log('additional data', additionalData);

return [
{
text: 'Close',
Comment thread
invisal marked this conversation as resolved.
disabled: tabs.length === 1,
onClick: () => {
// not be implemented
if (additionalData) {
onTabClosed(additionalData);
}
},
},
{
text: 'Close Others',
disabled: tabs.length === 1,
onClick: () => {
// not be implemented
if (additionalData) {
setTabs(tabs.filter((tab) => tab.key === additionalData.key));
setSelectedTab(additionalData.key);
}
},
},
{
text: 'Close to the Right',
Comment thread
invisal marked this conversation as resolved.
disabled:
tabs.findIndex((tab) => tab.key === additionalData?.key) >=
tabs.length - 1,
onClick: () => {
// not be implemented
},
},
];
},
[]
);
if (additionalData) {
const index = tabs.findIndex(
(tab) => tab.key === additionalData.key
);

const onTabClosed = useCallback(
(closedTab: WindowTabItem) => {
// Close current tab will select other available tab
if (closedTab.key === selectedTab) {
const closedTabIndex = tabs.findIndex(
(tab) => closedTab.key === tab.key
);
const selectedIndex = tabs.findIndex(
(tab) => tab.key === selectedTab
);

const nextTabKey =
closedTabIndex + 1 >= tabs.length
? tabs[closedTabIndex - 1].key
: tabs[closedTabIndex + 1].key;

setSelectedTab(nextTabKey);
}
if (selectedIndex > index) {
setSelectedTab(additionalData.key);
}

setTabs((prev) => prev.filter((tab) => tab.key !== closedTab.key));
// if tab is found
if (index !== -1) {
const newTabs = tabs.slice(0, index + 1);
setTabs(newTabs);
}
}
},
},
];
},
[setSelectedTab, setTabs, selectedTab, tabs]
[tabs, onTabClosed, setTabs, setSelectedTab, selectedTab]
);

return (
Expand Down