From cb7e982c213dbafc4f8e8ecdbe0dbe521ca984d1 Mon Sep 17 00:00:00 2001 From: Araozu Date: Fri, 14 Oct 2022 23:44:20 -0500 Subject: [PATCH] Usar rutas de backend --- src/API/Login.ts | 1 + src/App.tsx | 2 +- src/Store.ts | 2 +- src/Views/Index.tsx | 22 +++++++++++----------- src/Views/MobileIndex.tsx | 10 +++++----- src/Views/SeleccionCursos.tsx | 8 ++++---- src/Views/SistemasMovil.tsx | 4 ++-- src/Views/VerMatricula.tsx | 4 ++-- src/Views/pc/SeleccionCursos.tsx | 18 +++++++++--------- src/Views/pc/Sistemas.tsx | 6 +++--- src/Views/pc/VerMatricula.tsx | 11 +++++------ 11 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/API/Login.ts b/src/API/Login.ts index c200919..73fa550 100644 --- a/src/API/Login.ts +++ b/src/API/Login.ts @@ -21,6 +21,7 @@ export const loginFn: LoginFunction = async(data) => { const petition = await fetch(`${SERVER_PATH}/login`, { method: "POST", headers: { + "Accept": "application/json", "Content-Type": "application/json", }, body: JSON.stringify({ diff --git a/src/App.tsx b/src/App.tsx index 2fa0558..6393f89 100755 --- a/src/App.tsx +++ b/src/App.tsx @@ -15,7 +15,7 @@ function App() { const isMobile = screen.width <= 500; return ( -
+
diff --git a/src/Store.ts b/src/Store.ts index 542e7cc..15c91e0 100755 --- a/src/Store.ts +++ b/src/Store.ts @@ -29,7 +29,7 @@ export const horasDescanso = [ "15:40 - 15:50", "17:30 - 17:40", ]; -export const SERVER_PATH = ""; +export const SERVER_PATH = "http://localhost:4000/sistema"; const numImgGuardado = Number(localStorage.getItem("num-img") ?? "0"); const tamanoLetraGuardado = Number(/* localStorage.getItem("tamano-letra") ?? */ "16"); diff --git a/src/Views/Index.tsx b/src/Views/Index.tsx index 9b713cd..f5ea7ee 100644 --- a/src/Views/Index.tsx +++ b/src/Views/Index.tsx @@ -4,7 +4,7 @@ import { RouterLink } from "../Router"; import { batch, createSignal, Show } from "solid-js"; import { isMobile, setGruposSeleccionados } from "../Store"; import { MobileIndex } from "./MobileIndex"; -import { mockLoginEmpty, mockLoginNotEmpty, mockLoginWithError } from "../API/Login"; +import { loginFn } from "../API/Login"; const e = StyleSheet.create({ contenedorGlobal: { @@ -46,17 +46,17 @@ const e = StyleSheet.create({ export function Index() { const [msgErrorVisible, setMsgErrorVisible] = createSignal(false); - const inputElement = ; + const inputElement = ; const login = async(ev: Event) => { ev.preventDefault(); const email = (inputElement as HTMLInputElement).value; - const response = await mockLoginEmpty({correo_usuario: email}); + const response = await loginFn({correo_usuario: email}); if (response === null) { setMsgErrorVisible(true); setTimeout(() => setMsgErrorVisible(false), 2500); - } else if (response.matriculas.length === 0) { + } else if (!response.matriculas || response.matriculas.length === 0) { localStorage.setItem("correo", email); window.location.href = "#/pc/seleccion-cursos/"; } else if (response.matriculas.length > 0) { @@ -73,9 +73,9 @@ export function Index() { return ( <> -
-
-
+
+
+

Horarios UNSA

-

+

Inicia sesión con tu correo institucional.
{inputElement} @@ -92,17 +92,17 @@ export function Index() { El correo es invalido

-

- + Código fuente en GitHub
diff --git a/src/Views/MobileIndex.tsx b/src/Views/MobileIndex.tsx index 88025aa..aa459ec 100644 --- a/src/Views/MobileIndex.tsx +++ b/src/Views/MobileIndex.tsx @@ -1,7 +1,7 @@ import { css, StyleSheet } from "aphrodite/no-important"; import { batch, createSignal } from "solid-js"; import { SERVER_PATH, setGruposSeleccionados } from "../Store"; -import { mockLoginEmpty } from "../API/Login"; +import { loginFn } from "../API/Login"; const e = StyleSheet.create({ contenedorGlobal: { @@ -51,12 +51,12 @@ export function MobileIndex() { }); const [msgErrorVisible, setMsgErrorVisible] = createSignal(false); - const inputElement = ; + const inputElement = ; const login = async(ev: Event) => { ev.preventDefault(); const email = (inputElement as HTMLInputElement).value; - const response = await mockLoginEmpty({correo_usuario: email}); + const response = await loginFn({correo_usuario: email}); if (response === null) { setMsgErrorVisible(true); @@ -76,7 +76,7 @@ export function MobileIndex() { }; return ( -
+

Iniciar sesión


@@ -84,7 +84,7 @@ export function MobileIndex() {
login(ev)}> {inputElement}
- +
El correo es invalido
diff --git a/src/Views/SeleccionCursos.tsx b/src/Views/SeleccionCursos.tsx index b1460d4..6e55fd3 100644 --- a/src/Views/SeleccionCursos.tsx +++ b/src/Views/SeleccionCursos.tsx @@ -2,7 +2,7 @@ import { TopBar } from "./SistemasMovil/TopBar"; import { StyleSheet, css } from "aphrodite/no-important"; import { Card } from "../components/Card"; import { createSignal, For } from "solid-js"; -import { getAllListaCursosMock, RespuestaListaCursos } from "../API/ListaCursos"; +import { getAllListaCursos, RespuestaListaCursos } from "../API/ListaCursos"; import { Button } from "../components/Button"; const s = StyleSheet.create({ @@ -23,7 +23,7 @@ export function SeleccionCursos() { const [msjErr, setMsjError] = createSignal(false); // Recuperar cursos de back - (async() => setCursos(await getAllListaCursosMock()))(); + (async() => setCursos(await getAllListaCursos()))(); const submit = (ev: Event) => { ev.preventDefault(); @@ -62,14 +62,14 @@ export function SeleccionCursos() { {([nombreAnio, infoCurso]) => (

{nombreAnio} año

-
+
{(curso) => ( <> {curso.nombre_curso} diff --git a/src/Views/SistemasMovil.tsx b/src/Views/SistemasMovil.tsx index 28fad90..d153501 100644 --- a/src/Views/SistemasMovil.tsx +++ b/src/Views/SistemasMovil.tsx @@ -1,6 +1,6 @@ import { TopBar } from "./SistemasMovil/TopBar"; import { GrupoDia, Table, TableInput } from "./SistemasMovil/Table"; -import { getHorariosMock, Horario, ListaCursosCompleto } from "../API/CargaHorarios"; +import { getHorarios, Horario, ListaCursosCompleto } from "../API/CargaHorarios"; import { createSignal } from "solid-js"; import { generarMapaCeldas } from "./SistemasMovil/mapaCeldas"; import { Button } from "../components/Button"; @@ -12,7 +12,7 @@ export function SistemasMovil() { // Obtener cursos seleccionados del servidor (async() => { const cursos: Array = JSON.parse(localStorage.getItem("cursos-seleccionados") ?? "[]"); - const data = await getHorariosMock({ + const data = await getHorarios({ cursos: cursos.map((x) => parseInt(x, 10)), }); setRawData(data); diff --git a/src/Views/VerMatricula.tsx b/src/Views/VerMatricula.tsx index fda5d06..d3cf54d 100644 --- a/src/Views/VerMatricula.tsx +++ b/src/Views/VerMatricula.tsx @@ -1,7 +1,7 @@ import { TopBar } from "./SistemasMovil/TopBar"; import { Card } from "../components/Card"; import { createSignal, For } from "solid-js"; -import { getMatriculaMock, InfoMatricula } from "../API/VerMatricula"; +import { getMatricula, InfoMatricula } from "../API/VerMatricula"; import { gruposSeleccionados } from "../Store"; export function VerMatricula() { @@ -11,7 +11,7 @@ export function VerMatricula() { const laboratorios = Object.entries(gruposSeleccionados) .filter((x) => x[1] === true) .map((x) => parseInt(x[0], 10)); - setInfoMatriculas(await getMatriculaMock({matriculas: laboratorios})); + setInfoMatriculas(await getMatricula({matriculas: laboratorios})); })(); return ( diff --git a/src/Views/pc/SeleccionCursos.tsx b/src/Views/pc/SeleccionCursos.tsx index 24946e0..20f1cf9 100644 --- a/src/Views/pc/SeleccionCursos.tsx +++ b/src/Views/pc/SeleccionCursos.tsx @@ -1,7 +1,7 @@ import { css, StyleSheet } from "aphrodite/no-important"; import { estilosGlobales } from "../../Estilos"; import { createSignal, For } from "solid-js"; -import { getAllListaCursosMock, RespuestaListaCursos } from "../../API/ListaCursos"; +import { getAllListaCursos, RespuestaListaCursos } from "../../API/ListaCursos"; const e = StyleSheet.create({ contenedorGlobal: { @@ -55,7 +55,7 @@ export function SeleccionCursos() { const [msgErr, setMsgError] = createSignal(false); // Recuperar cursos de back - (async() => setCursos(await getAllListaCursosMock()))(); + (async() => setCursos(await getAllListaCursos()))(); const submit = (ev: Event) => { ev.preventDefault(); @@ -83,10 +83,10 @@ export function SeleccionCursos() { }; return ( -
-
+
+
-
+

( <>

{nombreAnio} año

-
+
{(curso) => ( <> {curso.nombre_curso} @@ -124,9 +124,9 @@ export function SeleccionCursos() {
diff --git a/src/Views/pc/Sistemas.tsx b/src/Views/pc/Sistemas.tsx index 3c2f5c5..f217a59 100644 --- a/src/Views/pc/Sistemas.tsx +++ b/src/Views/pc/Sistemas.tsx @@ -3,7 +3,7 @@ import { ContenedorHorarios } from "./Sistemas/ContenedorHorarios"; import { Creditos } from "../../Creditos"; import { Separador } from "../../Separador"; import { createSignal } from "solid-js"; -import { getHorariosMock, ListaCursosCompleto } from "../../API/CargaHorarios"; +import { getHorarios, ListaCursosCompleto } from "../../API/CargaHorarios"; import { Cursos, DatosGrupo } from "../../types/DatosHorario"; import { infoDiaAListaHoras } from "../SistemasMovil"; import { StyleSheet, css } from "aphrodite/no-important"; @@ -25,7 +25,7 @@ export function Sistemas() { // Obtener cursos seleccionados del servidor (async() => { const cursos: Array = JSON.parse(localStorage.getItem("cursos-seleccionados") ?? "[]"); - const data = await getHorariosMock({ + const data = await getHorarios({ cursos: cursos.map((x) => parseInt(x, 10)), }); setData(listaCursosADatos(data)); @@ -62,7 +62,7 @@ export function Sistemas() {