mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 06:55:47 +01:00
62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
|
|
//@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
|
||
|
|
}
|
||
|
|
}
|