Skip to content

Commit

Permalink
Merge pull request #27 from iic2154-uc-cl/get_campana
Browse files Browse the repository at this point in the history
campana funcional para masivas [muestra todas]
  • Loading branch information
luzmagurzua authored Nov 7, 2024
2 parents 67798ac + cebd7df commit c6e24f3
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/components/Campana.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import '../pages/users/campana.css';

const Campana = () => {
const [isOpen, setIsOpen] = useState(false);
const [notificaciones, setNotificaciones] = useState([]);

const toggleNotifications = () => {
setIsOpen(!isOpen);
};

useEffect(() => {
if (isOpen && notificaciones.length === 0) {
fetch('http://localhost:8000/onesignal/notificaciones/')
.then((response) => response.json())
.then((data) => setNotificaciones(data))
.catch((error) => console.error('Error fetching notifications:', error));
}
}, [isOpen]);

return (
<div className="campana-container">
<div className="loader" onClick={toggleNotifications}>
Expand Down Expand Up @@ -35,9 +45,16 @@ const Campana = () => {
<div className="notification-box">
<h4>Notificaciones</h4>
<ul>
<li>Notificación 1</li>
<li>Notificación 2</li>
<li>Notificación 3</li>
{notificaciones.length > 0 ? (
notificaciones.map((notificacion, index) => (
<li key={index}>
<h5>{notificacion.title}</h5>
<p>{notificacion.message}</p>
</li>
))
) : (
<li>No hay notificaciones disponibles</li>
)}
</ul>
</div>
)}
Expand Down

0 comments on commit c6e24f3

Please sign in to comment.