Skip to content

Commit

Permalink
fix: add delete tab
Browse files Browse the repository at this point in the history
  • Loading branch information
mxvsh committed Jan 20, 2025
1 parent c99d893 commit 0d90e45
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const macTitleIconColors = [
];

function Tabs() {
const { tabs, current, addTab, setCurrent } = useStore();
const { tabs, current, addTab, setCurrent, deleteTab } = useStore();

return (
<div className="flex items-center h-full pl-4" data-tauri-drag-region>
Expand Down Expand Up @@ -59,7 +59,16 @@ function Tabs() {
>
{tab.title}
</h1>
<XIcon className="min-w-4 h-4 ml-1 cursor-pointer" />
<XIcon
className={`min-w-4 h-4 ml-1 ${
tab.id === current.id ? 'opacity-0' : 'opacity-40'
}`}
onClick={() => {
if (tab.id === 0) return;

deleteTab(tab.id);
}}
/>
</div>
))}
<button
Expand Down
11 changes: 11 additions & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Actions = {
updateCode: (id: number, code: string) => void;
updateOutput: (id: number, output: string) => void;
setCurrent: (id: number) => void;
deleteTab: (id: number) => void;
};

let initialTab: Tab = {
Expand Down Expand Up @@ -80,6 +81,16 @@ const useStore = create<State & Actions>()(
}
return { current: state.current };
}),

deleteTab: id => {
set(state => {
state.tabs = state.tabs.filter(tab => tab.id !== id);
if (state.current.id === id) {
state.current = state.tabs[0];
}
return { tabs: state.tabs, current: state.current };
});
},
}),
{
name: 'tabs_x',
Expand Down

0 comments on commit 0d90e45

Please sign in to comment.