From 2a8c7214fa9d9303aff59f5f7ab1d79ecde88dc1 Mon Sep 17 00:00:00 2001 From: Leonardo Bonetti Date: Sun, 8 Dec 2024 01:17:05 -0300 Subject: [PATCH] =?UTF-8?q?Refactor=20CadastrarEvento=20styles=20and=20mel?= =?UTF-8?q?horia=20da=20filtragem=20de=20eventos=20por=20calend=C3=A1rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/private/pages/cadastrarEvento.tsx | 43 ++++++++++++++--------- src/app/private/tabs/eventos.tsx | 21 +++++++---- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/app/private/pages/cadastrarEvento.tsx b/src/app/private/pages/cadastrarEvento.tsx index 8435224..79491b3 100644 --- a/src/app/private/pages/cadastrarEvento.tsx +++ b/src/app/private/pages/cadastrarEvento.tsx @@ -105,7 +105,7 @@ import { Try } from "expo-router/build/views/Try"; evento.dataHora = new Date(getDateIsoString()); evento.token = token; evento.notificacao = notificacao; - evento.idIdoso = String(idoso?.id); + evento.idIdoso = idoso?.id; }); }); console.log("Estado atual do banco:", await eventoCollection.query().fetch()); @@ -291,7 +291,7 @@ import { Try } from "expo-router/build/views/Try"; alignItems: "center", width: "100%", fontWeight: "700", - marginBottom: 25, + marginBottom: 20, }, notificacaoText: { fontWeight: "600", @@ -308,7 +308,7 @@ import { Try } from "expo-router/build/views/Try"; paddingBottom: 10, alignItems: "center", paddingHorizontal: 15, - marginBottom: 10, + marginBottom: 15, }, tituloheader: { fontWeight: "bold", @@ -316,7 +316,17 @@ import { Try } from "expo-router/build/views/Try"; color: "#fff", }, evento: { - marginHorizontal: 10, + flexDirection: "column", + borderRadius: 15, + backgroundColor: "white", + margin: 15, + padding: 15, + shadowColor: "#000", + shadowOffset: { width: 1, height: 1 }, + shadowOpacity: 0.3, + shadowRadius: 6, + alignItems: "center", + justifyContent: "center", }, titulo: { width: "100%", @@ -325,7 +335,7 @@ import { Try } from "expo-router/build/views/Try"; borderRadius: 6, justifyContent: "center", paddingHorizontal: 15, - marginBottom: 30, + marginBottom: -20, }, inputTitulo: { width: "100%", @@ -340,7 +350,7 @@ import { Try } from "expo-router/build/views/Try"; height: 60, backgroundColor: "#F6F6F6", borderRadius: 6, - marginBottom: 30, + marginBottom: 0, flexDirection: "row", alignItems: "center", paddingHorizontal: 15, @@ -360,21 +370,18 @@ import { Try } from "expo-router/build/views/Try"; borderRadius: 5, borderWidth: 0, height: 60, - marginBottom: 30, + marginBottom: -5, }, categoriaSelecionada: { fontSize: 18, color: "#707070", }, categoria: { - width: "100%", - height: 60, - backgroundColor: "#F6F6F6", - borderRadius: 6, - marginBottom: 30, flexDirection: "row", - alignItems: "center", - paddingHorizontal: 15, + borderBottomWidth: 1, + width: 300, + alignItems: "baseline", + paddingBottom: 5, }, iconCategoria: { marginRight: 10, @@ -382,13 +389,14 @@ import { Try } from "expo-router/build/views/Try"; color: "#707070", }, repete: { - marginBottom: 15, + marginBottom: 5, }, weekDays: { - marginBottom: 30, + marginBottom: 0, }, descricao: { - marginBottom: 30, + width: "100%", + marginBottom: 0, }, textInputDescription: { padding: 10, @@ -400,5 +408,6 @@ import { Try } from "expo-router/build/views/Try"; }, linkButton: { marginBottom: 30, + alignItems: "center", }, }); diff --git a/src/app/private/tabs/eventos.tsx b/src/app/private/tabs/eventos.tsx index f522dcb..83172cb 100644 --- a/src/app/private/tabs/eventos.tsx +++ b/src/app/private/tabs/eventos.tsx @@ -28,6 +28,7 @@ import database from "../../db"; import { Collection, Q } from "@nozbe/watermelondb"; import Evento from "../../model/Evento"; import { getFoto } from "../../shared/helpers/photo.helper"; +import { json } from "@nozbe/watermelondb/decorators"; export default function Eventos() { moment.locale("pt-br"); @@ -79,15 +80,23 @@ export default function Eventos() { try { const eventoCollection = database.get('evento') as Collection; - const allIdosoEventos = await eventoCollection.query( - Q.where('idoso_id', idoso.id) - ).fetch(); + // TODO: Consulta com defeito, arrumar um jeito de filtar com ela + /*const eventoFiltrados = await eventoCollection.query( + Q.where('idoso_id', idoso.id), + ).fetch();*/ - const filteredEventos = allIdosoEventos.filter((evento) => { - return moment(evento.dataHora).isSame(selectedDate, 'day'); + const todosEventos = await eventoCollection.query().fetch(); + + const startOfDay = selectedDate.startOf('day').toISOString(); + const endOfDay = selectedDate.endOf('day').toISOString(); + + // Metodo menos eficiente, assim que resolvido deve ser descontinuado + const eventosFiltrados = todosEventos.filter(evento => { + const eventoDataHora = new Date(evento.dataHora).toISOString(); + return evento.idIdoso === idoso.id && eventoDataHora >= startOfDay && eventoDataHora <= endOfDay; }); - setEventos(filteredEventos); + setEventos(eventosFiltrados); } finally { setLoading(false); }