@@ -4,16 +4,43 @@ import OptionsController from './sidebar/OptionsController'
4
4
import SelectedOptionController from './sidebar/SelectedOptionController'
5
5
import CoursesController from './sidebar/CoursesController'
6
6
import MultipleOptionsContext from '../../contexts/MultipleOptionsContext'
7
+ import { useSidebarContext } from '../layout/SidebarPosition'
8
+ import { ArrowsRightLeftIcon , TrashIcon } from '@heroicons/react/24/outline'
9
+ import { Button } from '../ui/button'
7
10
8
11
/**
9
12
* Sidebar with all the main schedule interactions
10
13
*/
11
14
const Sidebar = ( ) => {
12
- const { multipleOptions, selectedOption } = useContext ( MultipleOptionsContext ) ;
15
+ const { multipleOptions, selectedOption, setMultipleOptions } = useContext ( MultipleOptionsContext ) ;
16
+ const { toggleSidebarPosition } = useSidebarContext ( ) ;
17
+
18
+ const noClassesPicked = ! multipleOptions [ selectedOption ] ?. course_options . some (
19
+ ( option ) => option . picked_class_id !== null
20
+ ) ;
21
+
22
+ const eraseClasses = ( ) => {
23
+ const currentOption = multipleOptions [ selectedOption ] ;
24
+
25
+ const updatedCourseOptions = currentOption . course_options . map ( courseOption => ( {
26
+ ...courseOption ,
27
+ picked_class_id : null ,
28
+ locked : false ,
29
+ } ) ) ;
30
+
31
+ const updatedMultipleOptions = [ ...multipleOptions ] ;
32
+ updatedMultipleOptions [ selectedOption ] = {
33
+ ...currentOption ,
34
+ course_options : updatedCourseOptions ,
35
+ } ;
36
+
37
+ setMultipleOptions ( updatedMultipleOptions ) ;
38
+ } ;
39
+
13
40
14
41
return (
15
42
< div className = "lg:min-h-adjusted order-2 col-span-12 flex min-h-min flex-col justify-between rounded-md bg-lightest px-3 py-3 dark:bg-dark lg:col-span-3 2xl:px-4 2xl:py-4" >
16
- < div className = "space-y-2" >
43
+ < div className = "flex-grow space-y-2" >
17
44
< div className = "relative flex flex-row flex-wrap items-center justify-center gap-x-2 gap-y-2 lg:justify-start" >
18
45
< SessionController />
19
46
< OptionsController />
@@ -23,6 +50,22 @@ const Sidebar = () => {
23
50
< CoursesController />
24
51
</ div >
25
52
</ div >
53
+ < footer className = "mt-4 gap-x-1 border-white-300 pt-3 text-center flex items-end justify-end" >
54
+ < Button
55
+ onClick = { eraseClasses }
56
+ variant = "icon"
57
+ className = { `bg-lightish text-darkish gap-1.5 ${ noClassesPicked ? 'opacity-50 pointer-events-none' : '' } ` }
58
+ >
59
+ < TrashIcon className = "h-5 w-5" />
60
+ < span > Limpar</ span >
61
+ </ Button >
62
+ < button title = 'Mudar o lado da Sidebar'
63
+ onClick = { toggleSidebarPosition }
64
+ className = "hidden md:flex items-center justify-center gap-2 w-[48px] h-[40px] bg-primary hover:opacity-80 dark:text-white rounded-md p-1 text-gray text-sm"
65
+ >
66
+ < ArrowsRightLeftIcon className = "h-5 w-5 text-white dark:text-white" />
67
+ </ button >
68
+ </ footer >
26
69
</ div >
27
70
)
28
71
}
0 commit comments