This commit is contained in:
Pasq G 2024-11-21 14:00:52 +01:00
parent 8aa0cd77f9
commit 4030d27a09
4 changed files with 205 additions and 26 deletions

View File

@ -1,3 +0,0 @@
import { Mongo } from 'meteor/mongo';
export const LinksCollection = new Mongo.Collection('links');

3
imports/api/pobles.js Normal file
View File

@ -0,0 +1,3 @@
import { Mongo } from 'meteor/mongo';
export const PoblesCollection = new Mongo.Collection('pobles');

View File

@ -1,17 +1,52 @@
import React from 'react'; import React, { Suspense } from 'react';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { BrowserRouter, Routes, Route, Link } from 'react-router-dom'; import { BrowserRouter, Routes, Route, Link } from 'react-router-dom';
import { Login } from './Login'; import { Login } from './Login';
import { useUserId } from 'meteor/react-meteor-accounts'; import { useUserId } from 'meteor/react-meteor-accounts';
import { PoblesCollection } from '/imports/api/pobles.js';
import { useSubscribe, useTracker, useFind } from 'meteor/react-meteor-data/suspense';
const AfegirPoblacio = () => {
useSubscribe('pobles');
const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync());
return <Suspense fallback={<>Carregant...</>} >
<form action={d => {
Meteor.callAsync('user.addToDataDay',
{
date: new Date(),
memo: d.get('memo'),
longmemo: d.get('longmemo')
}
).catch(err => console.error(err))
}}>
<label htmlFor="nomPoblacio">Població: </label><input name="nomPoblacio" type="text" /><br />
<label htmlFor="comarca">Comarca: </label><input name="comarca" type="text" /><br />
<label htmlFor="cp">Codi Postal: </label><input name="cp" type="text" /><br />
<button type='submit'>Crear la Població</button>
</form>
<ul>{
pobles
.sort((a,b) => a.nomPoble > b.nomPoble)
.map(pob => <li key={`pob_${pob._id}`}>{pob.nomPoble}</li>)
}</ul>
</Suspense>;
};
const Loguejat = () => { const Loguejat = () => {
const userId = useUserId(); const userId = useUserId();
// const user = await Meteor.userAsync(); // const user = await Meteor.userAsync();
return userId ? <div> return userId ? <div>
<Link to="/afegir_poblacio" >Afegir Població</Link>
<button onClick={() => Meteor.logout()} >Logout</button> <button onClick={() => Meteor.logout()} >Logout</button>
<p>- 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 </p> <p>- 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 </p>
<p>- estat: impossible de trobar / disponible / pendent / enviada / ha arribat (que cada poble puga tocar aquestes opcions dels subministres per al seu poble)</p> <p>- estat: impossible de trobar / disponible / pendent / enviada / ha arribat (que cada poble puga tocar aquestes opcions dels subministres per al seu poble)</p>
<p>- tipus de subministre: maquinària / menjar i beguda / productes infantils / higiene i neteja / sanitari / roba i calçat / ferramentes / necessitats especials / EPIs / electrònica / per a animals / roba de llit, mantes, cortines i mantells / vaixella i utensilis de cuina / papereria i material escolar / mobiliari i electrodomèstics /altres</p> <p>- tipus de subministre: maquinària / menjar i beguda / productes infantils / higiene i neteja / sanitari / roba i calçat / ferramentes / necessitats especials / EPIs / electrònica / per a animals / roba de llit, mantes, cortines i mantells / vaixella i utensilis de cuina / papereria i material escolar / mobiliari i electrodomèstics /altres</p>
@ -45,6 +80,7 @@ export const App = () => (
<BrowserRouter> <BrowserRouter>
<Routes> <Routes>
<Route path="/" element={ <Loguejat /> } /> <Route path="/" element={ <Loguejat /> } />
<Route path="/afegir_poblacio" element={ <AfegirPoblacio /> } />
<Route path="/login" element={ <Login /> } /> <Route path="/login" element={ <Login /> } />
</Routes> </Routes>
</BrowserRouter> </BrowserRouter>

View File

@ -1,37 +1,180 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { LinksCollection } from '/imports/api/links'; import { PoblesCollection } from '/imports/api/pobles.js';
async function insertLink({ title, url }) { async function insertPoble({ nomPoble, cp, comarca }) {
await LinksCollection.insertAsync({ title, url, createdAt: new Date() }); await PoblesCollection.insertAsync({ nomPoble, cp, comarca, createdAt: new Date() });
} }
Meteor.startup(async () => { Meteor.startup(async () => {
// If the Links collection is empty, add some data. // If the Pobles collection is empty, add some data.
if (await LinksCollection.find().countAsync() === 0) { if (await PoblesCollection.find().countAsync() === 0) {
await insertLink({ await insertPoble({
title: 'Do the Tutorial', nomPoble: "Alaquàs",
url: 'https://www.meteor.com/tutorials/react/creating-an-app', cp: "",
comarca: ""
}); });
await insertLink({ await insertPoble({
title: 'Follow the Guide', nomPoble: "Albal",
url: 'https://guide.meteor.com', cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Aldaia",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Alfafar",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Algemesí",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Alginet",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Alcàsser",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Benetússer",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Beniparrell",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Carlet",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Catarroja",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Dosaigües",
cp: "",
comarca: ""
}); });
await insertLink({ await insertPoble({
title: 'Read the Docs', nomPoble: "Godelleta",
url: 'https://docs.meteor.com', cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Guadassuar",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Iàtova",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "L'Alcúdia",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Llocnou de la Corona",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Massanassa",
cp: "",
comarca: ""
}); });
await insertLink({
title: 'Discussions',
url: 'https://forums.meteor.com', await insertPoble({
nomPoble: "Paiporta",
cp: "",
comarca: ""
}); });
await insertPoble({
nomPoble: "Parke Alkosa",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Picanya",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Sedaví",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Setaigües",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Utiel",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "València-Castellar Oliveral",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "València-Forn d'Alcedo",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "València-La Torre",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Xest",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Xiva",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Llombai",
cp: "",
comarca: ""
});
await insertPoble({
nomPoble: "Tremolar",
cp: "",
comarca: ""
});
} }
// We publish the entire Links collection to all clients. // We publish the entire Pobles collection to all clients.
// In order to be fetched in real-time to the clients // In order to be fetched in real-time to the clients
Meteor.publish("links", function () { Meteor.publish("pobles", function () {
return LinksCollection.find(); return PoblesCollection.find();
}); });
}); });