From d6e1329d798c865fc355a3d60b9e65109213f507 Mon Sep 17 00:00:00 2001 From: Pasq G Date: Tue, 7 Jan 2025 12:08:38 +0100 Subject: [PATCH] codis_0 --- imports/ui/Codis.jsx | 250 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 imports/ui/Codis.jsx diff --git a/imports/ui/Codis.jsx b/imports/ui/Codis.jsx new file mode 100644 index 0000000..b22ce5f --- /dev/null +++ b/imports/ui/Codis.jsx @@ -0,0 +1,250 @@ +import React, { Suspense, useEffect, useState, useRef, lazy } from 'react'; +import { Meteor } from 'meteor/meteor';; +import { NecessitatsCollection } from '/imports/api/necessitats.js'; +import { PoblesCollection } from '../api/pobles'; +import { TipusCollection } from '../api/tipus'; +import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/suspense'; +import { Roles } from 'meteor/roles'; +// import { useUserId } from 'meteor/react-meteor-accounts'; +import Select from 'react-select'; + +import CreatableSelect from 'react-select/creatable'; +import AsyncCreatableSelect from 'react-select/async-creatable'; +import { BarraNav } from "./BarraNav/BarraNav"; + + + + +export const Codis = () => { + + // const [permes, setPermes] = useState(false); + const [esEditor, setEsEditor] = useState(false); + const userId = Meteor.userId(); + + useEffect(() => { + (async () => { + const comprovaAdmin = await Roles.userIsInRoleAsync(userId, ["admin"]); + setEsEditor(comprovaAdmin); + })(); + }, []); + + // console.log("isAdmin: ", isAdmin) ; + + let ambitSeleccionat = null; + + useSubscribe('necessitats'); + const necessitats = useTracker("necessitats", () => NecessitatsCollection.find().fetchAsync()); + + useSubscribe('pobles'); + const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync()); + const ambits = pobles?.map(p => p?.ambitAssociat); + + // console.log("ambits: ", ambits); + + // useSubscribe('tipus'); + // const ambits = useTracker("ambits", () => Collection.find().fetchAsync()); + + // console.log("tipus: ", tipus); + // console.log("necessitats: ", necessitats); + + // console.log("tipusSeleccionat: ", tipusSeleccionat); + + + // const filterAmbit = (inputValue) => { + // return ambits.filter((i) => + // i.toLowerCase().includes(inputValue.toLowerCase()) + // ); + // }; + + const SelectorDeRol = ({ambitSeleccionat}) => { + return <> + + "Crear nou tipus..."} + // filterOption={filterAmbit} + options={ + [... + ambits + .map((v,i) => ({ + value: v, + label: v + })) + .sort((a,b) => a.label.toLowerCase() > b.label.toLowerCase()), + { + value: "GENERAL", + label: "GENERAL" + } + ] + } + // onCreateOption={(inputValue) => Meteor.callAsync('afigT', {titol: inputValue})} + isSearchable + // loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))} + onChange={ev => { + ambitSeleccionat = ev.value; + console.log("ambitSeleccionat: ", ambitSeleccionat); + + }} + /> + + {/* */} + +
+ + + +
+ + + + +

+ + + + ({value: v._id, label: v.nomPoble})) } /> + {/* */} + +
+ + + + {ambitSeleccionat && esEditor && } + + ; + }; + + + return Carregant...} > + + + +

+ + {/* ({value: v, label: v.titol})) } + loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))} + /> */} + + {/* */} + + +
    { + ambits + .sort((a,b) => a.toLowerCase() > b.toLowerCase()) + .map(amb =>
  • + {amb}{esEditor && } +
  • ) + }
+
; +}; \ No newline at end of file