diff --git a/imports/ui/Usuaris.jsx b/imports/ui/Usuaris.jsx index 3491b99..8873b5a 100644 --- a/imports/ui/Usuaris.jsx +++ b/imports/ui/Usuaris.jsx @@ -5,155 +5,206 @@ import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/susp import { Roles } from 'meteor/roles'; // import { useUserId } from 'meteor/react-meteor-accounts'; -import { BarraNav } from "./BarraNav/BarraNav"; -const isClickInsideRectangle = (e, element) => { - const r = element?.getBoundingClientRect(); - return ( - e.clientX > r.left && - e.clientX < r.right && - e.clientY > r.top && - e.clientY < r.bottom - ); +// import { Meteor } from 'meteor/meteor'; +// import React, {useState, useEffect, Suspense} from 'react'; +// import { useTracker, useFind } from 'meteor/react-meteor-data/suspense'; + +// import { FilesCol } from '/imports/api/files.js'; +import { useNavigate, Link } from 'react-router-dom'; + +// import { Roles } from 'meteor/roles'; +// import { useUserContext } from '/imports/api/contexts/AppContext'; +// import { groupBy } from 'lodash'; + +//import Radium from 'radium'; + + +// const IndicadorMissatges = ({notif}) => { +// return +// {notif && } +// +// ; +// }; + +const U = ({u, esAdministrador}) => { + + // const [esAdministrador, setEsAdministrador] = useState(false); + +// const u = useTracker("user", async () => await Meteor.userAsync()); +// const userId = Meteor.userId(); + + + // useEffect(() => { + // (async () => { + // const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]); + // setEsAdministrador(comprovaAdmin); + // })(); + // }, [Meteor.userId()]); + + // const u = useUserContext(); + + + // console.log("UUU: ", u); + + const navigate = useNavigate(); + // const files = useTracker(() => { + // const filesHandle = Meteor.subscribe('files.avatar'); + // // const docsReadyYet = filesHandle.ready(); + // const files = FilesCol?.find({"meta.userId": Meteor.userId()}, {sort: {name: 1}}).fetch(); // Meteor.userId() ?? "nop" + + // return files; + // }); + +// const uname = useTracker(() => Meteor.user({ fields: { 'username': 1 } })?.username ); + +// const [mostraMenu, setMostraMenu] = useState(false); + + //const avatarLink = u.avatarLink; + + // alert("avLnk: ", u.profile.avatarLink); + + return +
{ + // setMostraMenu(true); + // }} + + // title="Logout" + + onClick={ev => { + ev.stopPropagation(); + ev.preventDefault(); + + // console.log("u: ", u); + + navigate(`/${u.username}`); + + }} + > + { (u && esAdministrador) &&
ADMIN
} + + + {u?.username} + + { + ev.preventDefault(); + ev.stopPropagation(); + + alert("Click en missatges"); + }} + > + {/* */} + +
+ { + // mostraMenu && + //
{ + // // setMostraMenu(false); + // // }} + // > + // {/* */} + //
{ + // //setEditaPerfil(true); + // ev.stopPropagation(); + // ev.preventDefault(); + + // navigate(`/c/config`); + + // }} + // >Configuración
+ // {/* */} + + //
{ + // Meteor.logout(err => { + // err && alert(`Problema: ${err}`); + // }); + // navigate(`/`); + // }} + // >Cierra la sesión
+ //
+ } +

+
; }; -const AssignadorDeRols = ({pobles, ambitGeneral, esEditor, rols, usrSeleccionat}) => { - const [creantRol, setCreantRol] = useState(false); - const [ambitsUSel, setAmbitsUSel] = useState([]); - - useEffect(() => { - (async () => { - const ambits = await Roles.getScopesForUserAsync(usrSeleccionat?._id); - setAmbitsUSel(ambits); - })(); - }, []); - - return
-

Rols

- -

Àmbits

-
General:
-
    { - rols?.map(uRol =>
  • - {uRol} - {esEditor && } -
  • ) - }
- - {/*
    */} - { - ambitsUSel?.map(async aus => { - - const uRol = await Roles.getRolesForUserAsync(usrSeleccionat._id, {scope: aus, onlyScoped: true}); - return <> -
    {aus}:
    - { - {uRol} - {esEditor && } - - }
    - ; - }) - } - {/*
*/} - - {esEditor && creantRol &&
-
{ - Meteor.callAsync('assignaRol', usrSeleccionat._id, d.get('selRol'), d.get('selAmbit')); - }}> - - Àmbit:
- - Rol:

- - - -
-
} - - {esEditor && usrSeleccionat && } -
; -}; export const Usuaris = () => { - const refQuadreSeleccionat = useRef(); + const [usrSeleccionat, setUsrSeleccionat] = useState(null); - useSubscribe('pobles'); const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync()); @@ -162,17 +213,10 @@ export const Usuaris = () => { const usuaris = useTracker("usuaris", () => { Meteor.subscribe('usuaris'); - return Meteor.users.find().fetch()//.filter(u => u._id !== Meteor.userId()); + return Meteor.users.find().fetch();//.filter(u => u._id !== Meteor.userId()); }); - - const rols = useTracker("rols", async () => { - return await Roles.getRolesForUserAsync(usrSeleccionat?._id); - }); - - // console.log("rols: ", rols); - // console.log("isAdmin: ", isAdmin) ; - // console.log("usuaris: ", usuaris); + console.log("usuaris: ", usuaris); // (async () => { useEffect(() => { (async () => { @@ -183,34 +227,15 @@ export const Usuaris = () => { }, []); // })(); - const QuadreInfo_Usuari = () => { - - // const [rols, setRols] = useState([]); - - const [ambitGeneral, setAmbitGeneral] = useState(false); - - - let allScopes; - - // useEffect( async () => { - // allScopes = await Roles.getScopesForUserAsync(usrSeleccionat?._id); - // // Roles.getRolesForUser(usrSeleccionat?._id).map(uRol =>
  • {uRol}
  • ); - - // // setRols(rols); - // }); - - return
    + display: `inline-block`, + border: `1px solid #6666`, + padding: `.5rem`, + borderRadius: `.3em`, + backgroundColor: `lightcyan` + }}> {usrSeleccionat &&

    {usrSeleccionat._id}

    } @@ -233,55 +258,48 @@ export const Usuaris = () => { >

    - - - +
    + - - { esEditor && } -
    ; }; - return
    { - !isClickInsideRectangle(ev, refQuadreSeleccionat.current) && setUsrSeleccionat(null); - }}>Carregant...} > - + return Carregant...} >

    Usuaris

    - { esEditor && usrSeleccionat && } + { esEditor && }
      { usuaris .sort((a,b) => a.username?.toLowerCase() > b.username?.toLowerCase()) .map(usr =>
    • - {usr.username}{esEditor && }
    • ) + {/* {usr.username}{esEditor && } */} + + ) }
    - - {esEditor && !usrSeleccionat && } - -
    ; + ; }; \ No newline at end of file