From 26050119f979cd03e51439375dbd974d898ea260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ugor=20Marcilio=20Brand=C3=A3o=20Costa?= Date: Sat, 21 Sep 2024 21:01:31 -0300 Subject: [PATCH] refact: treating duplicity --- src/app/components/PublicacaoVisualizar.tsx | 20 +------------------- src/app/private/pages/cadastrarMetrica.tsx | 18 ++---------------- src/app/private/tabs/perfil.tsx | 17 ++--------------- src/app/private/tabs/registros.tsx | 15 +-------------- src/app/private/tabs/rotinas.tsx | 16 +--------------- src/app/shared/helpers/foto.helper.tsx | 10 +--------- 6 files changed, 8 insertions(+), 88 deletions(-) diff --git a/src/app/components/PublicacaoVisualizar.tsx b/src/app/components/PublicacaoVisualizar.tsx index 5194240..92162ec 100644 --- a/src/app/components/PublicacaoVisualizar.tsx +++ b/src/app/components/PublicacaoVisualizar.tsx @@ -4,31 +4,13 @@ import { IPublicacaoUsuario } from "../interfaces/forum.interface"; import Icon from "react-native-vector-icons/MaterialCommunityIcons"; import AntDesing from "react-native-vector-icons/AntDesign"; import { hasFoto } from "../shared/helpers/foto.helper"; - +import { getFoto } from "../shared/helpers/photo.helper"; interface IProps { item: IPublicacaoUsuario; } export default function PublicacaoVisualizar({ item }: IProps) { - const getFoto = (foto: string | null | undefined) => { - if (hasFoto(foto)) { - return ( - - ); - } - - return ( - - - - ); - }; - const getFormattedDate = (payload: Date | string): string => { const date = new Date(payload); return date.toLocaleDateString("pt-BR"); diff --git a/src/app/private/pages/cadastrarMetrica.tsx b/src/app/private/pages/cadastrarMetrica.tsx index 156da57..5e6f5b7 100644 --- a/src/app/private/pages/cadastrarMetrica.tsx +++ b/src/app/private/pages/cadastrarMetrica.tsx @@ -15,9 +15,9 @@ import { router } from "expo-router"; import { postMetrica } from "../../services/metrica.service"; import { EMetricas, IMetrica } from "../../interfaces/metricas.interface"; import Toast from "react-native-toast-message"; -import { hasFoto +import { hasFoto} from "../../shared/helpers/foto.helper"; +import { getFoto } from "../../shared/helpers/photo.helper"; - } from "../../shared/helpers/foto.helper"; export default function criarMetrica() { const [user, setUser] = useState(undefined); const [idoso, setIdoso] = useState(); @@ -45,20 +45,6 @@ export default function criarMetrica() { }); }; - const getFoto = (foto: string | null | undefined) => { - if (hasFoto(foto)) { - return ( - - ); - } - - return ( - - - - ); - }; - const handleMetricSelection = async (metricType: EMetricas) => { const body = { idIdoso: Number(idoso?.id), diff --git a/src/app/private/tabs/perfil.tsx b/src/app/private/tabs/perfil.tsx index ad9ad6c..4164ea2 100644 --- a/src/app/private/tabs/perfil.tsx +++ b/src/app/private/tabs/perfil.tsx @@ -6,7 +6,8 @@ import AsyncStorage from "@react-native-async-storage/async-storage"; import { IUser } from "../../interfaces/user.interface"; import { router } from "expo-router"; import NaoAutenticado from "../../components/NaoAutenticado"; -import { hasFoto, getFoto } from "../../shared/helpers/foto.helper"; +import { hasFoto } from "../../shared/helpers/foto.helper"; +import { getFoto } from "../../shared/helpers/photo.helper"; export default function Perfil() { const [user, setUser] = useState(undefined); @@ -40,20 +41,6 @@ export default function Perfil() { }); }; - const getFoto = (foto: string | null | undefined) => { - if (hasFoto(foto)) { - return ( - - ); - } - - return ( - - - - ); - }; - useEffect(() => handleUser(), []); return !idUsuario ? ( diff --git a/src/app/private/tabs/registros.tsx b/src/app/private/tabs/registros.tsx index e32fc0e..3c6fb86 100644 --- a/src/app/private/tabs/registros.tsx +++ b/src/app/private/tabs/registros.tsx @@ -16,6 +16,7 @@ import Toast from "react-native-toast-message"; import database from "../../db"; import { Q } from "@nozbe/watermelondb"; import { hasFoto } from "../../shared/helpers/foto.helper"; +import { getFoto } from "../../shared/helpers/photo.helper"; export default function Registros() { const [user, setUser] = useState(undefined); @@ -39,20 +40,6 @@ export default function Registros() { }); }; - const getFoto = (foto: string | null | undefined) => { - if (hasFoto(foto)) { - return ( - - ); - } - - return ( - - - - ); - }; - const visualizarMetrica = (item: IMetrica) => { router.push({ pathname: "private/pages/visualizarMetrica", diff --git a/src/app/private/tabs/rotinas.tsx b/src/app/private/tabs/rotinas.tsx index 8813ae2..9255f43 100644 --- a/src/app/private/tabs/rotinas.tsx +++ b/src/app/private/tabs/rotinas.tsx @@ -31,7 +31,7 @@ import "moment/locale/pt-br"; import database from "../../db"; import { Collection, Q } from "@nozbe/watermelondb"; import Rotina from "../../model/Rotina"; -import { hasFoto } from "../../shared/helpers/foto.helper"; +import { getFoto } from "../../shared/helpers/photo.helper"; export default function Rotinas() { moment.locale("pt-br"); @@ -62,20 +62,6 @@ export default function Rotinas() { }); }; - const getFoto = (foto: string | null | undefined) => { - if (hasFoto(foto)) { - return ( - - ); - } - - return ( - - - - ); - }; - const novaRotina = () => { router.push({ pathname: "private/pages/cadastrarRotina", diff --git a/src/app/shared/helpers/foto.helper.tsx b/src/app/shared/helpers/foto.helper.tsx index 97502b4..0ebb511 100644 --- a/src/app/shared/helpers/foto.helper.tsx +++ b/src/app/shared/helpers/foto.helper.tsx @@ -1,17 +1,9 @@ // Funções auxiliares para foto: -import { Image } from 'react-native'; // Import do Image para usar na função getFoto +import { Image } from 'react-native'; import React from "react"; export const hasFoto = (foto: string | null | undefined): boolean => { if (!foto) return false; const raw = foto.split("data:image/png;base64,")[1]; return raw ? raw.length > 0 : false; -}; - -export const getFoto = (foto: string | null | undefined, styles: any) => { - if (hasFoto(foto)) { - return ( - - ); - } }; \ No newline at end of file