mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
boris: refactored sagas
This commit is contained in:
parent
20dead5ef5
commit
90ac1fe611
2 changed files with 10 additions and 11 deletions
|
@ -1,13 +1,10 @@
|
||||||
import git from '~/stats/git.json';
|
import git from '~/stats/git.json';
|
||||||
import { API } from '~/constants/api';
|
import { API } from '~/constants/api';
|
||||||
import { api, resultMiddleware, errorMiddleware } from '~/utils/api';
|
import { api, resultMiddleware, errorMiddleware, cleanResult } from '~/utils/api';
|
||||||
import { IBorisState, IStatBackend } from './reducer';
|
import { IBorisState, IStatBackend } from './reducer';
|
||||||
import { IResultWithStatus } from '../types';
|
import { IResultWithStatus } from '../types';
|
||||||
|
|
||||||
export const getBorisGitStats = (): Promise<IBorisState['stats']['git']> => Promise.resolve(git);
|
export const getBorisGitStats = () => Promise.resolve<IBorisState['stats']['git']>(git);
|
||||||
|
|
||||||
export const getBorisBackendStats = (): Promise<IResultWithStatus<IStatBackend>> =>
|
export const getBorisBackendStats = () =>
|
||||||
api
|
api.get<IStatBackend>(API.BORIS.GET_BACKEND_STATS).then(cleanResult);
|
||||||
.get(API.BORIS.GET_BACKEND_STATS)
|
|
||||||
.then(resultMiddleware)
|
|
||||||
.catch(errorMiddleware);
|
|
||||||
|
|
|
@ -5,15 +5,17 @@ import { getBorisGitStats, getBorisBackendStats } from './api';
|
||||||
import { Unwrap } from '../types';
|
import { Unwrap } from '../types';
|
||||||
|
|
||||||
function* loadStats() {
|
function* loadStats() {
|
||||||
|
try {
|
||||||
yield put(borisSetStats({ is_loading: true }));
|
yield put(borisSetStats({ is_loading: true }));
|
||||||
|
|
||||||
try {
|
|
||||||
const git: Unwrap<typeof getBorisGitStats> = yield call(getBorisGitStats);
|
const git: Unwrap<typeof getBorisGitStats> = yield call(getBorisGitStats);
|
||||||
const backend: Unwrap<typeof getBorisBackendStats> = yield call(getBorisBackendStats);
|
const backend: Unwrap<typeof getBorisBackendStats> = yield call(getBorisBackendStats);
|
||||||
|
|
||||||
yield put(borisSetStats({ git, backend: backend.data, is_loading: false }));
|
yield put(borisSetStats({ git, backend }));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
yield put(borisSetStats({ git: [], backend: null, is_loading: false }));
|
yield put(borisSetStats({ git: [], backend: undefined }));
|
||||||
|
} finally {
|
||||||
|
yield put(borisSetStats({ is_loading: false }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue