Skip to content

Commit

Permalink
send data to snapshot page
Browse files Browse the repository at this point in the history
  • Loading branch information
Joabesv committed Dec 15, 2024
1 parent ac0d4cb commit 469dfa2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/components/KicksModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,15 @@ const kicksForecast = computed(() => {
})
async function fetch() {
if (!props.corteId) {
if (!props.corteId || !matriculaStudent) {
return;
}
const studentId = matriculaStudent?.studentId?.toString() ?? ''
loading.value = true;
try {
const kicksInfo = await getKicksInfo(props.corteId, studentId);
const kicksInfo = await getKicksInfo(props.corteId, matriculaStudent?.studentId);
kicks.value = kicksInfo
resort();
} catch(error: any) {
Expand Down
6 changes: 3 additions & 3 deletions src/entrypoints/matricula.content/UFABC-Matricula.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Filter = {
}
const matriculas = inject<typeof window.matriculas>('matriculas')
const matriculaStudent = inject<UFABCMatriculaStudent>('student')
const selected = ref(false)
const cursadas = ref(false)
Expand All @@ -24,7 +25,6 @@ const showWarning = ref(false);
const teachers = ref(false);
const { state: student } = useStorage<Student>('local:student');
const { state: matriculaStudent } = useStorage<UFABCMatriculaStudent>(`sync:${student.value?.ra}`)
const campusFilters = ref<Filter[]>([
{
Expand Down Expand Up @@ -114,12 +114,12 @@ function changeSelected() {
return;
}
if (!matriculaStudent.value) {
if (!matriculaStudent) {
console.log('show some message to the user')
return
}
const enrollments = matriculas?.[matriculaStudent.value.studentId] || []
const enrollments = matriculas?.[matriculaStudent?.studentId] || []
const tableRows = document.querySelectorAll('tr')
for (const $row of tableRows) {
Expand Down
16 changes: 13 additions & 3 deletions src/entrypoints/matricula.content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default defineContentScript({
const ufabcMatriculaStudent = await storage.getItem<UFABCMatriculaStudent>(
`sync:${student?.ra}`,
);

const ui = await mountUFABCMatriculaFilters(ctx, ufabcMatriculaStudent);
ui.mount();

Expand All @@ -33,10 +32,22 @@ export default defineContentScript({
$mountedUi.style.top = '0px';
$mountedUi.style.zIndex = '9';

// TODO(Joabesv): create student here
if (ufabcMatriculaStudent && student) {
await updateStudent(student.login, student.ra, ufabcMatriculaStudent.studentId)
}

const URLS_TO_CHECK = ['http://localhost:3003', 'https://ufabc-matricula-snapshot.vercel.app']
const origin = new URL(document.location.href).origin

if (URLS_TO_CHECK.includes(origin)) {
document.dispatchEvent(new CustomEvent('student-info', {
detail: {
ra: student?.ra,
login: student?.login,
hasStudent: !!student
},
}))
}
},
runAt: 'document_end',
cssInjectionMode: 'ui',
Expand Down Expand Up @@ -67,7 +78,6 @@ async function mountUFABCMatriculaFilters(

const matriculas = await getUFEnrolled();
window.matriculas = matriculas;

const app = createApp(UFABCMatricula);
app.provide('matriculas', window.matriculas);
app.provide('student', student);
Expand Down
2 changes: 1 addition & 1 deletion src/services/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export async function getComponents() {
return components;
}

export async function getKicksInfo(kickId: string, studentId: string) {
export async function getKicksInfo(kickId: string, studentId: number) {
const kicksData = await nextService(`/entities/components/${kickId}/kicks?studentId=${studentId}`)
return kicksData;
}
Expand Down

0 comments on commit 469dfa2

Please sign in to comment.