Skip to content

Commit 69ef61e

Browse files
add disabled states for incompatible stack
1 parent 31e5a01 commit 69ef61e

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

apps/web/src/app/(home)/_components/stack-builder.tsx

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,63 @@ const StackBuilder = () => {
12371237
}
12381238
};
12391239

1240+
const isOptionCompatible = (
1241+
currentStack: StackState,
1242+
category: keyof typeof TECH_OPTIONS,
1243+
optionId: string,
1244+
): boolean => {
1245+
const simulatedStack: StackState = JSON.parse(JSON.stringify(currentStack));
1246+
1247+
const updateArrayCategory = (arr: string[], cat: string): string[] => {
1248+
const isAlreadySelected = arr.includes(optionId);
1249+
1250+
if (cat === "webFrontend" || cat === "nativeFrontend") {
1251+
if (isAlreadySelected) {
1252+
return optionId === "none" ? arr : ["none"];
1253+
}
1254+
if (optionId === "none") return ["none"];
1255+
return [optionId];
1256+
}
1257+
1258+
const next: string[] = isAlreadySelected
1259+
? arr.filter((id) => id !== optionId)
1260+
: [...arr.filter((id) => id !== "none"), optionId];
1261+
1262+
if (next.length === 0) return ["none"];
1263+
return [...new Set(next)];
1264+
};
1265+
1266+
if (
1267+
category === "webFrontend" ||
1268+
category === "nativeFrontend" ||
1269+
category === "addons" ||
1270+
category === "examples"
1271+
) {
1272+
const currentArr = Array.isArray(simulatedStack[category])
1273+
? [...(simulatedStack[category] as string[])]
1274+
: [];
1275+
(simulatedStack[category] as string[]) = updateArrayCategory(
1276+
currentArr,
1277+
category,
1278+
);
1279+
} else {
1280+
(simulatedStack[category] as string) = optionId;
1281+
}
1282+
1283+
const { adjustedStack } = analyzeStackCompatibility(simulatedStack);
1284+
const finalStack = adjustedStack ?? simulatedStack;
1285+
1286+
if (
1287+
category === "webFrontend" ||
1288+
category === "nativeFrontend" ||
1289+
category === "addons" ||
1290+
category === "examples"
1291+
) {
1292+
return (finalStack[category] as string[]).includes(optionId);
1293+
}
1294+
return finalStack[category] === optionId;
1295+
};
1296+
12401297
return (
12411298
<TooltipProvider>
12421299
<div
@@ -1493,6 +1550,12 @@ const StackBuilder = () => {
14931550
isSelected = currentValue === tech.id;
14941551
}
14951552

1553+
const isDisabled = !isOptionCompatible(
1554+
stack,
1555+
categoryKey as keyof typeof TECH_OPTIONS,
1556+
tech.id,
1557+
);
1558+
14961559
return (
14971560
<Tooltip key={tech.id} delayDuration={100}>
14981561
<TooltipTrigger asChild>
@@ -1501,7 +1564,9 @@ const StackBuilder = () => {
15011564
"relative cursor-pointer rounded border p-2 transition-all",
15021565
isSelected
15031566
? "border-primary bg-primary/10"
1504-
: "border-border hover:border-muted hover:bg-muted",
1567+
: isDisabled
1568+
? "border-destructive/30 bg-destructive/5 opacity-50 hover:opacity-75"
1569+
: "border-border hover:border-muted hover:bg-muted",
15051570
)}
15061571
whileHover={{ scale: 1.02 }}
15071572
whileTap={{ scale: 0.98 }}

0 commit comments

Comments
 (0)