1
- " use client"
2
- import Programs from " @/comps/Programs" ;
1
+ ' use client' ;
2
+ import Programs from ' @/comps/Programs' ;
3
3
import {
4
- Dialog ,
5
- DialogContent ,
6
- DialogDescription ,
7
- DialogHeader ,
8
- DialogTitle ,
9
- DialogTrigger ,
10
- DialogFooter ,
11
- DialogClose
12
- } from "@/components/ui/dialog"
13
- import { Button } from "@/components/ui/button" ;
14
- import { Label } from "@/components/ui/label"
15
- import { Input } from "@/components/ui/input"
16
- import { CopyIcon } from "@radix-ui/react-icons"
17
- import { useEffect , useState } from "react" ;
18
-
4
+ Dialog ,
5
+ DialogContent ,
6
+ DialogDescription ,
7
+ DialogHeader ,
8
+ DialogTitle ,
9
+ DialogTrigger ,
10
+ DialogFooter ,
11
+ DialogClose ,
12
+ } from '@/components/ui/dialog' ;
13
+ import { Button } from '@/components/ui/button' ;
14
+ import { Label } from '@/components/ui/label' ;
15
+ import { Input } from '@/components/ui/input' ;
16
+ import { CopyIcon } from '@radix-ui/react-icons' ;
17
+ import { useEffect , useState } from 'react' ;
19
18
20
19
21
20
21
+ export default function program ( ) {
22
+ const [ filterOption , setFilterOption ] = useState < "" | "Yes" | "No" > ( "" ) ; // Explicitly define the type
22
23
23
- export default function programs ( ) {
24
- const [ filterOption , setFilterOption ] = useState ( "" ) ;
25
-
26
- const handleFilterChange = ( newOption ) => {
27
- setFilterOption ( newOption ) ;
28
- } ;
29
-
30
- return (
24
+ const handleFilterChange = ( newOption : "" | "Yes" | "No" ) => {
25
+ // Only set the filter option if it's one of the allowed values
26
+ if ( newOption === "" || newOption === "Yes" || newOption === "No" ) {
27
+ setFilterOption ( newOption ) ;
28
+ }
29
+ } ;
30
+
31
+ return (
31
32
< div >
32
- < section className = "mx-4 " >
33
- < div className = "container flex flex-col items-center gap-4 text-center" >
34
- < h1 className = "tracking-tight font-semibold text-2xl sm:text-5xl md:text-6xl lg:text-5xl mb-4 dark:text-white" >
35
- Opensource Programs List
36
- </ h1 >
37
- < p className = "max-w-[42rem] leading-normal dark:text-white text-muted-foreground sm:text-xl sm:leading-8" >
38
- Discover a curated collection of diverse open source programs. Filter based on stipend availability and find opportunities that match your interests and skills.
39
-
40
- </ p >
41
- </ div >
42
- < Filter onFilterChange = { handleFilterChange } />
43
- </ section >
44
- < Programs filter_option = { filterOption } />
33
+ < section className = "mx-4 " >
34
+ < div className = "container flex flex-col items-center gap-4 text-center" >
35
+ < h1 className = "tracking-tight font-semibold text-2xl sm:text-5xl md:text-6xl lg:text-5xl mb-4 dark:text-white" >
36
+ Opensource Programs List
37
+ </ h1 >
38
+ < p className = "max-w-[42rem] leading-normal dark:text-white text-muted-foreground sm:text-xl sm:leading-8" >
39
+ Discover a curated collection of diverse open source programs. Filter based on stipend availability and find opportunities that match your interests and skills.
40
+ </ p >
41
+ </ div >
42
+ < Filter onFilterChange = { handleFilterChange } />
43
+ </ section >
44
+ < Programs filter_option = { filterOption } />
45
45
</ div >
46
- ) ;
47
- }
48
-
49
- function Filter ( { onFilterChange } ) {
50
- const [ opt , setOpt ] = useState ( "" ) ;
51
-
52
- useEffect ( ( ) => {
46
+ ) ;
47
+ }
48
+
49
+ function Filter ( { onFilterChange } : { onFilterChange : ( newOption : "" | "Yes" | "No" ) => void } ) {
50
+ const [ opt , setOpt ] = useState < "" | "Yes" | "No" > ( "" ) ; // Explicitly define the type
51
+
52
+ useEffect ( ( ) => {
53
53
// Call the callback function whenever opt changes
54
54
onFilterChange ( opt ) ;
55
- } , [ opt , onFilterChange ] ) ;
56
-
57
- return (
58
- < div className = "dark:text-white dark:bg-[#09090B]" >
59
- < Dialog >
60
- < DialogTrigger asChild >
61
- < Button variant = "outline" > Filters</ Button >
62
- </ DialogTrigger >
63
- < DialogContent className = "sm:max-w-md" >
64
- < DialogHeader className = "dark:text-white " >
65
- < DialogTitle className = "dark:text-white " > Filters</ DialogTitle >
66
- </ DialogHeader >
67
- < div className = "flex items-center space-x-2" >
68
- < DialogClose asChild >
69
- < Button size = "sm" className = "px-3" onClick = { ( ) => setOpt ( "Yes" ) } >
70
- < span className = "sr-only" > Copy</ span >
71
- With stipend
72
- </ Button >
73
- </ DialogClose >
74
-
75
-
76
-
77
- < DialogClose asChild >
55
+ } , [ opt , onFilterChange ] ) ;
78
56
79
- < Button onClick = { ( ) => setOpt ( "No" ) } size = "sm" className = "px-3" >
80
- < span className = "sr-only" > Copy</ span >
81
- No stipend
82
- </ Button >
83
- </ DialogClose >
57
+ return (
58
+ < div className = "dark:text-white dark:bg-[#09090B]" >
59
+ < Dialog >
60
+ < DialogTrigger asChild >
61
+ < Button variant = "outline" > Filters</ Button >
62
+ </ DialogTrigger >
63
+ < DialogContent className = "sm:max-w-md" >
64
+ < DialogHeader className = "dark:text-white" >
65
+ < DialogTitle className = "dark:text-white" > Filters</ DialogTitle >
66
+ </ DialogHeader >
67
+ < div className = "flex items-center space-x-2" >
68
+ < DialogClose asChild >
69
+ < Button size = "sm" className = "px-3" onClick = { ( ) => setOpt ( "Yes" ) } >
70
+ < span className = "sr-only" > Copy</ span >
71
+ With stipend
72
+ </ Button >
73
+ </ DialogClose >
84
74
85
- < DialogClose asChild >
86
- < Button size = "sm" className = "px-3" onClick = { ( ) => setOpt ( "" ) } >
87
- < span className = "sr-only" > Copy</ span >
88
- Default
89
- </ Button >
90
- </ DialogClose >
75
+ < DialogClose asChild >
76
+ < Button onClick = { ( ) => setOpt ( "No " ) } size = "sm" className = "px-3" >
77
+ < span className = "sr-only" > Copy</ span >
78
+ No stipend
79
+ </ Button >
80
+ </ DialogClose >
91
81
92
- </ div >
93
- </ DialogContent >
94
- </ Dialog >
82
+ < DialogClose asChild >
83
+ < Button size = "sm" className = "px-3" onClick = { ( ) => setOpt ( "" ) } >
84
+ < span className = "sr-only" > Copy</ span >
85
+ Default
86
+ </ Button >
87
+ </ DialogClose >
88
+ </ div >
89
+ </ DialogContent >
90
+ </ Dialog >
95
91
</ div >
96
- ) ;
97
- }
98
-
92
+ ) ;
93
+ }
0 commit comments