Skip to content

Instantly share code, notes, and snippets.

@eightyfive
Last active March 2, 2021 20:08
Show Gist options
  • Save eightyfive/3260c0acc80ad39e77b0884ea321dfe5 to your computer and use it in GitHub Desktop.
Save eightyfive/3260c0acc80ad39e77b0884ea321dfe5 to your computer and use it in GitHub Desktop.
RNNA App
import { Platform } from 'react-native';
import Env from '../env';
export default {
url: `${Env.APP_URL}/${Env.API_PREFIX}`,
options: {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-Platform': Platform.OS,
},
},
};
// import { schema } from 'normalizr';
// const user = new schema.Entity('users');
export default {
// users: user,
};
import { Platform } from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
const isAndroid = Platform.OS === 'android';
const config = {
middlewares: [],
persist: {
key: 'root',
storage: AsyncStorage,
// whitelist: [],
},
};
if (__DEV__) {
// Redux Flipper
const createDebugger = require('redux-flipper').default;
config.middlewares.push(createDebugger());
// AsyncStorage Flipper
const asyncStorageFlipper = require('rn-async-storage-flipper').default;
asyncStorageFlipper(AsyncStorage);
if (isAndroid) {
// https://github.com/facebook/react-native/issues/14101
// https://github.com/rt2zz/redux-persist/issues/717#issuecomment-437589374
config.persist.timeout = 0;
}
}
export default config;
export default Object.assign(
{
APP_URL: 'https://example.org',
API_PREFIX: 'api',
},
__DEV__ && {
APP_URL: 'http://127.0.0.1:8000',
},
);
import { onAction } from 'rnna/events';
export default function onAction(({ type, payload }, state, services) => {
switch (type) {
default:
break;
}
});
import onBoot from 'rnna/events/boot';
export default onBoot((state, services) => {
//
});
import api from './api';
import boot from './boot';
import register from './register';
export default [
register,
boot,
api,
];
import onRegister from 'rnna/events/register';
export default onRegister((services) => {
//
});
import createStore from 'rnna/store';
import epics from './events';
import reducers from './state';
import * as services from './services';
import storeConfig from './config/store';
const store = createStore({ ...storeConfig, epics, reducers }, services);
// Boot services
services.router.addGlobalProp('dispatch', store.dispatch);
export default {
boot() {
return store.hydrate();
}
};
import View from '../views/scenes/home';
View.options = {};
View.controller = (state, services) => {
return {};
};
export default View;
// import Login from './login';
import Home from './home';
export default {
// auth: {
// Login,
// },
main: {
Home,
},
};
import createApi from 'rnna/services/api';
import apiConfig from '../config/api';
export default createApi(apiConfig);
import createDb, { createSelector } from 'rnna/services/db';
import dbConfig from '../config/db';
const db = createDb(dbConfig);
// db.isGuest = createSelector('session.token', (token) => !token);
export default db;
export { default as api } from api;
export { default as db } from db;
export { default as router } from router;
import { createRouter } from 'rnna/services';
import db from './db';
import routes from '../routes';
export default createRouter(routes, { db });
import { createReducer, produceTables, produceTableOrder } from 'rnna/services/state';
const initialState = {
tables: {},
orders: {},
};
export default createReducer((draft, { type, payload = {}, meta }) => {
const { entities, result } = payload;
if (entities) {
produceTables(draft.tables, entities);
}
if (Array.isArray(result)) {
produceTableOrder(draft.orders, type, result);
}
}, initialState);
export default {
//
};
import React from 'react';
import { Text } from 'react-native';
import { Screen } from 'rnna/views';
export default class Home extends Screen {
static displayName = 'Home';
render() {
return <Text>Home</Text>;
}
}
// Colors
https://www.materialpalette.com/indigo/red
const primary = '#3F51B5';
const primaryDark = '#303F9F';
const primaryLight = '#C5CAE9';
const accent = '#FF5252';
const black = '#212121';
const white = '#FFFFFF';
const grey = '#757575';
const greyLight = '#BDBDBD';
export const colors = {
primary,
primaryVariant: primaryDark,
accent,
background: primary,
surface: white,
error: 'red',
text: black,
textSecondary: grey,
divider: greyLight,
on: {
primary: white,
accent: white,
background: white,
surface: black,
error: white,
},
};
export const roundness = 15;
export default {
colors,
roundness: 10,
};
import app from './app/register';
app.boot();
{
"keywords": ["rnna", "react-native", "react-native-navigation"],
"dependencies": [
"@react-native-community/async-storage",
"color",
"date-fns",
"react-native-flipper"
],
"devDependencies": [
"redux-flipper",
"rn-async-storage-flipper"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment