Skip to content

Commit

Permalink
Updated example
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo mathieu committed Mar 20, 2016
1 parent a5bae25 commit d4cb79b
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 11 deletions.
5 changes: 4 additions & 1 deletion example/mobile/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export default class App extends Component {
};
}
componentWillMount() {
const url = 'http://'+(this.props.serverUrl || '127.0.0.1')+':3000/websocket';
console.info('------');
console.info('------');

const url = 'http://'+(this.props.serverUrl || '192.168.1.139')+':3000/websocket';
Meteor.connect(url);

Meteor.ddp.on('connected', function() {
Expand Down
21 changes: 21 additions & 0 deletions example/mobile/app/Routes/CollectionFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ console.disableYellowBox = true;
import React, {
Component,
StyleSheet,
Image,
Text,
View
} from 'react-native';
Expand All @@ -17,10 +18,30 @@ import Button from 'react-native-button';

@connectMeteor
export default class CollectionFS extends Component {
startMeteorSubscriptions() {
Meteor.subscribe('imagesFiles');
}
getMeteorData() {
return {
image: Meteor.FSCollection('imagesFiles').findOne()
}
}
render() {
const { image } = this.data;

console.log(image && image.url());
return (
<View style={styles.container}>
<Text>You have to be logged to see this image (see publish method). CollectionFS url() generate an authToken and it is checked in this example.</Text>

{image &&
<Image
style={{height: 400, width: 400}}
source={{uri: image.url({store: 'anotherStore'})}}
/>
}

<Image />
</View>
);
}
Expand Down
2 changes: 1 addition & 1 deletion example/mobile/app/Tabs.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class Tabs extends Component {
constructor(props) {
super(props);
this.state = {
selectedTab: 0
selectedTab: 1
};
}
selectTab(index) {
Expand Down
2 changes: 1 addition & 1 deletion example/mobile/ios/mobile/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
* on the same Wi-Fi network.
*/

jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
jsCodeLocation = [NSURL URLWithString:@"http://192.168.1.139:8081/index.ios.bundle?platform=ios&dev=true"];

/**
* OPTION 2
Expand Down
17 changes: 17 additions & 0 deletions example/web/app/collections/images_files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

const ImagesFiles = new FS.Collection("imagesFiles", {
stores: [
new FS.Store.GridFS("imagesFiles"),
new FS.Store.GridFS("anotherStore")
]
});

const allow = function(userId) {
return !!userId;
};

ImagesFiles.allow({
download: allow
});

export default ImagesFiles;
1 change: 1 addition & 0 deletions example/web/app/collections/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

export const Users = Meteor.users;
export const Todos = require('./todos');
export const ImagesFiles = require('./images_files');
export const Settings = new Mongo.Collection('settings');
3 changes: 3 additions & 0 deletions example/web/app/components/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default class Header extends Component {
<NavItem eventKey={1} onClick={()=>{browserHistory.push('/todos')}}>
Todos
</NavItem>
<NavItem eventKey={1} onClick={()=>{browserHistory.push('/image')}}>
CollectionFS
</NavItem>
</Nav>
</Navbar.Collapse>
</Navbar>
Expand Down
23 changes: 23 additions & 0 deletions example/web/app/components/Routes/ImageFile.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* global ReactMeteorData */
import React, {Component} from 'react';
import reactMixin from 'react-mixin';

import { ImagesFiles } from 'collections';

@reactMixin.decorate(ReactMeteorData)
export default class TodosComponent extends Component {
getMeteorData() {
return {
image: ImagesFiles.findOne()
};
}
render() {
const { image } = this.data;
console.log(image);
return (
<div>
<img src={image && image.url({store: 'anotherStore'})} alt=""/>
</div>
);
}
}
11 changes: 9 additions & 2 deletions example/web/app/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* global Accounts */

import { Settings, ImagesFiles } from 'collections';

export function createUsers() {
console.log('Creating fake users');
['User'].forEach(function(name) {
Expand All @@ -11,10 +13,15 @@ export function createUsers() {
});
}

import { Settings } from 'collections';

export function createSettings() {
Settings.insert({
param1: 'react-native-meteor'
});
}


export function createImages() {
const imageFile = new FS.File(Npm.require('fs').realpathSync(__meteor_bootstrap__.serverDir+'/../../../../../../app/opengraph.png'));
ImagesFiles.insert(imageFile);

}
4 changes: 3 additions & 1 deletion example/web/app/main_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { Router, Route, browserHistory } from 'react-router';
import App from './components/App.jsx';
import Home from './components/Routes/Home.jsx';
import Todos from './components/Routes/Todos.jsx';
import ImageFile from './components/Routes/ImageFile.jsx';

Accounts.ui.config({
passwordSignupFields: 'USERNAME_ONLY',
});

import publications from './publications/todos';
import publications from './publications';
publications();

Meteor.startup(() => {
Expand All @@ -20,6 +21,7 @@ Meteor.startup(() => {
<Router history={browserHistory}>
<Route path="/" component={Home}/>
<Route path="todos" component={Todos}/>
<Route path="image" component={ImageFile}/>
</Router>
</App>
), document.getElementById('root')
Expand Down
10 changes: 5 additions & 5 deletions example/web/app/main_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import React from 'react';
//import {Posts} from './collections';
//import {createPosts, createUsers} from './fixtures';
import './methods';
import { createUsers, createSettings } from './fixtures';
import { createUsers, createSettings, createImages } from './fixtures';

import todos from './publications/todos';
import settings from './publications/settings';
todos();
settings();
import publications from './publications';
publications();

if(Meteor.users.find().count()===0) {
createUsers();
createSettings();
createImages();
}


console.log('\n\nRunning on server only');;
Binary file added example/web/app/opengraph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions example/web/app/publications/imagesFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ImagesFiles } from '../collections';

export default function() {
if (Meteor.isClient) {
Meteor.subscribe('imagesFiles');
}

if (Meteor.isServer) {
Meteor.publish('imagesFiles', function() {
return ImagesFiles.find({});
});
}
};
9 changes: 9 additions & 0 deletions example/web/app/publications/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import imagesFiles from './imagesFiles';
import settings from './settings';
import todos from './todos';

export default function() {
imagesFiles();
todos();
settings();
};
2 changes: 2 additions & 0 deletions example/web/meteor_core/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ mindfront:why-reminify
aldeed:simple-schema
aldeed:collection2
reactjs:react
cfs:standard-packages
cfs:gridfs

0 comments on commit d4cb79b

Please sign in to comment.