Skip to content

Commit

Permalink
refact: treating duplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
ubrando committed Sep 22, 2024
1 parent f07cd3d commit 2605011
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 88 deletions.
20 changes: 1 addition & 19 deletions src/app/components/PublicacaoVisualizar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Image
source={{ uri: foto as string }}
style={styles.fotoPerfil}
testID="foto-resultado"
/>
);
}

return (
<View style={[styles.semFoto, styles.fotoPerfil]}>
<Icon style={styles.semFotoIcon} name="image-outline" size={15} />
</View>
);
};

const getFormattedDate = (payload: Date | string): string => {
const date = new Date(payload);
return date.toLocaleDateString("pt-BR");
Expand Down
18 changes: 2 additions & 16 deletions src/app/private/pages/cadastrarMetrica.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IUser | undefined>(undefined);
const [idoso, setIdoso] = useState<IIdoso>();
Expand Down Expand Up @@ -45,20 +45,6 @@ export default function criarMetrica() {
});
};

const getFoto = (foto: string | null | undefined) => {
if (hasFoto(foto)) {
return (
<Image source={{ uri: foto as string }} style={styles.fotoPerfil} />
);
}

return (
<View style={[styles.semFoto, styles.fotoPerfil]}>
<Icon style={styles.semFotoIcon} name="image-outline" size={15} />
</View>
);
};

const handleMetricSelection = async (metricType: EMetricas) => {
const body = {
idIdoso: Number(idoso?.id),
Expand Down
17 changes: 2 additions & 15 deletions src/app/private/tabs/perfil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IUser | undefined>(undefined);
Expand Down Expand Up @@ -40,20 +41,6 @@ export default function Perfil() {
});
};

const getFoto = (foto: string | null | undefined) => {
if (hasFoto(foto)) {
return (
<Image source={{ uri: foto as string }} style={styles.fotoPerfil} />
);
}

return (
<View style={[styles.semFoto, styles.fotoPerfil]}>
<Icon style={styles.semFotoIcon} name="image-outline" size={15} />
</View>
);
};

useEffect(() => handleUser(), []);

return !idUsuario ? (
Expand Down
15 changes: 1 addition & 14 deletions src/app/private/tabs/registros.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IUser | undefined>(undefined);
Expand All @@ -39,20 +40,6 @@ export default function Registros() {
});
};

const getFoto = (foto: string | null | undefined) => {
if (hasFoto(foto)) {
return (
<Image source={{ uri: foto as string }} style={styles.fotoPerfil} />
);
}

return (
<View style={[styles.semFoto, styles.fotoPerfil]}>
<Icon style={styles.semFotoIcon} name="image-outline" size={15} />
</View>
);
};

const visualizarMetrica = (item: IMetrica) => {
router.push({
pathname: "private/pages/visualizarMetrica",
Expand Down
16 changes: 1 addition & 15 deletions src/app/private/tabs/rotinas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -62,20 +62,6 @@ export default function Rotinas() {
});
};

const getFoto = (foto: string | null | undefined) => {
if (hasFoto(foto)) {
return (
<Image source={{ uri: foto as string }} style={styles.fotoPerfil} />
);
}

return (
<View style={[styles.semFoto, styles.fotoPerfil]}>
<Icon style={styles.semFotoIcon} name="image-outline" size={15} />
</View>
);
};

const novaRotina = () => {
router.push({
pathname: "private/pages/cadastrarRotina",
Expand Down
10 changes: 1 addition & 9 deletions src/app/shared/helpers/foto.helper.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Image source={{ uri: foto as string }} style={styles.fotoPerfil} />
);
}
};

0 comments on commit 2605011

Please sign in to comment.