Meteor + Remote DB connection finally working with publish/subscribe methods.
This commit is contained in:
parent
829769501c
commit
42ab3f317d
@ -18,6 +18,5 @@ ecmascript@0.14.3 # Enable ECMAScript2015+ syntax in app code
|
|||||||
typescript@3.7.6 # Enable TypeScript syntax in .ts and .tsx modules
|
typescript@3.7.6 # Enable TypeScript syntax in .ts and .tsx modules
|
||||||
shell-server@0.5.0 # Server-side component of the `meteor shell` command
|
shell-server@0.5.0 # Server-side component of the `meteor shell` command
|
||||||
|
|
||||||
autopublish@1.0.7 # Publish all data to the clients (for prototyping)
|
|
||||||
insecure@1.0.7 # Allow all DB writes from clients (for prototyping)
|
insecure@1.0.7 # Allow all DB writes from clients (for prototyping)
|
||||||
static-html
|
static-html
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
allow-deny@1.1.0
|
allow-deny@1.1.0
|
||||||
autopublish@1.0.7
|
|
||||||
autoupdate@1.6.0
|
autoupdate@1.6.0
|
||||||
babel-compiler@7.5.3
|
babel-compiler@7.5.3
|
||||||
babel-runtime@1.5.0
|
babel-runtime@1.5.0
|
||||||
|
|||||||
@ -4,6 +4,20 @@ import ReactDOM from 'react-dom';
|
|||||||
import App from '../imports/ui/App';
|
import App from '../imports/ui/App';
|
||||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||||
|
|
||||||
|
export const PlantTypesCollection = new Meteor.Collection('plantTypes');
|
||||||
|
|
||||||
Meteor.startup(() => {
|
Meteor.startup(() => {
|
||||||
ReactDOM.render(<App />, document.getElementById('root'));
|
if(Meteor.isServer) {
|
||||||
});
|
Meteor.publish('plantTypesCollection', function() {
|
||||||
|
return PlantTypesCollection.find();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Meteor.isClient) {
|
||||||
|
Meteor.subscribe('plantTypesCollection');
|
||||||
|
}
|
||||||
|
|
||||||
|
Meteor.setTimeout(function() {
|
||||||
|
ReactDOM.render(<App />, document.getElementById('root'));
|
||||||
|
}, 500);
|
||||||
|
});
|
||||||
@ -1,37 +1,13 @@
|
|||||||
import { Meteor } from 'meteor/meteor';
|
import {PlantTypesCollection} from '../../client/main'
|
||||||
|
|
||||||
const PlantTypesCollection = new Meteor.Collection('plantTypes');
|
export function getAllPlantTypes() {
|
||||||
|
const plantTypesDocuments = PlantTypesCollection.find();
|
||||||
|
|
||||||
var plantTypesDocuments = PlantTypesCollection.find();
|
var plantTypes = [];
|
||||||
|
|
||||||
export var plantTypes = [];
|
plantTypesDocuments.forEach((plantType) => {
|
||||||
|
plantTypes.push(plantType.plantType);
|
||||||
plantTypesDocuments.forEach((plantType) => {
|
|
||||||
plantTypes.push(plantType.plantType);
|
|
||||||
});
|
|
||||||
|
|
||||||
function createTypesString() {
|
|
||||||
var typesString = "";
|
|
||||||
var arrayLength = plantTypes.length;
|
|
||||||
var cnt = 1;
|
|
||||||
plantTypes.forEach((plantType) => {
|
|
||||||
if (cnt === arrayLength) {
|
|
||||||
typesString = typesString + plantType
|
|
||||||
} else {
|
|
||||||
typesString = typesString + plantType + ", "
|
|
||||||
}
|
|
||||||
cnt++;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return typesString;
|
return plantTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
var types = createTypesString();
|
|
||||||
|
|
||||||
console.log("TYPES: " + types);
|
|
||||||
|
|
||||||
//PlantTypesCollection.insert({plantType: "BAUM"});
|
|
||||||
|
|
||||||
//const plantTypeVegetables = PlantTypesCollection.findOne({dirtType: "Humus"});
|
|
||||||
//const plantTypeCacti = PlantTypesCollection.findOne({dirtType: "Sand"});
|
|
||||||
//const plantTypeFlowers = PlantTypesCollection.findOne({dirtType: "Loam"});
|
|
||||||
@ -1,10 +1,10 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { Container, Row, Col} from 'react-bootstrap';
|
import { Container, Row, Col} from 'react-bootstrap';
|
||||||
import { plantTypes } from '/imports/api/plantTypes';
|
|
||||||
|
|
||||||
import AddPlant from './AddPlant'
|
import AddPlant from './AddPlant'
|
||||||
import Plants from './Plants'
|
import Plants from './Plants'
|
||||||
import ActivatePlant from './ActivatePlant'
|
import ActivatePlant from './ActivatePlant'
|
||||||
|
import {getAllPlantTypes} from "../api/plantTypes";
|
||||||
|
|
||||||
class Settings extends React.Component{
|
class Settings extends React.Component{
|
||||||
|
|
||||||
@ -12,10 +12,18 @@ class Settings extends React.Component{
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
plants: [],
|
plants: [],
|
||||||
types: ['Chile', 'Mint'], // hardcoded for now
|
types: [],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
(async ()=>{
|
||||||
|
this.setState({
|
||||||
|
types: getAllPlantTypes(),
|
||||||
|
})
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
// pass this function to the addplant comp as a prop
|
// pass this function to the addplant comp as a prop
|
||||||
addPlant = (plant) => {
|
addPlant = (plant) => {
|
||||||
plant.id = this.state.plants.length + 1 // TODO rework
|
plant.id = this.state.plants.length + 1 // TODO rework
|
||||||
|
|||||||
@ -1,6 +1,15 @@
|
|||||||
import { Meteor } from 'meteor/meteor';
|
import { Meteor } from 'meteor/meteor';
|
||||||
import { PlantTypesCollection } from '/imports/api/plantTypes';
|
|
||||||
|
var PlantTypesCollection = new Meteor.Collection('plantTypes');
|
||||||
|
|
||||||
Meteor.startup(() => {
|
Meteor.startup(() => {
|
||||||
|
if(Meteor.isServer) {
|
||||||
|
Meteor.publish('plantTypesCollection', function() {
|
||||||
|
return PlantTypesCollection.find();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Meteor.isClient) {
|
||||||
|
Meteor.subscribe('plantTypesCollection');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
Loading…
Reference in New Issue
Block a user