diff --git a/imports/ui/App.jsx b/imports/ui/App.jsx index d1d8e40..e26b67c 100644 --- a/imports/ui/App.jsx +++ b/imports/ui/App.jsx @@ -7,6 +7,9 @@ import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/susp import { Pobles } from './Pobles'; import { Necessitats } from './Necessitats'; import { Tipus } from './Tipus'; +import { BarraNav } from './BarraNav/BarraNav'; + +import { UserStat } from './BarraNav/UserStat'; const Loguejat = lazy(async () => await import('/imports/ui/Loguejat.jsx')); @@ -17,6 +20,10 @@ export const App = () => { // const userId = await Meteor.userAsync(); return + + + + Carregant...}>{user ? : } } /> } /> diff --git a/imports/ui/BarraNav/BarraNav.jsx b/imports/ui/BarraNav/BarraNav.jsx new file mode 100644 index 0000000..dfd76af --- /dev/null +++ b/imports/ui/BarraNav/BarraNav.jsx @@ -0,0 +1,70 @@ +import React, {useState, useEffect} from "react"; +import { Link } from 'react-router-dom'; +import { Roles } from 'meteor/roles'; + +const BotóSecció = ({titol, linkto}) => { + return
+ {titol} +
; +}; + +const SeccióPobles = () => ; + +const SeccióNecessitats = () => ; + +const SeccióTipus = () => ; + +const SeccióUsuaris = () => ; + +const PanellSeccions = ({children}) => { + return <>
{children}
+
+ ; +}; + +const BarraNav = () => { + const [esAdministrador, setEsAdministrador] = useState(false); + const userId = Meteor.userId(); + + + useEffect(() => { + (async () => { + const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]); + setEsAdministrador(comprovaAdmin); + })(); + }, []); + + + return + { esAdministrador && } + + + + ; +}; + +export { BarraNav }; \ No newline at end of file diff --git a/imports/ui/BarraNav/UserStat.jsx b/imports/ui/BarraNav/UserStat.jsx new file mode 100644 index 0000000..3268988 --- /dev/null +++ b/imports/ui/BarraNav/UserStat.jsx @@ -0,0 +1,191 @@ +import { Meteor } from 'meteor/meteor'; +import React, {useState, useEffect} from 'react'; +import { useTracker } 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 UserStat = ({setEditaPerfil}) => { + + 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); + })(); +}, []); + + // 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}`); + + }} + > + { 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
+
+ } +

+ ; +}; + +export { UserStat }; \ No newline at end of file diff --git a/imports/ui/Loguejat.jsx b/imports/ui/Loguejat.jsx index 71de603..a6fb91d 100644 --- a/imports/ui/Loguejat.jsx +++ b/imports/ui/Loguejat.jsx @@ -2,47 +2,10 @@ import React from "react"; import { useUserId } from 'meteor/react-meteor-accounts'; import { Link } from 'react-router-dom'; // import { styled } from 'styled-components' +// import { BarraNav } from "./BarraNav/BarraNav"; // if (loguejat) - -const BotóSecció = ({titol, linkto}) => { - return
- {titol} -
; -}; - -const SeccióPobles = () => ; - -const SeccióNecessitats = () => ; - -const SeccióTipus = () => ; - -const PanellSeccions = ({children}) => { - return
{children}
; -}; - const Loguejat = () => { const userId = useUserId(); @@ -52,12 +15,7 @@ const Loguejat = () => {

- - - - - - + {/* */}

- poble (que cada poble només tinga accés a lo del seu poble, la resta de pobles no els han de poder tocar): Alaquàs / Albal / Aldaia / Alfafar / Algemesí / Alginet / Alcàsser / Benetússer / Beniparrell / Carlet / Catarroja / Dosaigües / Godelleta / Guadassuar / Iàtova / L'Alcúdia / Llocnou de la Corona / Massanassa / Paiporta / Parke Alkosa / Picanya / Sedaví / Setaigües / Utiel / València-Castellar Oliveral / València-Forn d'Alcedo / València-La Torre / Xest / Xiva / Llombai / Tremolar

- estat: impossible de trobar / disponible / pendent / enviada / ha arribat (que cada poble puga tocar aquestes opcions dels subministres per al seu poble)

diff --git a/imports/ui/Necessitats.jsx b/imports/ui/Necessitats.jsx index 2159cee..ad5b45f 100644 --- a/imports/ui/Necessitats.jsx +++ b/imports/ui/Necessitats.jsx @@ -10,6 +10,7 @@ import { Roles } from 'meteor/roles'; import CreatableSelect from 'react-select/creatable'; import AsyncCreatableSelect from 'react-select/async-creatable'; +import { BarraNav } from "./BarraNav/BarraNav"; @@ -50,10 +51,8 @@ export const Necessitats = () => { borderRadius: `.3em`, backgroundColor: `lightcyan` }}> - { esEditor &&
ADMINISTRADOR
} - {necessitatSeleccionada &&

{necessitatSeleccionada._id}

} + + {necessitatSeleccionada &&

{necessitatSeleccionada._id}

}

Necessitats

{ borderRadius: `.3em`, backgroundColor: `lightcyan` }}> - { esEditor &&
ADMINISTRADOR
} - {pobleSeleccionat &&

{pobleSeleccionat._id}

} + + {pobleSeleccionat &&

{pobleSeleccionat._id}

}

