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

Merge branch 'master' into 23-labs

# Conflicts:
#	src/redux/node/constants.ts
This commit is contained in:
Fedor Katurov 2021-03-12 11:26:03 +07:00
commit 8316b46efe
56 changed files with 1085 additions and 527 deletions

View file

@ -1,10 +1,20 @@
import git from '~/stats/git.json';
import { API } from '~/constants/api';
import { api, resultMiddleware, errorMiddleware, cleanResult } from '~/utils/api';
import { api, cleanResult } from '~/utils/api';
import { IBorisState, IStatBackend } from './reducer';
import { IResultWithStatus } from '../types';
import axios from 'axios';
import { IGetGithubIssuesResult } from '~/redux/boris/types';
export const getBorisGitStats = () => Promise.resolve<IBorisState['stats']['git']>(git);
export const getBorisBackendStats = () =>
api.get<IStatBackend>(API.BORIS.GET_BACKEND_STATS).then(cleanResult);
export const getGithubIssues = () => {
return axios
.get<IGetGithubIssuesResult>('https://api.github.com/repos/muerwre/vault-frontend/issues', {
params: { state: 'all', sort: 'created' },
})
.then(result => result.data)
.catch(() => []);
};

View file

@ -1,5 +1,6 @@
import { createReducer } from '~/utils/reducer';
import { BORIS_HANDLERS } from './handlers';
import { IGithubIssue } from '~/redux/boris/types';
export type IStatGitRow = {
commit: string;
@ -31,6 +32,7 @@ export type IStatBackend = {
export type IBorisState = Readonly<{
stats: {
git: Partial<IStatGitRow>[];
issues: IGithubIssue[];
backend?: IStatBackend;
is_loading: boolean;
};
@ -39,6 +41,7 @@ export type IBorisState = Readonly<{
const BORIS_INITIAL_STATE: IBorisState = {
stats: {
git: [],
issues: [],
backend: undefined,
is_loading: false,
},

View file

@ -1,17 +1,17 @@
import { takeLatest, put, call } from 'redux-saga/effects';
import { call, put, takeLatest } from 'redux-saga/effects';
import { BORIS_ACTIONS } from './constants';
import { borisSetStats } from './actions';
import { getBorisGitStats, getBorisBackendStats } from './api';
import { getBorisBackendStats, getGithubIssues } from './api';
import { Unwrap } from '../types';
function* loadStats() {
try {
yield put(borisSetStats({ is_loading: true }));
const git: Unwrap<typeof getBorisGitStats> = yield call(getBorisGitStats);
const backend: Unwrap<typeof getBorisBackendStats> = yield call(getBorisBackendStats);
const issues: Unwrap<typeof getGithubIssues> = yield call(getGithubIssues);
yield put(borisSetStats({ git, backend }));
yield put(borisSetStats({ issues, backend }));
} catch (e) {
yield put(borisSetStats({ git: [], backend: undefined }));
} finally {

12
src/redux/boris/types.ts Normal file
View file

@ -0,0 +1,12 @@
export interface IGithubIssue {
id: string;
url: string;
html_url: string;
body: string;
title: string;
state: 'open' | 'closed';
created_at: string;
pull_request?: unknown;
}
export type IGetGithubIssuesResult = IGithubIssue[];

View file

@ -129,7 +129,7 @@ export const nodeSetEditor = (editor: INode) => ({
editor,
});
export const nodeSetCoverImage = (current_cover_image: IFile) => ({
export const nodeSetCoverImage = (current_cover_image?: IFile) => ({
type: NODE_ACTIONS.SET_COVER_IMAGE,
current_cover_image,
});

View file

@ -1,6 +1,5 @@
import { FC, ReactElement } from 'react';
import { FC } from 'react';
import { IComment, INode, ValueOf } from '../types';
import { NodeImageSlideBlock } from '~/components/node/NodeImageSlideBlock';
import { NodeTextBlock } from '~/components/node/NodeTextBlock';
import { NodeAudioBlock } from '~/components/node/NodeAudioBlock';
import { NodeVideoBlock } from '~/components/node/NodeVideoBlock';
@ -12,10 +11,10 @@ import { AudioEditor } from '~/components/editors/AudioEditor';
import { EditorImageUploadButton } from '~/components/editors/EditorImageUploadButton';
import { EditorAudioUploadButton } from '~/components/editors/EditorAudioUploadButton';
import { EditorUploadCoverButton } from '~/components/editors/EditorUploadCoverButton';
import { modalShowPhotoswipe } from '../modal/actions';
import { IEditorComponentProps, NodeEditorProps } from '~/redux/node/types';
import { EditorFiller } from '~/components/editors/EditorFiller';
import { EditorPublicSwitch } from '~/components/editors/EditorPublicSwitch';
import { NodeImageSwiperBlock } from '~/components/node/NodeImageSwiperBlock';
const prefix = 'NODE.';
export const NODE_ACTIONS = {
@ -79,17 +78,13 @@ export const NODE_TYPES = {
export type INodeComponentProps = {
node: INode;
is_loading: boolean;
is_modal_shown: boolean;
layout: {};
updateLayout: () => void;
modalShowPhotoswipe: typeof modalShowPhotoswipe;
isLoading: boolean;
};
export type INodeComponents = Record<ValueOf<typeof NODE_TYPES>, FC<INodeComponentProps>>;
export const NODE_HEADS: INodeComponents = {
[NODE_TYPES.IMAGE]: NodeImageSlideBlock,
[NODE_TYPES.IMAGE]: NodeImageSwiperBlock,
};
export const NODE_COMPONENTS: INodeComponents = {

View file

@ -1,16 +1,14 @@
import { createReducer } from '~/utils/reducer';
import { INode, IComment, IFile } from '../types';
import { EMPTY_NODE, EMPTY_COMMENT } from './constants';
import { IComment, IFile, INode } from '../types';
import { EMPTY_COMMENT, EMPTY_NODE } from './constants';
import { NODE_HANDLERS } from './handlers';
import { INodeRelated } from '~/redux/node/types';
export type INodeState = Readonly<{
editor: INode;
current: INode;
comments: IComment[];
related: {
albums: Record<string, INode[]>;
similar: INode[];
};
related: INodeRelated;
comment_data: Record<number, IComment>;
comment_count: number;
current_cover_image?: IFile;

View file

@ -89,3 +89,8 @@ export type NodeEditorProps = {
temp: string[];
setTemp: (val: string[]) => void;
};
export type INodeRelated = {
albums: Record<string, INode[]>;
similar: INode[];
};

View file

@ -75,7 +75,9 @@ export const sagaMiddleware = createSagaMiddleware();
export const history = createBrowserHistory();
const composeEnhancers =
typeof window === 'object' && (<any>window).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
typeof window === 'object' &&
(<any>window).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ &&
process.env.NODE_ENV === 'development'
? (<any>window).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
: compose;

View file

@ -11,7 +11,7 @@ import { apiGetTagSuggestions, apiGetNodesOfTag } from '~/redux/tag/api';
import { Unwrap } from '~/redux/types';
function* loadTagNodes({ tag }: ReturnType<typeof tagLoadNodes>) {
yield put(tagSetNodes({ isLoading: true, list: [] }));
yield put(tagSetNodes({ isLoading: true }));
try {
const { list }: ReturnType<typeof selectTagNodes> = yield select(selectTagNodes);