Skip to content

Commit

Permalink
Move around the very basic components
Browse files Browse the repository at this point in the history
  • Loading branch information
sroze committed Jul 20, 2018
1 parent 99af734 commit 578982b
Show file tree
Hide file tree
Showing 24 changed files with 98 additions and 20 deletions.
38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
# React Native Standards
<p align="center"><a href="https://github.com/kametventures/galette" target="_blank">
<img src="./assets/galette.png" height="50">
</a></p>

A set of tools, components and screens that should not be re-written every single time. Built on the shoulders of React & Redux,
these standards will get you up and running very fast.
# Galette

## Standards
Galette is a set of tools, components and screens to be re-used within your applications. Built on the shoulders of
React & Redux, these modules will get you up and running very fast.

- Collection
- Empty State
## Modules

## Specifics
These modules are generic modules to be used both for React and React Native. Checkout bellow for React and React Native
specific components that work well with these modules.

- Infinite-Scroll-View
- [**Store**](./modules/store)<br>
Reducers, selectors and helpers to store your collections and items in your Redux store.

- [**Hydra**](./modules/hydra)<br>
Super-set of Store, adding specifics for Hydra APIs.

- [**ram** (redux-api-middleware)](./modules/redux-api-middleware)<br>
Superset of Store, adding specifics for redux-api-middleware.

## React Web

- [**TokenWall**](./web/token-wall)<br>
Adding a simple token wall for your early prototype.

## React Native

- [**InfiniteScrollView**](./native/infinite-scroll-view)<br>
An easy to use infinite scroll view for your paginated collections.

- [**EmptyState**](./native/empty-state)<br>
Set of screens to be used when nothing has been found.
Binary file added assets/galette.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions collection/README.md

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions collection/Collection.js → modules/store/Collection.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ListView } from "react-native";

export default class Collection
{
constructor(list, itemsKey = 'items') {
Expand All @@ -25,13 +23,6 @@ export default class Collection
});
}

dataSource() {
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2})
let items = this.items();

return ds.cloneWithRows(items);
}

hasError() {
return !!this.list.error;
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions native/collection/NativeCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ListView } from "react-native";

export class NativeCollection extends Collection
{
dataSource() {
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2})
let items = this.items();

return ds.cloneWithRows(items);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "@galette/galette",
"require": {
"react-native-elements": "^0.18.4"
}
Expand Down
26 changes: 26 additions & 0 deletions web/token-wall/components/TokenEnforcementWall.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as React from 'react'
import {Component} from "react";
import {getToken} from "../token";

export default class TokenEnforcementWall extends Component {
render() {
if (getToken()) {
return this.props.children;
}

return (
<div>
<h1>You need to be authenticated.</h1>
<form method="get">
<p>
<label>Token</label>
<input type="text" name="access_token"/>
</p>
<p>
<button type="submit">Login</button>
</p>
</form>
</div>
)
}
}
30 changes: 30 additions & 0 deletions web/token-wall/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const getParams = query => {
if (!query) {
return {};
}

return (/^[?#]/.test(query) ? query.slice(1) : query)
.split('&')
.reduce((params, param) => {
let [key, value] = param.split('=');
params[key] = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : '';
return params;
}, {});
};

export const getToken = (): string => {
let token: string = localStorage.getItem('token');
if (token) {
return token;
}

token = getParams(document.location.search).access_token;
if (token) {
localStorage.setItem('token', token);

// Refresh so that it looses the token
window.location.href = window.location.origin;
}

return token;
}

0 comments on commit 578982b

Please sign in to comment.