mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 17:55:17 -04:00
Frontend config and Loader component (#12)
* Add FrontendConfig and Loader Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * Merge more setup into the application loader Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * Rename config files Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * Remove blank line Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * Fix url Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * Make strings more specific Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * Restructure store use Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * split methods and actions Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * extract code Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * remove actions.ts Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * add reason and rename component Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * remove unused call Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * Use redux store in api Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * activate email in backend config Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * add new line Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * reduce code Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * Make error more specific Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * Use expectedResponseCode Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * Update src/redux/backend-config/types.ts Co-authored-by: Philip Molares <git@molar.es> * Update src/components/application-loader/application-loader.tsx Co-authored-by: Philip Molares <git@molar.es> * Update src/components/application-loader/application-loader.tsx Co-authored-by: Philip Molares <git@molar.es> * Update src/components/application-loader/application-loader.tsx Co-authored-by: Philip Molares <git@molar.es> * Use fragment Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> Co-authored-by: Philip Molares <git@molar.es>
This commit is contained in:
parent
ef17c7acbb
commit
a490e1240b
36 changed files with 425 additions and 256 deletions
|
@ -1,20 +0,0 @@
|
|||
import {Action, ActionCreator} from 'redux';
|
||||
import {ApplicationConfigState} from "./types";
|
||||
|
||||
export const SET_APPLICATION_CONFIG_ACTION_TYPE = 'config/set';
|
||||
|
||||
export interface SetApplicationConfigAction extends Action {
|
||||
type: string;
|
||||
payload: {
|
||||
state: ApplicationConfigState;
|
||||
};
|
||||
}
|
||||
|
||||
export const setApplicationConfig: ActionCreator<SetApplicationConfigAction> = (state: ApplicationConfigState) => ({
|
||||
type: SET_APPLICATION_CONFIG_ACTION_TYPE,
|
||||
payload: {
|
||||
state
|
||||
},
|
||||
})
|
||||
|
||||
export type ApplicationConfigActions = SetApplicationConfigAction;
|
|
@ -1,13 +0,0 @@
|
|||
import {createStore} from 'redux';
|
||||
import {allReducers} from '../index';
|
||||
import {Provider} from "react-redux";
|
||||
import React, {ReactNode} from "react";
|
||||
|
||||
interface JustChildrenProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export const ApplicationStateStoreProvider: React.FC<JustChildrenProps> = (props: JustChildrenProps) => {
|
||||
const store = createStore(allReducers);
|
||||
return <Provider store={store}>{props.children}</Provider>;
|
||||
}
|
12
src/redux/backend-config/methods.ts
Normal file
12
src/redux/backend-config/methods.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import {BackendConfigState, SET_BACKEND_CONFIG_ACTION_TYPE, SetBackendConfigAction} from "./types";
|
||||
import {store} from "../../utils/store";
|
||||
|
||||
export const setBackendConfig = (state: BackendConfigState) => {
|
||||
const action: SetBackendConfigAction = {
|
||||
type: SET_BACKEND_CONFIG_ACTION_TYPE,
|
||||
payload: {
|
||||
state
|
||||
}
|
||||
};
|
||||
store.dispatch(action)
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
import {Reducer} from 'redux';
|
||||
import {ApplicationConfigState} from './types';
|
||||
import {ApplicationConfigActions, SET_APPLICATION_CONFIG_ACTION_TYPE} from "./actions";
|
||||
import {BackendConfigActions, BackendConfigState, SET_BACKEND_CONFIG_ACTION_TYPE} from './types';
|
||||
|
||||
export const initialState: ApplicationConfigState = {
|
||||
export const initialState: BackendConfigState = {
|
||||
allowAnonymous: true,
|
||||
authProviders: {
|
||||
facebook: true,
|
||||
|
@ -23,9 +22,9 @@ export const initialState: ApplicationConfigState = {
|
|||
}
|
||||
};
|
||||
|
||||
export const ApplicationConfigReducer: Reducer<ApplicationConfigState, ApplicationConfigActions> = (state: ApplicationConfigState = initialState, action: ApplicationConfigActions) => {
|
||||
export const BackendConfigReducer: Reducer<BackendConfigState, BackendConfigActions> = (state: BackendConfigState = initialState, action: BackendConfigActions) => {
|
||||
switch (action.type) {
|
||||
case SET_APPLICATION_CONFIG_ACTION_TYPE:
|
||||
case SET_BACKEND_CONFIG_ACTION_TYPE:
|
||||
return action.payload.state;
|
||||
default:
|
||||
return state;
|
|
@ -1,10 +1,13 @@
|
|||
export interface ApplicationConfigState {
|
||||
import {Action} from "redux";
|
||||
|
||||
export const SET_BACKEND_CONFIG_ACTION_TYPE = 'backend-config/set';
|
||||
|
||||
export interface BackendConfigState {
|
||||
allowAnonymous: boolean,
|
||||
authProviders: AuthProvidersState,
|
||||
specialLinks: SpecialLinks,
|
||||
}
|
||||
|
||||
|
||||
export interface AuthProvidersState {
|
||||
facebook: true,
|
||||
github: false,
|
||||
|
@ -23,3 +26,12 @@ export interface SpecialLinks {
|
|||
termsOfUse: string,
|
||||
imprint: string,
|
||||
}
|
||||
|
||||
export interface SetBackendConfigAction extends Action {
|
||||
type: string;
|
||||
payload: {
|
||||
state: BackendConfigState;
|
||||
};
|
||||
}
|
||||
|
||||
export type BackendConfigActions = SetBackendConfigAction;
|
12
src/redux/frontend-config/methods.ts
Normal file
12
src/redux/frontend-config/methods.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import {FrontendConfigState, SET_FRONTEND_CONFIG_ACTION_TYPE, SetFrontendConfigAction} from "./types";
|
||||
import {store} from "../../utils/store";
|
||||
|
||||
export const setFrontendConfig = (state: FrontendConfigState) => {
|
||||
const action: SetFrontendConfigAction = {
|
||||
type: SET_FRONTEND_CONFIG_ACTION_TYPE,
|
||||
payload: {
|
||||
state
|
||||
}
|
||||
}
|
||||
store.dispatch(action);
|
||||
}
|
15
src/redux/frontend-config/reducers.ts
Normal file
15
src/redux/frontend-config/reducers.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import {Reducer} from 'redux';
|
||||
import {FrontendConfigActions, FrontendConfigState, SET_FRONTEND_CONFIG_ACTION_TYPE} from './types';
|
||||
|
||||
export const initialState: FrontendConfigState = {
|
||||
backendUrl: ""
|
||||
};
|
||||
|
||||
export const FrontendConfigReducer: Reducer<FrontendConfigState, FrontendConfigActions> = (state: FrontendConfigState = initialState, action: FrontendConfigActions) => {
|
||||
switch (action.type) {
|
||||
case SET_FRONTEND_CONFIG_ACTION_TYPE:
|
||||
return action.payload.state;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
16
src/redux/frontend-config/types.ts
Normal file
16
src/redux/frontend-config/types.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import {Action} from "redux";
|
||||
|
||||
export const SET_FRONTEND_CONFIG_ACTION_TYPE = 'frontend-config/set';
|
||||
|
||||
export interface SetFrontendConfigAction extends Action {
|
||||
type: string;
|
||||
payload: {
|
||||
state: FrontendConfigState;
|
||||
};
|
||||
}
|
||||
|
||||
export interface FrontendConfigState {
|
||||
backendUrl: string,
|
||||
}
|
||||
|
||||
export type FrontendConfigActions = SetFrontendConfigAction;
|
|
@ -1,19 +1,23 @@
|
|||
import {combineReducers, Reducer} from 'redux';
|
||||
import {UserState} from "./user/types";
|
||||
import {UserReducer} from "./user/reducers";
|
||||
import {ApplicationConfigReducer} from "./application-config/reducers";
|
||||
import {ApplicationConfigState} from "./application-config/types";
|
||||
import {ModalShowReducer} from "./modal/reducers";
|
||||
import {ModalShowState} from "./modal/types";
|
||||
import {BackendConfigState} from "./backend-config/types";
|
||||
import {FrontendConfigState} from "./frontend-config/types";
|
||||
import {BackendConfigReducer} from "./backend-config/reducers";
|
||||
import {FrontendConfigReducer} from "./frontend-config/reducers";
|
||||
|
||||
export interface ApplicationState {
|
||||
user: UserState;
|
||||
modalShow: ModalShowState;
|
||||
applicationConfig: ApplicationConfigState;
|
||||
backendConfig: BackendConfigState;
|
||||
frontendConfig: FrontendConfigState;
|
||||
}
|
||||
|
||||
export const allReducers: Reducer<ApplicationState> = combineReducers<ApplicationState>({
|
||||
user: UserReducer,
|
||||
modalShow: ModalShowReducer,
|
||||
applicationConfig: ApplicationConfigReducer
|
||||
backendConfig: BackendConfigReducer,
|
||||
frontendConfig: FrontendConfigReducer
|
||||
});
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
import {Action, ActionCreator} from 'redux';
|
||||
|
||||
export const SET_HISTORY_DELETE_MODAL_SHOW_ACTION_TYPE = 'modal/history-delete/set';
|
||||
|
||||
export interface SetHistoryDeleteModalShowAction extends Action {
|
||||
type: string;
|
||||
payload: boolean;
|
||||
}
|
||||
|
||||
export const setSignInModalShow: ActionCreator<SetHistoryDeleteModalShowAction> = (historyDelete: boolean) => ({
|
||||
type: SET_HISTORY_DELETE_MODAL_SHOW_ACTION_TYPE,
|
||||
payload: historyDelete,
|
||||
})
|
||||
|
||||
export type ModalShowActions = SetHistoryDeleteModalShowAction;
|
7
src/redux/modal/methods.ts
Normal file
7
src/redux/modal/methods.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import {ActionCreator} from "redux";
|
||||
import {SET_HISTORY_DELETE_MODAL_SHOW_ACTION_TYPE, SetHistoryDeleteModalShowAction} from "./types";
|
||||
|
||||
export const setSignInModalShow: ActionCreator<SetHistoryDeleteModalShowAction> = (historyDelete: boolean) => ({
|
||||
type: SET_HISTORY_DELETE_MODAL_SHOW_ACTION_TYPE,
|
||||
payload: historyDelete,
|
||||
})
|
|
@ -1,6 +1,5 @@
|
|||
import {Reducer} from 'redux';
|
||||
import {ModalShowState} from './types';
|
||||
import {ModalShowActions, SET_HISTORY_DELETE_MODAL_SHOW_ACTION_TYPE} from "./actions";
|
||||
import {ModalShowActions, ModalShowState, SET_HISTORY_DELETE_MODAL_SHOW_ACTION_TYPE} from './types';
|
||||
|
||||
export const initialState: ModalShowState = {
|
||||
historyDelete: false
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
import {Action} from "redux";
|
||||
|
||||
export const SET_HISTORY_DELETE_MODAL_SHOW_ACTION_TYPE = 'modal/history-delete/set';
|
||||
|
||||
export interface ModalShowState {
|
||||
historyDelete: boolean
|
||||
}
|
||||
|
||||
export interface SetHistoryDeleteModalShowAction extends Action {
|
||||
type: string;
|
||||
payload: boolean;
|
||||
}
|
||||
|
||||
export type ModalShowActions = SetHistoryDeleteModalShowAction;
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
import {Action, ActionCreator} from 'redux';
|
||||
import {UserState} from "./types";
|
||||
|
||||
export const SET_USER_ACTION_TYPE = 'user/set';
|
||||
export const CLEAR_USER_ACTION_TYPE = 'user/clear';
|
||||
|
||||
export interface SetUserAction extends Action {
|
||||
type: string;
|
||||
payload: {
|
||||
state: UserState,
|
||||
};
|
||||
}
|
||||
|
||||
export interface ClearUserAction extends Action {
|
||||
type: string;
|
||||
payload: {};
|
||||
}
|
||||
|
||||
export const setUser: ActionCreator<SetUserAction> = (state: UserState) => ({
|
||||
type: SET_USER_ACTION_TYPE,
|
||||
payload: {
|
||||
state
|
||||
},
|
||||
})
|
||||
|
||||
export const clearUser: ActionCreator<ClearUserAction> = () => ({
|
||||
type: CLEAR_USER_ACTION_TYPE,
|
||||
payload: {},
|
||||
})
|
||||
|
||||
|
||||
export type UserActions = SetUserAction | ClearUserAction;
|
20
src/redux/user/methods.ts
Normal file
20
src/redux/user/methods.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import {CLEAR_USER_ACTION_TYPE, ClearUserAction, SET_USER_ACTION_TYPE, SetUserAction, UserState} from "./types";
|
||||
import {store} from "../../utils/store";
|
||||
|
||||
export const setUser = (state: UserState) => {
|
||||
const action: SetUserAction = {
|
||||
type: SET_USER_ACTION_TYPE,
|
||||
payload: {
|
||||
state
|
||||
}
|
||||
}
|
||||
store.dispatch(action);
|
||||
}
|
||||
|
||||
export const clearUser = () => {
|
||||
const action: ClearUserAction = {
|
||||
type: CLEAR_USER_ACTION_TYPE,
|
||||
payload: {},
|
||||
}
|
||||
store.dispatch(action);
|
||||
}
|
|
@ -1,6 +1,12 @@
|
|||
import {Reducer} from 'redux';
|
||||
import {LoginStatus, UserState} from './types';
|
||||
import {CLEAR_USER_ACTION_TYPE, SET_USER_ACTION_TYPE, SetUserAction, UserActions} from "./actions";
|
||||
import {
|
||||
CLEAR_USER_ACTION_TYPE,
|
||||
LoginStatus,
|
||||
SET_USER_ACTION_TYPE,
|
||||
SetUserAction,
|
||||
UserActions,
|
||||
UserState
|
||||
} from './types';
|
||||
|
||||
export const initialState: UserState = {
|
||||
id: "",
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
import {Action} from "redux";
|
||||
|
||||
export const SET_USER_ACTION_TYPE = 'user/set';
|
||||
export const CLEAR_USER_ACTION_TYPE = 'user/clear';
|
||||
|
||||
export interface SetUserAction extends Action {
|
||||
type: string;
|
||||
payload: {
|
||||
state: UserState,
|
||||
};
|
||||
}
|
||||
|
||||
export interface ClearUserAction extends Action {
|
||||
type: string;
|
||||
payload: {};
|
||||
}
|
||||
|
||||
export interface UserState {
|
||||
status: LoginStatus;
|
||||
id: string;
|
||||
|
@ -8,4 +25,6 @@ export interface UserState {
|
|||
export enum LoginStatus {
|
||||
forbidden = "forbidden",
|
||||
ok = "ok"
|
||||
}
|
||||
}
|
||||
|
||||
export type UserActions = SetUserAction | ClearUserAction;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue