1
1
<script setup lang="ts">
2
- import Cortes from ' @/components/Cortes.vue' ;
3
- import Teachers from ' @/components/Teachers.vue' ;
4
2
import { getComponents } from ' @/services/next' ;
5
3
import { render } from ' vue' ;
6
4
import SubjectReview from ' @/components/SubjectReview.vue' ;
@@ -10,32 +8,21 @@ import { toast, Toaster } from 'vue-sonner'
10
8
import { useQuery } from ' @tanstack/vue-query' ;
11
9
import { useFilters } from ' @/composables/useFilters'
12
10
import { useModals } from ' @/composables/useModals'
11
+ import { useComponentsBuilder } from ' @/composables/useComponentsBuilder'
13
12
import type { UFABCMatriculaStudent } from ' .' ;
14
13
import type { Student } from ' @/scripts/sig/homepage' ;
15
14
16
-
17
- type Filter = {
18
- name: ' Santo André' | ' São Bernardo' | ' Noturno' | ' Matutino'
19
- val: boolean
20
- comparator: ' bernardo' | ' andr' | ' diurno' | ' noturno'
21
- class: ' notAndre' | ' notBernardo' | ' notNoturno' | ' notMatutino'
22
- }
23
-
24
15
const matriculas = inject <typeof window .matriculas >(' matriculas' )
25
16
const matriculaStudent = inject <UFABCMatriculaStudent >(' student' )
26
17
27
18
const { state : student } = useStorage <Student >(' local:student' );
28
19
const { campusFilters, shiftFilters, applyFilter } = useFilters ()
29
20
const { subjectReview, kicksModal, teacherReview } = useModals ()
21
+ const { teachers, buildComponents } = useComponentsBuilder ()
30
22
31
23
const selected = ref (false )
32
24
const cursadas = ref (false )
33
25
const showWarning = ref (false );
34
- const teachers = ref (false );
35
- const { data : components } = useQuery ({
36
- queryKey: [' components' ],
37
- queryFn : () => getComponents (),
38
- })
39
26
40
27
function openSubjectReview(subjectId : string ) {
41
28
subjectReview .value .isOpen = true ;
@@ -105,7 +92,7 @@ function changeCursadas() {
105
92
}
106
93
return ;
107
94
}
108
- if (student .value ) {
95
+ if (! student .value ) {
109
96
toast .warning (' Não encontramos suas disciplinas cursadas, por favor acesse o sigaa' )
110
97
return
111
98
}
@@ -154,77 +141,6 @@ const target = event.target as HTMLElement;
154
141
}
155
142
}
156
143
157
-
158
-
159
- async function buildComponents() {
160
- if (! teachers .value ) {
161
- for (const $element of document .querySelectorAll <HTMLTableCaptionElement >(' .isTeacherReview' )) {
162
- $element .style .display = ' none'
163
- }
164
- return
165
- }
166
- // se ja tiver calculado nao refaz o trabalho
167
- const teacherReviews = document .querySelectorAll <HTMLTableCaptionElement >(' .isTeacherReview' );
168
- if (teacherReviews .length > 0 ) {
169
- for (const $element of document .querySelectorAll <HTMLTableCaptionElement >(' .isTeacherReview' )) {
170
- $element .style .display = ' '
171
- }
172
- return ;
173
- }
174
- const components = await getComponents ()
175
- const componentsMap = new Map (
176
- components .map ((component ) => [
177
- component .disciplina_id .toString (),
178
- component ,
179
- ]),
180
- );
181
-
182
- const mainTable = document .querySelectorAll (' table tr' );
183
- for (const row of mainTable ) {
184
- const el = row .querySelector <HTMLTableColElement >(' td:nth-child(3)' );
185
- const subjectEl = row .querySelector <HTMLSpanElement >(' td:nth-child(3) > span' );
186
- const corteEl = row .querySelector (' td:nth-child(5)' );
187
- const componentId = row .getAttribute (' value' );
188
- if (! componentId ) {
189
- continue ;
190
- }
191
- const component = componentsMap .get (componentId );
192
- if (! component ) {
193
- continue ;
194
- }
195
-
196
- if (component .subject && subjectEl ) {
197
- subjectEl .style .cursor = ' pointer'
198
-
199
- subjectEl .addEventListener (' mouseenter' , () => {
200
- subjectEl .style .textDecoration = ' underline' ;
201
- });
202
-
203
- subjectEl .addEventListener (' mouseleave' , () => {
204
- subjectEl .style .textDecoration = ' none' ;
205
- });
206
-
207
- subjectEl .setAttribute (' subjectId' , component .subjectId );
208
- }
209
-
210
- const teacherContainer = document .createElement (' div' )
211
- el ?.appendChild (teacherContainer )
212
-
213
- render (h (Teachers , {
214
- teoria: component .teoria ,
215
- teoriaId: component .teoriaId ,
216
- pratica: component .pratica ,
217
- praticaId: component .praticaId ,
218
- }), teacherContainer )
219
-
220
- const cortesContainer = document .createElement (' div' );
221
- corteEl ?.appendChild (cortesContainer );
222
-
223
- render (h (Cortes ), cortesContainer )
224
- }
225
- }
226
-
227
-
228
144
onMounted (async () => {
229
145
document .body .addEventListener (" click" , handleClick );
230
146
const studentId = getStudentId ()
@@ -235,7 +151,7 @@ onMounted(async () => {
235
151
})
236
152
237
153
teachers .value = true ;
238
- await buildComponents ();
154
+ buildComponents ();
239
155
})
240
156
241
157
onUnmounted (() => {
0 commit comments