Skip to content

Instantly share code, notes, and snippets.

View divyanshu013's full-sized avatar
:shipit:
Ship it

Divyanshu Maithani divyanshu013

:shipit:
Ship it
View GitHub Profile
@divyanshu013
divyanshu013 / TodosContainer.js
Created February 19, 2018 14:07
Updating onAllData to stream results
import Utils from '../utils';
...
export default class TodosContainer extends React.Component {
...
onAllData = (todos, streamData) => {
// merge streaming todos data along with current todos
const todosData = Utils.mergeTodos(todos, streamData);
// filter data based on "screen": [All | Active | Completed]
@divyanshu013
divyanshu013 / TodoItem.js
Last active February 19, 2018 13:37
Adding a TodoItem component
class TodoItem extends Component {
onTodoItemToggle = (todo, propAction) => {
propAction({
...todo,
completed: !todo.completed,
});
};
render() {
const { todo, onUpdate, onDelete } = this.props;
@divyanshu013
divyanshu013 / TodosContainer.js
Created February 19, 2018 13:25
Rendering a FlatList from ReactiveList
...
import { ScrollView, StyleSheet, StatusBar, FlatList, Text } from 'react-native';
import CONSTANTS from '../constants';
...
export default class TodosContainer extends React.Component {
...
onAllData = (todos, streamData) => {
// filter data based on "screen": [All | Active | Completed]
const filteredData = this.filterTodosData(todos);
@divyanshu013
divyanshu013 / TodosContainer.js
Created February 19, 2018 13:13
Adding ReactiveList in TodosContainer
...
import { ReactiveList } from '@appbaseio/reactivesearch-native';
...
export default class TodosContainer extends React.Component {
render() {
return (
<View style={styles.container}>
<Header />
@divyanshu013
divyanshu013 / TodosContainer.js
Last active February 19, 2018 12:28
Adding AddTodo component
...
import AddTodoButton from './AddTodoButton';
import AddTodo from './AddTodo';
import TodoModel from '../api/todos';
...
// will render todos based on the active screen: all, active or completed
export default class TodosContainer extends React.Component {
state = {
addingTodo: false,
@divyanshu013
divyanshu013 / AddTodo.js
Created February 19, 2018 11:20
Component for showing add todo input
class AddTodo extends Component {
constructor(props) {
super(props);
const { title, completed, createdAt } = this.props.todo;
this.state = {
title,
completed,
createdAt,
};
}
@divyanshu013
divyanshu013 / AddTodoButton.js
Created February 19, 2018 11:05
Adding floating button for adding Todos
const AddTodoButton = ({ onPress }) => (
<Fab
direction="up"
containerStyle={{}}
style={{ backgroundColor: COLORS.primary }}
position="bottomRight"
onPress={onPress}
>
<Icon name="add" />
</Fab>
@divyanshu013
divyanshu013 / MainTabNavigator.js
Created February 19, 2018 08:42
The main tab navigation logic for todos-native app
import React from 'react';
import { MaterialIcons } from '@expo/vector-icons';
import { TabNavigator, TabBarBottom } from 'react-navigation';
import Colors from '../constants/Colors';
import CONSTANTS from '../constants';
import TodosScreen from '../screens/TodosScreen';
const commonNavigationOptions = ({ navigation }) => ({
header: null,
@divyanshu013
divyanshu013 / App_init.js
Last active February 14, 2018 14:01
Initial version of App.js for todos-native-auth app
import Expo from 'expo';
import React from 'react';
import { StatusBar, View, Platform, Text, StyleSheet } from 'react-native';
import { Container, Spinner } from 'native-base';
import { ReactiveBase } from '@appbaseio/reactivesearch-native';
import { appname, type, credentialsWrite, colors } from './utils/constants';
export default class App extends React.Component {
state = {
@divyanshu013
divyanshu013 / constants.js
Last active February 14, 2018 12:36
Constants for Todos Native Auth app
export const appname = 'todomvc-auth'; // Elasticsearch index
export const credentialsRead = 'pVPf3rRLj:61fd73c0-3660-44db-8309-77d9d35d64cc';
export const credentialsWrite = 'QiqJNlwfU:41a45e61-f761-44fe-947a-6f47de32ae0a';
export const type = 'todo_reactjs'; // Elasticsearch type
export const url = 'https://scalr.api.appbase.io'; // Elasticsearch cluster
// Some nice colors I'm using in the app
const tintColor = '#2f95dc';
export const colors = {