Pobles

{ - try { - Meteor.callAsync('editaOAfigPoble', - { - ...pobleSeleccionat || [], - nomPoble: d.get('nomPoble'), - cp: d.get('cp') || "", - comarca: d.get('comarca') || "", - }).then(() => setPobleSeleccionat(null)) - .catch(err => console.error(err)); - } catch (err) { - alert(err); - console.error(err); - } + try { + Meteor.callAsync('editaOAfigPoble', + { + ...pobleSeleccionat || [], + nomPoble: d.get('nomPoble'), + cp: d.get('cp') || "", + comarca: d.get('comarca') || "", + }).then(() => setPobleSeleccionat(null)) + .catch(err => console.error(err)); + } catch (err) { + alert(err); + console.error(err); + } }} >
diff --git a/imports/ui/Tipus.jsx b/imports/ui/Tipus.jsx index 78066ae..38d0df5 100644 --- a/imports/ui/Tipus.jsx +++ b/imports/ui/Tipus.jsx @@ -10,6 +10,7 @@ import Select from 'react-select'; import CreatableSelect from 'react-select/creatable'; import AsyncCreatableSelect from 'react-select/async-creatable'; +import { BarraNav } from "./BarraNav/BarraNav"; @@ -40,10 +41,17 @@ export const Tipus = () => { useSubscribe('tipus'); const tipus = useTracker("tipus", () => TipusCollection.find().fetchAsync()); - console.log("tipus: ", tipus); - console.log("necessitats: ", necessitats); + // console.log("tipus: ", tipus); + // console.log("necessitats: ", necessitats); - console.log("tipusSeleccionat: ", tipusSeleccionat); + // console.log("tipusSeleccionat: ", tipusSeleccionat); + + + const filterTipus = (inputValue) => { + return tipus.filter((i) => + i.titol.toLowerCase().includes(inputValue.toLowerCase()) + ); + }; const QuadreInfo_Tipus = () => { @@ -54,9 +62,7 @@ export const Tipus = () => { borderRadius: `.3em`, backgroundColor: `lightcyan` }}> - { esEditor &&
ADMINISTRADOR
} + {tipusSeleccionat &&

{tipusSeleccionat._id}

}

Tipus

@@ -87,11 +93,13 @@ export const Tipus = () => { si no tansols podrà assignar a un tipus predefinit o al de ALTRES */} + "Crear nou tipus..."} defaultOptions={tipus.map((v,i) => ({value: v._id, label: v.titol})).sort((a,b) => a.label.toLowerCase() > b.label.toLowerCase()) } onCreateOption={(inputValue) => Meteor.callAsync('afigTipus', {titol: inputValue})} + isSearchable // loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))} /> @@ -159,10 +167,27 @@ export const Tipus = () => { {/* */} - {/*
    { +
      { tipus - .sort((a,b) => a.nomPoble?.toLowerCase() > b.nomPoble?.toLowerCase()) - .map(pob =>
    • {pob.nomPoble}{esEditor && }
    • ) - }
    */} + .sort((a,b) => a.titol?.toLowerCase() > b.titol?.toLowerCase()) + .map(titol =>
  • + {titol.titol}{esEditor && }
  • ) + }
; }; \ No newline at end of file