From 4b577f90940c9ddac2d6ae101af81a5060bc37d1 Mon Sep 17 00:00:00 2001 From: Pasq G Date: Fri, 22 Nov 2024 13:45:03 +0100 Subject: [PATCH] Millorant pobles --- imports/ui/App.jsx | 36 +++++++++++++++++++++--------------- server/main.js | 2 +- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/imports/ui/App.jsx b/imports/ui/App.jsx index 7c61d62..3ad9b1f 100644 --- a/imports/ui/App.jsx +++ b/imports/ui/App.jsx @@ -1,4 +1,4 @@ -import React, { Suspense } from 'react'; +import React, { Suspense, useEffect, useState, useRef } from 'react'; import { Meteor } from 'meteor/meteor'; import { BrowserRouter, Routes, Route, Link } from 'react-router-dom'; import { Login } from './Login'; @@ -7,50 +7,56 @@ import { PoblesCollection } from '/imports/api/pobles.js'; import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/suspense'; -const AfegirPoblacio = () => { - useSubscribe('pobles'); +const Pobles = () => { + const [pobleSeleccionat, setPobleSeleccionat] = useState(null); + useSubscribe('pobles'); const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync()); - return Carregant...} > -
{ + const QuadreInfo_Poble = () => { + + return <> +

{pobleSeleccionat._id}

+ { try { - Meteor.callAsync('afigPoble', + Meteor.callAsync('editaOAfigPoble', { createdAt: new Date(), nomPoble: d.get('nomPoble'), cp: d.get('cp') || "", comarca: d.get('comarca') || "", - } + }, pobleSeleccionat ).catch(err => console.error(err)); } catch (err) { alert(err); console.error(err); } - }}> -
+


-
+ ; + }; + + return Carregant...} > + {pobleSeleccionat && }
    { pobles .sort((a,b) => a.nomPoble.toLowerCase() > b.nomPoble.toLowerCase()) - .map(pob =>
  • {pob.nomPoble}
  • ) + .map(pob =>
  • {pob.nomPoble}
  • ) }
; }; const Loguejat = () => { + const userId = useUserId(); - // const user = await Meteor.userAsync(); - return userId ?
- Afegir Població + Pobles @@ -87,7 +93,7 @@ export const App = () => ( } /> - } /> + } /> } /> diff --git a/server/main.js b/server/main.js index b79a9e1..eb029eb 100644 --- a/server/main.js +++ b/server/main.js @@ -182,7 +182,7 @@ Meteor.startup(async () => { Meteor.methods({ - 'afigPoble': async function (poble) { + 'editaOAfigPoble': async function (poble) { try { if (poble.nomPoble) { return await PoblesCollection.insertAsync({