added mockup users page and login page

This commit is contained in:
Maren Süwer
2018-07-02 16:05:58 +02:00
parent cdbdbf40ca
commit e087920ba5
7 changed files with 285 additions and 8 deletions

36
scm-ui/src/Login.js Normal file
View File

@@ -0,0 +1,36 @@
//@flow
import React from 'react';
import injectSheet from 'react-jss';
const styles = {
wrapper: {
width: '100%',
display: 'flex',
height: '10em'
},
loading: {
margin: 'auto',
textAlign: 'center'
}
};
type Props = {
classes: any;
}
class Login extends React.Component<Props> {
render() {
const { classes } = this.props;
return (
<div className={classes.wrapper}>
<div className={classes.loading}>
You need to log in! ...
</div>
</div>
);
}
}
export default injectSheet(styles)(Login);

View File

@@ -6,6 +6,7 @@ import classNames from 'classnames';
import { Route, withRouter } from 'react-router';
import Page from './containers/Page';
import Users from './containers/Users';
import {Switch} from 'react-router-dom';
const styles = {
@@ -25,7 +26,8 @@ class Main extends React.Component<Props> {
return (
<div className={classNames('container', classes.content)}>
<Switch>
<Route path="/:repository/:branch" component={Page} />
<Route exact path="/" component={Page} />
<Route exact path="/users" component={Users} />
</Switch>
</div>
);

View File

@@ -1,3 +1,63 @@
/**
* Created by masuewer on 02.07.18.
*/
// @flow
import React from 'react';
import { connect } from 'react-redux';
import { fetchRepositoriesIfNeeded } from '../modules/page';
import Login from '../Login';
type Props = {
loading: boolean,
error: any,
repositories: any,
fetchRepositoriesIfNeeded: () => void
}
class Page extends React.Component<Props> {
componentDidMount() {
this.props.fetchRepositoriesIfNeeded();
}
render() {
const { loading, error, repositories } = this.props;
if(loading) {
return (
<div>
<h1>SCM</h1>
<Login/>
</div>
);
}
else if(!loading){
return (
<div>
<h1>SCM</h1>
<h2>Startpage</h2>
<a href={"/users" }>
Users hier!
</a>
</div>
);
}
}
}
const mapStateToProps = (state) => {
return null;
};
const mapDispatchToProps = (dispatch) => {
return {
fetchRepositoriesIfNeeded: () => {
dispatch(fetchRepositoriesIfNeeded())
}
}
};
export default connect(mapStateToProps, mapDispatchToProps)(Page);

View File

@@ -0,0 +1,58 @@
// @flow
import React from 'react';
import { connect } from 'react-redux';
import { fetchRepositoriesIfNeeded } from '../modules/users';
import Login from '../Login';
type Props = {
loading: boolean,
error: any,
repositories: any,
fetchRepositoriesIfNeeded: () => void
}
class Users extends React.Component<Props> {
componentDidMount() {
this.props.fetchRepositoriesIfNeeded();
}
render() {
const { loading, error, repositories } = this.props;
if(loading) {
return (
<div>
<h1>SCM</h1>
<Login/>
</div>
);
}
else if(!loading){
return (
<div>
<h1>SCM</h1>
<h2>Users</h2>
</div>
);
}
}
}
const mapStateToProps = (state) => {
return null;
};
const mapDispatchToProps = (dispatch) => {
return {
fetchRepositoriesIfNeeded: () => {
dispatch(fetchRepositoriesIfNeeded())
}
}
};
export default connect(mapStateToProps, mapDispatchToProps)(Users);

View File

@@ -4,13 +4,15 @@ import { createStore, compose, applyMiddleware, combineReducers } from 'redux';
import { routerReducer, routerMiddleware } from 'react-router-redux';
import page from './modules/page';
import users from './modules/users';
function createReduxStore(history) {
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const reducer = combineReducers({
router: routerReducer,
page
page,
users
});
return createStore(

View File

@@ -1,3 +1,61 @@
/**
* Created by masuewer on 02.07.18.
*/
//@flow
const FETCH_REPOSITORIES = 'smeagol/repositories/FETCH';
const FETCH_REPOSITORIES_SUCCESS = 'smeagol/repositories/FETCH_SUCCESS';
const FETCH_REPOSITORIES_FAILURE = 'smeagol/repositories/FETCH_FAILURE';
const THRESHOLD_TIMESTAMP = 10000;
function requestRepositories() {
return {
type: FETCH_REPOSITORIES
};
}
function fetchRepositories() {
return function(dispatch) {
dispatch(requestRepositories());
return null;
}
}
export function shouldFetchRepositories(state: any): boolean {
const repositories = state.repositories;
return null;
}
export function fetchRepositoriesIfNeeded() {
return (dispatch, getState) => {
if (shouldFetchRepositories(getState())) {
dispatch(fetchRepositories());
}
}
}
export default function reducer(state = {}, action = {}) {
switch (action.type) {
case FETCH_REPOSITORIES:
return {
...state,
loading: true,
error: null
};
case FETCH_REPOSITORIES_SUCCESS:
return {
...state,
loading: true,
timestamp: action.timestamp,
error: null,
repositories: action.payload
};
case FETCH_REPOSITORIES_FAILURE:
return {
...state,
loading: true,
error: action.payload
};
default:
return state
}
}

View File

@@ -0,0 +1,61 @@
//@flow
const FETCH_REPOSITORIES = 'smeagol/repositories/FETCH';
const FETCH_REPOSITORIES_SUCCESS = 'smeagol/repositories/FETCH_SUCCESS';
const FETCH_REPOSITORIES_FAILURE = 'smeagol/repositories/FETCH_FAILURE';
const THRESHOLD_TIMESTAMP = 10000;
function requestRepositories() {
return {
type: FETCH_REPOSITORIES
};
}
function fetchRepositories() {
return function(dispatch) {
dispatch(requestRepositories());
return null;
}
}
export function shouldFetchRepositories(state: any): boolean {
const repositories = state.repositories;
return null;
}
export function fetchRepositoriesIfNeeded() {
return (dispatch, getState) => {
if (shouldFetchRepositories(getState())) {
dispatch(fetchRepositories());
}
}
}
export default function reducer(state = {}, action = {}) {
switch (action.type) {
case FETCH_REPOSITORIES:
return {
...state,
loading: true,
error: null
};
case FETCH_REPOSITORIES_SUCCESS:
return {
...state,
loading: false,
timestamp: action.timestamp,
error: null,
repositories: action.payload
};
case FETCH_REPOSITORIES_FAILURE:
return {
...state,
loading: false,
error: action.payload
};
default:
return state
}
}