Browse Source

Fix project card filament badges showing duplicates and raw color codes

Multi-color prints store comma-separated values in filament_color (e.g.,
"#FFFFFF,#43403D") and filament_type (e.g., "PLA, PLA-S"). The project
cards were displaying these raw strings instead of splitting them into
individual badges.

- Split comma-separated colors into individual color swatches
- Split comma-separated materials into individual text badges
- Deduplicate both to avoid showing "PLA" multiple times
maziggy 4 months ago
parent
commit
013f801e6b
3 changed files with 15 additions and 3 deletions
  1. 14 2
      frontend/src/pages/ProjectsPage.tsx
  2. 0 0
      static/assets/index-CCWSzj3L.js
  3. 1 1
      static/index.html

+ 14 - 2
frontend/src/pages/ProjectsPage.tsx

@@ -293,8 +293,20 @@ function ProjectCard({ project, onClick, onEdit, onDelete }: ProjectCardProps) {
               )}
               )}
               {/* Filament materials/colors */}
               {/* Filament materials/colors */}
               {project.archives && project.archives.length > 0 && (() => {
               {project.archives && project.archives.length > 0 && (() => {
-                const materials = [...new Set(project.archives.map(a => a.filament_type).filter(Boolean))];
-                const colors = [...new Set(project.archives.map(a => a.filament_color).filter(Boolean))] as string[];
+                // Flatten comma-separated materials and deduplicate
+                const allMaterials = project.archives
+                  .map(a => a.filament_type)
+                  .filter(Boolean)
+                  .flatMap(m => (m as string).split(',').map(s => s.trim()))
+                  .filter(Boolean);
+                const materials = [...new Set(allMaterials)];
+                // Flatten comma-separated colors and deduplicate
+                const allColors = project.archives
+                  .map(a => a.filament_color)
+                  .filter(Boolean)
+                  .flatMap(c => (c as string).split(',').map(s => s.trim()))
+                  .filter(c => c.startsWith('#') || /^[0-9A-Fa-f]{6}$/.test(c));
+                const colors = [...new Set(allColors)];
                 if (materials.length === 0 && colors.length === 0) return null;
                 if (materials.length === 0 && colors.length === 0) return null;
                 return (
                 return (
                   <div className="flex items-center gap-2 mt-1.5">
                   <div className="flex items-center gap-2 mt-1.5">

File diff suppressed because it is too large
+ 0 - 0
static/assets/index-CCWSzj3L.js


+ 1 - 1
static/index.html

@@ -23,7 +23,7 @@
 
 
     <!-- Splash screens for iOS -->
     <!-- Splash screens for iOS -->
     <link rel="apple-touch-startup-image" href="/img/android-chrome-512x512.png" />
     <link rel="apple-touch-startup-image" href="/img/android-chrome-512x512.png" />
-    <script type="module" crossorigin src="/assets/index-CN6OA8A6.js"></script>
+    <script type="module" crossorigin src="/assets/index-CCWSzj3L.js"></script>
     <link rel="stylesheet" crossorigin href="/assets/index-BEtulymk.css">
     <link rel="stylesheet" crossorigin href="/assets/index-BEtulymk.css">
   </head>
   </head>
   <body>
   <body>

Some files were not shown because too many files changed in this diff