Skip to content
Snippets Groups Projects
Commit c89a54b3 authored by Guilherme Eduardo's avatar Guilherme Eduardo
Browse files

Issue #294: UPDATE remove duplicate user resources

parent c7f6cb03
No related branches found
No related tags found
No related merge requests found
Pipeline #41984 passed
......@@ -89,20 +89,21 @@ export default function ProfileResources({ id, idLogin }) {
}, [resourcesCount, homologaCount])
useEffect(() => {
// Remove os itens duplicados - Set é uma estrutura de dados
// que não aceita repetição
if (resources.length > 0 || homologaResources.length > 0) {
const unificado = [...resources, ...homologaResources];
const remove_duplicates = [... new Set (unificado)]
const unified = [...resources, ...homologaResources];
// Remove recursos duplicados com base no id (Retorna a primeira ocorrência)
const remove_duplicates = unified.filter((item, index, array) => {
return array.findIndex(obj => obj.id === item.id) === index;
});
// Atualiza o estado com os únicos
setUniqueResources(remove_duplicates);
}
}, [resources, homologaResources]);
console.log ("Recursos: ", resources)
console.log ("Homologados: ", homologaResources)
console.log ("Unificado: ", uniqueResources)
return (
<>
{got ? (
......@@ -130,27 +131,16 @@ export default function ProfileResources({ id, idLogin }) {
) : (
<div className="p-3 my-5 mb-24 mx-5 rounded-md min-w-[200px] min-h-[180px] bg-white-HC-dark ">
<div className="flex flex-wrap justify-center">
{resources.map((resource, index) => (
<Cards
id={resource.id}
key={index}
title={resource.name}
author={resource.publisher.name}
avatar={resource.publisher.avatar}
image={resource.thumbnail}
updated_at={resource.updated_at}
/>
))}
{homologaResources.map((resource, index) => (
{uniqueResources.map((resource, index) => (
<Cards
id={resource.id}
key={index}
title={resource.learning_object.name}
author={resource.learning_object.author}
avatar={resource.submitter.avatar}
image={resource.learning_object.thumbnail}
updated_at={resource.learning_object.updated_at}
homologa={resource.status}
title={resource?.name || resource.learning_object?.name}
author={resource.publisher?.name || resource.learning_object?.author}
avatar={resource.publisher?.avatar || resource.submitter?.avatar}
image={resource?.thumbnail || resource.learning_object?.thumbnail}
updated_at={resource?.updated_at || resource.learning_object?.updated_at}
homologa={resource?.status}
/>
))}
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment