1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

left panel with git logs at boris

This commit is contained in:
Fedor Katurov 2020-06-09 11:20:46 +07:00
parent 13ac60a1e6
commit cb518f0528
15 changed files with 211 additions and 44 deletions

View file

@ -6,6 +6,11 @@ export const borisSet = (state: Partial<IBorisState>) => ({
state,
});
export const borisSetStats = (stats: Partial<IBorisState['stats']>) => ({
type: BORIS_ACTIONS.SET_STATS,
stats,
});
export const borisLoadStats = () => ({
type: BORIS_ACTIONS.LOAD_STATS,
});

View file

@ -1,8 +1,3 @@
import Axios from 'axios';
import { API } from '~/constants/api';
import { resultMiddleware, errorMiddleware } from '~/utils/api';
import git from '~/stats/git.json';
export const getBorisGitStats = (): Promise<any> =>
Axios.get(API.BORIS.GET_GIT_LOG)
.then(resultMiddleware)
.catch(errorMiddleware);
export const getBorisGitStats = (): Promise<any> => Promise.resolve(git);

View file

@ -2,5 +2,7 @@ const prefix = `BORIS.`;
export const BORIS_ACTIONS = {
SET_BORIS: `${prefix}SET_BORIS`,
SET_STATS: `${prefix}SET_STATS`,
LOAD_STATS: `${prefix}LOAD_STATS`,
};

View file

@ -6,6 +6,15 @@ const borisSet = (current: IBorisState, { state }: ReturnType<typeof borisSet>)
...state,
});
const borisSetStats = (state: IBorisState, { stats }: ReturnType<typeof borisSetStats>) => ({
...state,
stats: {
...state.stats,
...stats,
},
});
export const BORIS_HANDLERS = {
[BORIS_ACTIONS.SET_BORIS]: borisSet,
[BORIS_ACTIONS.SET_STATS]: borisSetStats,
};

View file

@ -10,15 +10,15 @@ export type IStatGitRow = {
export type IBorisState = Readonly<{
stats: {
git: IStatGitRow[];
is_loading: boolean;
};
is_loading: boolean;
}>;
const BORIS_INITIAL_STATE: IBorisState = {
stats: {
git: [],
is_loading: false,
},
is_loading: false,
};
export default createReducer(BORIS_INITIAL_STATE, BORIS_HANDLERS);

View file

@ -1,15 +1,17 @@
import { takeLatest, put, call } from 'redux-saga/effects';
import { BORIS_ACTIONS } from './constants';
import { borisSet } from './actions';
import { borisSet, borisSetStats } from './actions';
import { getBorisGitStats } from './api';
function* loadStats() {
yield put(borisSet({ is_loading: true }));
yield put(borisSetStats({ is_loading: true }));
const result = yield getBorisGitStats();
console.log(result);
yield put(borisSet({ is_loading: false }));
try {
const git = yield getBorisGitStats();
yield put(borisSetStats({ git, is_loading: false }));
} catch (e) {
yield put(borisSetStats({ git: [], is_loading: false }));
}
}
export default function* borisSaga() {