import React, { Suspense, useEffect, useState, useRef, lazy } from 'react';
import { Meteor } from 'meteor/meteor';
import { PoblesCollection } from '/imports/api/pobles.js';
import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/suspense';
import { Roles } from 'meteor/roles';
// import { useUserId } from 'meteor/react-meteor-accounts';
import { BarraNav } from "./BarraNav/BarraNav";
import { Link } from 'react-router-dom';
import { NecessitatsCollection } from '../api/necessitats';
const QuadreInfo_Poble = ({esEditor, pobleSeleccionat, setPobleSeleccionat}) => {
const refInAmbitAssignat = useRef();
return
{pobleSeleccionat &&
{pobleSeleccionat._id}
}
;
};
const BotoPobleAmbIndicadors = ({pob, pobleSeleccionat, setPobleSeleccionat, esEditor}) => {
// let pob = pobleSeleccionat;
useSubscribe('necessitats', pob.ambitAssociat);
const necessitats = useFind(NecessitatsCollection, [{"poble.ambitAssociat": pob.ambitAssociat}]);
const [monitors, setMonitors] = useState(false);
const [encarregats, setEncarregats] = useState(false);
const [voluntaris, setVoluntaris] = useState(false);
// let mon, mons, enc, encs, vol, vols;
(async () => {
const mons = await Roles.getUsersInRoleAsync("monitor_de_poble", pob?.ambitAssociat);
// console.log("monitors: ", monitors);
setMonitors(mons?.fetch().length || false);
const encs = await Roles.getUsersInRoleAsync("encarregat_de_tasques", pob?.ambitAssociat);
// console.log("monitors: ", monitors);
setEncarregats(encs?.fetch().length || false);
const vols = await Roles.getUsersInRoleAsync("voluntari_de_poble", pob?.ambitAssociat);
// console.log("monitors: ", monitors);
setVoluntaris(vols?.fetch().length || false);
})();
return
{// Indicadors de Responsables
{
monitors
? {monitors}
: false
}
{ encarregats
? {encarregats}
: false
}
{ voluntaris
? {voluntaris}
: false
}
}
{// Indicadors de Necessitats
{
necessitats.length
?
{necessitats.length }
: false
}
}
{// Botó de creació de nou poble
{pob.nomPoble} {esEditor && }
}
;
}
export const Pobles = () => {
const [pobleSeleccionat, setPobleSeleccionat] = useState(null);
const [creantPoble, setCreantPoble] = useState(false);
useSubscribe('pobles');
useSubscribe('usuaris');
// const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync());
const pobles = useFind(PoblesCollection, [{}, {sort: {nomPoble: 1}}]);
const [esEditor, setEsEditor] = useState(false);
const userId = Meteor.userId();
// console.log("isAdmin: ", isAdmin) ;
// (async () => {
useEffect(() => {
(async () => {
const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]);
setEsEditor(comprovaAdmin);
})();
}, []);
// })();
// const Indicador = ({valor, ambit, }) => {
// };
return <>
Pobles
{ esEditor && (pobleSeleccionat || creantPoble) && }
{
pobles
.sort((a,b) => a.nomPoble?.toLowerCase() > b.nomPoble?.toLowerCase())
.map(pob => {
return
})
}
{esEditor && }
>;
};