Skip to content

Commit

Permalink
Refactor CadastrarEvento styles and melhoria da filtragem de eventos …
Browse files Browse the repository at this point in the history
…por calendário
  • Loading branch information
LeoFacB committed Dec 8, 2024
1 parent 7ae6db5 commit 2a8c721
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
43 changes: 26 additions & 17 deletions src/app/private/pages/cadastrarEvento.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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",
Expand All @@ -308,15 +308,25 @@ import { Try } from "expo-router/build/views/Try";
paddingBottom: 10,
alignItems: "center",
paddingHorizontal: 15,
marginBottom: 10,
marginBottom: 15,
},
tituloheader: {
fontWeight: "bold",
fontSize: 20,
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%",
Expand All @@ -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%",
Expand All @@ -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,
Expand All @@ -360,35 +370,33 @@ 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,
fontSize: 24,
color: "#707070",
},
repete: {
marginBottom: 15,
marginBottom: 5,
},
weekDays: {
marginBottom: 30,
marginBottom: 0,
},
descricao: {
marginBottom: 30,
width: "100%",
marginBottom: 0,
},
textInputDescription: {
padding: 10,
Expand All @@ -400,5 +408,6 @@ import { Try } from "expo-router/build/views/Try";
},
linkButton: {
marginBottom: 30,
alignItems: "center",
},
});
21 changes: 15 additions & 6 deletions src/app/private/tabs/eventos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -79,15 +80,23 @@ export default function Eventos() {
try {
const eventoCollection = database.get('evento') as Collection<Evento>;

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);
}
Expand Down

0 comments on commit 2a8c721

Please sign in to comment.