1
1
<script lang="ts" setup>
2
- import { ref } from ' vue'
3
- import { Menu as IconMenu , Message , Setting } from ' @element-plus/icons-vue'
2
+ import { onMounted , ref , type Ref } from ' vue'
4
3
import type { Subject , Chapter } from ' @/interfaces' ;
5
4
6
5
7
- const activeSubject = ref (' Bangla 1st Paper' )
6
+ const activeSubject: Ref <string > = ref (" " )
7
+ const tableData: Ref <Chapter []> = ref ([]);
8
8
const subjectList: Subject [] = [
9
9
{
10
10
id: 1 ,
@@ -79,11 +79,13 @@ const subjectList: Subject[] = [
79
79
group: ' science'
80
80
},
81
81
]
82
- const tableData: Chapter [] = [
82
+
83
+ const chapterData: Chapter [] = [
83
84
{
84
85
id: 1 ,
85
86
number: 1 ,
86
87
name: " My Chapter" ,
88
+ subject_id: 1 ,
87
89
progress: 0 ,
88
90
cq: false ,
89
91
mcq: true
@@ -92,6 +94,7 @@ const tableData: Chapter[] = [
92
94
id: 2 ,
93
95
number: 2 ,
94
96
name: " My Chapter #2" ,
97
+ subject_id: 3 ,
95
98
progress: 25 ,
96
99
mcq: false ,
97
100
cq: true
@@ -100,33 +103,49 @@ const tableData: Chapter[] = [
100
103
id: 3 ,
101
104
number: 3 ,
102
105
name: " My Chapter #3" ,
106
+ subject_id: 1 ,
103
107
progress: 85 ,
104
108
cq: true ,
105
109
mcq: true
106
110
},
107
111
]
108
112
109
113
114
+ function updateTableData(subject_id : number ) {
115
+ const subjectChapters: Chapter [] = [];
116
+ chapterData .forEach ((chapter ) => {
117
+ if (chapter .subject_id == subject_id ) {
118
+ subjectChapters .push (chapter );
119
+ // console.log(chapter)
120
+ }
121
+ });
122
+ tableData .value = subjectChapters
123
+ }
110
124
111
125
112
126
const handleSelect = (key : string , keyPath : string []) => {
113
- console .log (keyPath )
127
+ // console.log(keyPath)
114
128
subjectList .forEach ((subject ) => {
115
129
if (subject .slug == keyPath [1 ]) {
116
130
activeSubject .value = subject .name
131
+ updateTableData (subject .id )
117
132
}
118
133
})
119
134
}
120
135
121
136
const toggleMcq = (index : number , chapter : Chapter ) => {
122
- console .log (index , chapter )
137
+ // console.log(index, chapter)
123
138
chapter .mcq = ! chapter .mcq
124
139
}
125
140
126
141
const toggleCq = (index : number , chapter : Chapter ) => {
127
- console .log (index , chapter )
142
+ // console.log(index, chapter)
128
143
chapter .cq = ! chapter .cq
129
144
}
145
+
146
+ onMounted (() => {
147
+ handleSelect (' 0' , [' 0' , ' bangla-1' ])
148
+ })
130
149
</script >
131
150
132
151
0 commit comments