fixed tab order logic when tabs are added or removed

This commit is contained in:
Carter 2025-04-02 11:08:01 -06:00
parent 2c4aceb13c
commit 6056e117f8
4 changed files with 50 additions and 59 deletions

View file

@ -235,11 +235,13 @@ export default function BinYard(props: Props) {
newBinYard.name = addYardName;
newBinYard.description = addYardDescription;
newBinYard.owner = user.id();
newBinYard.userSort[user.id()] = binYards.length + 1;
binYardAPI
.addBinYard(newBinYard)
.then(_resp => {
loadYards();
// loadYards();
let newYards = [...binYards]
newYards.push(newBinYard)
setBinYards(newYards)
setShowAddYard(false);
openSnackbar("success", "Bin Yard created :)");
})
@ -357,50 +359,6 @@ export default function BinYard(props: Props) {
});
};
const moveLeft = (index: number) => {
let key = as ? as : user.id();
if (binYards[index - 1]) {
let left = binYards[index - 1].userSort[key] ?? index - 1;
let right = binYards[index].userSort[key] ?? index;
let binLeft = binYards[index - 1];
let binRight = binYards[index];
binLeft.userSort[key] = right;
binRight.userSort[key] = left;
if (binRight.userSort[key] >= binLeft.userSort[key]) {
binLeft.userSort[key] = binRight.userSort[key] + 1;
}
let leftPromise = binYardAPI.updateBinYard(binLeft.key, binLeft, true);
let rightPromise = binYardAPI.updateBinYard(binRight.key, binRight, true);
Promise.all([leftPromise, rightPromise]).then((/*[leftResp, rightResp]*/) => {
loadYards();
if (index === tab - 1) setTab(tab - 1);
if (index === tab) setTab(tab + 1);
});
}
};
const moveRight = (index: number) => {
let key = as ? as : user.id();
if (binYards[index + 1]) {
let left = binYards[index].userSort[key] ?? index;
let right = binYards[index + 1].userSort[key] ?? index + 1;
let binLeft = binYards[index];
let binRight = binYards[index + 1];
binLeft.userSort[key] = right;
binRight.userSort[key] = left;
if (binRight.userSort[key] <= binLeft.userSort[key]) {
binRight.userSort[key] = binLeft.userSort[key] - 1;
}
let leftPromise = binYardAPI.updateBinYard(binLeft.key, binLeft, true);
let rightPromise = binYardAPI.updateBinYard(binRight.key, binRight, true);
Promise.all([leftPromise, rightPromise]).then((/*[leftResp, rightResp]*/) => {
loadYards();
if (index === tab - 1) setTab(tab + 1);
if (index === tab - 2) setTab(tab - 1);
});
}
};
const openShareDialog = () => {
setShareDialog(true);
};
@ -764,7 +722,8 @@ export default function BinYard(props: Props) {
n.name
)
}
key={index}>
key={n.name}
>
<Tab
classes={{ root: classes.tab, selected: classes.selectedTab }}
key={index}