Skip to content

Commit 437df53

Browse files
committed
make filtering work
1 parent 4ef52fa commit 437df53

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/components/tutorials/TutorialsShowcase.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ export const TutorialsShowcase: React.FC<TutorialsShowcaseProps> = ({
9696
}, [tutorials, services]);
9797

9898
const uniquePlatforms = useMemo(() => {
99-
const allPlatforms = new Set(tutorials.flatMap(tutorial => tutorial.platform));
99+
const allPlatforms = new Set(tutorials.flatMap(tutorial =>
100+
tutorial.platform.map(p => p.toLowerCase()) // Convert to lowercase
101+
));
100102
return Array.from(allPlatforms).sort((a, b) => (platforms[a] || a).localeCompare(platforms[b] || b));
101103
}, [tutorials, platforms]);
102104

@@ -121,7 +123,7 @@ export const TutorialsShowcase: React.FC<TutorialsShowcaseProps> = ({
121123

122124
// Other filters
123125
if (filters.services.length > 0 && !filters.services.some(service => tutorial.services.includes(service))) return false;
124-
if (filters.platforms.length > 0 && !filters.platforms.some(platform => tutorial.platform.includes(platform))) return false;
126+
if (filters.platforms.length > 0 && !filters.platforms.some(platform => tutorial.platform.map(p => p.toLowerCase()).includes(platform))) return false;
125127
if (filters.deployments.length > 0 && !filters.deployments.some(deployment => tutorial.deployment.includes(deployment))) return false;
126128
if (filters.showProOnly && !tutorial.pro) return false;
127129

@@ -510,7 +512,10 @@ export const TutorialsShowcase: React.FC<TutorialsShowcaseProps> = ({
510512

511513
<select
512514
value={filters.services[0] || ''}
513-
onChange={(e) => e.target.value ? toggleFilter('services', e.target.value) : null}
515+
onChange={(e) => setFilters(prev => ({
516+
...prev,
517+
services: e.target.value ? [e.target.value] : []
518+
}))}
514519
className="filter-select"
515520
>
516521
<option value="">Services</option>
@@ -523,7 +528,10 @@ export const TutorialsShowcase: React.FC<TutorialsShowcaseProps> = ({
523528

524529
<select
525530
value={filters.platforms[0] || ''}
526-
onChange={(e) => e.target.value ? toggleFilter('platforms', e.target.value) : null}
531+
onChange={(e) => setFilters(prev => ({
532+
...prev,
533+
platforms: e.target.value ? [e.target.value] : []
534+
}))}
527535
className="filter-select"
528536
>
529537
<option value="">Languages</option>
@@ -536,7 +544,10 @@ export const TutorialsShowcase: React.FC<TutorialsShowcaseProps> = ({
536544

537545
<select
538546
value={filters.deployments[0] || ''}
539-
onChange={(e) => e.target.value ? toggleFilter('deployments', e.target.value) : null}
547+
onChange={(e) => setFilters(prev => ({
548+
...prev,
549+
deployments: e.target.value ? [e.target.value] : []
550+
}))}
540551
className="filter-select"
541552
>
542553
<option value="">Deployment</option>

src/content.config.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
import { defineCollection } from 'astro:content';
1+
import { defineCollection, z } from 'astro:content';
22
import { docsLoader } from '@astrojs/starlight/loaders';
33
import { docsSchema } from '@astrojs/starlight/schema';
44

55
export const collections = {
6-
docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }),
6+
docs: defineCollection({
7+
loader: docsLoader(),
8+
schema: docsSchema({
9+
extend: z.object({
10+
services: z.array(z.string()).optional(),
11+
platform: z.array(z.string()).optional(),
12+
deployment: z.array(z.string()).optional(),
13+
pro: z.boolean().optional(),
14+
leadimage: z.string().optional(),
15+
}),
16+
}),
17+
}),
718
};

0 commit comments

Comments
 (0)