Skip to content

Commit

Permalink
this code was written in extreme stress, ill debug it later
Browse files Browse the repository at this point in the history
  • Loading branch information
Joabesv committed Dec 11, 2024
1 parent d8189ee commit 049ea6f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
24 changes: 18 additions & 6 deletions src/entrypoints/popup/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@ import { Loader2 } from 'lucide-vue-next'
import { useStorage } from '@/composables/useStorage'
import { useDateFormat } from '@vueuse/core'
import type { Student } from '@/scripts/sig/homepage'
import { getStudent, type MatriculaStudent } from '@/services/next';
const { state: student, isLoading: loading, error } = useStorage<Student>('local:student');
const studentCoefficients = ref<MatriculaStudent>()
const formattedDate = useDateFormat(student.value?.lastUpdate, 'DD/MM/YYYY HH:mm', { locales: 'pt-BR' })
onMounted(async () => {
if (!student.value) {
return;
}
const matriculaStudent = await getStudent(student.value.login, student.value.ra)
studentCoefficients.value = matriculaStudent;
})
</script>

<template>
Expand All @@ -32,16 +44,16 @@ const formattedDate = useDateFormat(student.value?.lastUpdate, 'DD/MM/YYYY HH:mm
<h3 class="font-bold flex-auto">{{ student.login }}</h3>
<span class="flex-none text-right text-sm">{{ student.ra }}</span>
</div>
<template v-if="student.graduations?.length">
<div class="mb-2 border border-solid border-[#efefef] rounded p-1.5" v-for="graduation in student.graduations">
<template v-if="studentCoefficients">
<div class="mb-2 border border-solid border-[#efefef] rounded p-1.5" v-for="graduation in studentCoefficients.graduations">
<div class="text-sm mb-1">
{{ graduation.course }}<br />
{{ graduation.name }}<br />
<b>{{ graduation.shift }}</b>
</div>
<div class="flex">
<span class="flex-1 text-sm text-left text-[#c78d00]">CP: {{ 1 }}</span>
<span class="flex-1 text-sm text-center text-[#05C218]">CR: {{ 1 }}</span>
<span class="flex-1 text-sm text-right text-[#2E7EED]">CA: {{ 1 }}</span>
<span class="flex-1 text-sm text-left text-[#c78d00]">CP: {{ graduation.cp }}</span>
<span class="flex-1 text-sm text-center text-[#05C218]">CR: {{ graduation.cr }}</span>
<span class="flex-1 text-sm text-right text-[#2E7EED]">CA: {{ graduation.ca }}</span>
</div>
</div>
</template>
Expand Down
5 changes: 3 additions & 2 deletions src/entrypoints/sig.content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { storage } from "wxt/storage";
import { scrapeMenu, type Student } from "@/scripts/sig/homepage";
import "toastify-js/src/toastify.css";
import '@/assets/tailwind.css'
import { syncHistory, type SigHistory } from "@/services/next";
import { createStudent, syncHistory, type SigHistory } from "@/services/next";
import { processingToast, errorToast, successToast } from '@/utils/toasts'

export default defineContentScript({
Expand Down Expand Up @@ -46,6 +46,7 @@ export default defineContentScript({
})

await storage.setItem("local:student", mergedStudent);
await createStudent(mergedStudent)
}
// update regular student - not new and same course
await syncHistory({
Expand All @@ -55,14 +56,14 @@ export default defineContentScript({
components: currentGraduation.components
})
} else {
await storage.setItem("local:student", currentStudent);
// Create student record with first graduation
await syncHistory({
ra: currentStudent.ra,
course: existingStudent?.graduations[0].course as string,
grade: existingStudent?.graduations[0].grade as string,
components: existingStudent?.graduations[0].components as SigHistory['components']
})
await storage.setItem("local:student", currentStudent);
}

successToast.showToast();
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/sig/homepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export async function scrapeMenu(
const graduation = {
course: currentGraduation.course,
campus: currentGraduation.campus,
grade: curriculumByRa.appliedAt,
grade: curriculumByRa.grade,
shift: currentGraduation.shift,
components,
};
Expand Down
1 change: 1 addition & 0 deletions src/services/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export type MatriculaStudent = {
affinity: number;
cp: number;
cr: number;
ca: number
}[];
}

Expand Down

0 comments on commit 049ea6f

Please sign in to comment.