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'; 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 BotoPobleAmbIndicadors = ({pob}) => { 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