Tabs switching logic fixed

This commit is contained in:
Lucas Oliveira 2023-02-22 23:40:16 -03:00
commit f49fa04d67
3 changed files with 16 additions and 16 deletions

View file

@ -30,17 +30,17 @@ export function TabsProvider({children}){
function removeFlow(id:string){
setFlows(prevState=>{
const newFlows = [...prevState];
const index = newFlows.findIndex(flow=>flow.id===id)
if(index!==-1){
newFlows.splice(index,1)
}
if(index===tabIndex){
if(tabIndex===0){
//
}
else{
setTabIndex(tabIndex-1)
const index = newFlows.findIndex(flow=>flow.id===id);
if(index >= 0){
if(index===tabIndex){
setTabIndex(flows.length-2);
newFlows.splice(index,1);
} else {
let flowId = flows[tabIndex].id;
newFlows.splice(index,1);
setTabIndex(newFlows.findIndex(flow=>flow.id === flowId));
}
}
window.sessionStorage.setItem('tabs', JSON.stringify(newFlows));
return newFlows;
@ -48,10 +48,11 @@ export function TabsProvider({children}){
}
function addFlow(newFlow: flow) {
setFlows(prevState => {
const newFlows = [...prevState, newFlow];
window.sessionStorage.setItem('tabs', JSON.stringify(newFlows));
return newFlows;
const newFlows = [...prevState, newFlow];
window.sessionStorage.setItem('tabs', JSON.stringify(newFlows));
return newFlows;
});
setTabIndex(flows.length);
}
function updateFlow(newFlow:flow){
setFlows(prevState=>{

View file

@ -20,7 +20,6 @@ export function TabsManager() {
<div className="h-full w-full flex flex-col">
<div className="w-full flex pr-2 flex-row text-center items-center bg-gray-100">
{flows.map((flow, index) => {
console.log(tabIndex);
return (
<TabComponent
onClick={() => setTabIndex(index)}

View file

@ -13,7 +13,7 @@ export default function TabComponent({ selected, flow, onClick }) {
{flow ? (
!selected ? (
<div
className="flex justify-between select-none truncate w-44 items-center px-4 my-2 mt-3 border-x border-gray-300 -ml-px"
className="flex justify-between select-none truncate w-44 items-center px-4 my-2 mt-3 border-x border-t border-t-transparent border-gray-300 -ml-px"
onClick={onClick}
>
{flow.name}
@ -68,7 +68,7 @@ export default function TabComponent({ selected, flow, onClick }) {
) : (
<div className="h-full py-2 pt-3 flex justify-center items-center">
<button
className="px-3 h-full border-gray-300 -ml-px"
className="px-3 flex items-center h-full mb-1 border-gray-300 -ml-px border-t border-t-transparent"
onClick={onClick}
>
<PlusIcon className="h-5" />