Commit 4bb20738 authored by ι™ˆεΈ…'s avatar ι™ˆεΈ…

fix code style

parent 63aebe91
......@@ -33,7 +33,7 @@ const SettingCodeString = `
<SettingDrawer
settings={settings}
onSettingChange={config =>
dispatch!({
dispatch({
type: 'settings/changeSetting',
payload: config,
})
......
......@@ -20,9 +20,12 @@ class AvatarDropdown extends React.Component<GlobalHeaderRightProps> {
if (key === 'logout') {
const { dispatch } = this.props;
dispatch!({
type: 'login/logout',
});
if (dispatch) {
dispatch({
type: 'login/logout',
});
}
return;
}
router.push(`/account/${key}`);
......
......@@ -66,16 +66,20 @@ class GlobalHeaderRight extends Component<GlobalHeaderRightProps> {
changeReadState = (clickedItem: NoticeItem) => {
const { id } = clickedItem;
const { dispatch } = this.props;
dispatch!({
type: 'global/changeNoticeReadState',
payload: id,
});
if (dispatch) {
dispatch({
type: 'global/changeNoticeReadState',
payload: id,
});
}
};
componentDidMount() {
const { dispatch } = this.props;
dispatch!({
type: 'global/fetchNotices',
});
if (dispatch) {
dispatch({
type: 'global/fetchNotices',
});
}
}
handleNoticeClear = (title: string, key: string) => {
const { dispatch } = this.props;
......
......@@ -7,6 +7,7 @@ import SelectLang from '../SelectLang';
import styles from './index.less';
import Avatar from './AvatarDropdown';
import { connect } from 'dva';
export type SiderTheme = 'light' | 'dark';
export interface GlobalHeaderRightProps extends ConnectProps {
theme?: SiderTheme;
......
......@@ -41,25 +41,28 @@ const menuDataRender = (menuList: MenuDataItem[]): MenuDataItem[] => {
};
const BasicLayout: React.FC<BasicLayoutProps> = props => {
const { dispatch, children, settings, location } = props;
const { dispatch, children, settings } = props;
/**
* constructor
*/
useState(() => {
dispatch!({
type: 'user/fetchCurrent',
});
dispatch!({
type: 'settings/getSetting',
});
if (dispatch) {
dispatch({
type: 'user/fetchCurrent',
});
dispatch({
type: 'settings/getSetting',
});
}
});
/**
* init variables
*/
const handleMenuCollapse = (payload: boolean) =>
dispatch!({
dispatch &&
dispatch({
type: 'global/changeLayoutCollapsed',
payload,
});
......
......@@ -99,7 +99,7 @@ const GlobalModel: GlobalModelType = {
},
reducers: {
changeLayoutCollapsed(state, { payload }) {
changeLayoutCollapsed(state = { notices: [], collapsed: true }, { payload }) {
return {
...state,
collapsed: payload,
......@@ -112,7 +112,7 @@ const GlobalModel: GlobalModelType = {
notices: payload,
};
},
saveClearedNotices(state, { payload }) {
saveClearedNotices(state = { notices: [], collapsed: true }, { payload }) {
return {
collapsed: false,
...state,
......
import { routerRedux } from 'dva/router';
import { Reducer } from 'redux';
import { Reducer, AnyAction } from 'redux';
import { EffectsCommandMap } from 'dva';
import { AnyAction } from 'redux';
import { stringify, parse } from 'qs';
export function getPageQuery() {
return parse(window.location.href.split('?')[1]);
}
export interface IStateType {}
export type Effect = (
action: AnyAction,
effects: EffectsCommandMap & { select: <T>(func: (state: IStateType) => T) => T },
effects: EffectsCommandMap & { select: <T>(func: (state: {}) => T) => T },
) => void;
export interface ModelType {
namespace: string;
state: IStateType;
state: {};
effects: {
logout: Effect;
};
reducers: {
changeLoginStatus: Reducer<IStateType>;
changeLoginStatus: Reducer<{}>;
};
}
......
......@@ -6,8 +6,8 @@ export interface SettingModelType {
namespace: 'settings';
state: DefaultSettings;
reducers: {
getSetting: Reducer<any>;
changeSetting: Reducer<any>;
getSetting: Reducer<DefaultSettings>;
changeSetting: Reducer<DefaultSettings>;
};
}
let lessNodesAppended: boolean;
......@@ -72,7 +72,7 @@ const updateTheme: (primaryColor?: string) => void = primaryColor => {
}
};
const updateColorWeak: (colorWeak: string) => void = colorWeak => {
const updateColorWeak: (colorWeak: boolean) => void = colorWeak => {
const root = document.getElementById('root');
if (root) {
root.className = colorWeak ? 'colorWeak' : '';
......@@ -83,8 +83,8 @@ const SettingModel: SettingModelType = {
namespace: 'settings',
state: defaultSettings,
reducers: {
getSetting(state) {
const setting: any = {};
getSetting(state = defaultSettings) {
const setting: Partial<DefaultSettings> = {};
const urlParams = new URL(window.location.href);
Object.keys(state).forEach(key => {
if (urlParams.searchParams.has(key)) {
......@@ -97,13 +97,13 @@ const SettingModel: SettingModelType = {
if (state.primaryColor !== primaryColor) {
updateTheme(primaryColor);
}
updateColorWeak(colorWeak);
updateColorWeak(!!colorWeak);
return {
...state,
...setting,
};
},
changeSetting(state, { payload }) {
changeSetting(state = defaultSettings, { payload }) {
const urlParams = new URL(window.location.href);
Object.keys(defaultSettings).forEach(key => {
if (urlParams.searchParams.has(key)) {
......
......@@ -9,13 +9,15 @@ export interface CurrentUser {
group?: string;
signature?: string;
geographic?: any;
tags?: any[];
tags?: {
key: string;
label: string;
}[];
unreadCount?: number;
}
export interface UserModelState {
list: any[];
currentUser: CurrentUser;
currentUser?: CurrentUser;
}
export interface UserModelType {
......@@ -26,9 +28,8 @@ export interface UserModelType {
fetchCurrent: Effect;
};
reducers: {
save: Reducer<any>;
saveCurrentUser: Reducer<any>;
changeNotifyCount: Reducer<any>;
saveCurrentUser: Reducer<UserModelState>;
changeNotifyCount: Reducer<UserModelState>;
};
}
......@@ -36,7 +37,6 @@ const UserModel: UserModelType = {
namespace: 'user',
state: {
list: [],
currentUser: {},
},
......@@ -58,19 +58,18 @@ const UserModel: UserModelType = {
},
reducers: {
save(state, action) {
return {
...state,
list: action.payload,
};
},
saveCurrentUser(state, action) {
return {
...state,
currentUser: action.payload || {},
};
},
changeNotifyCount(state, action) {
changeNotifyCount(
state = {
currentUser: {},
},
action,
) {
return {
...state,
currentUser: {
......
import Authorized from '@/utils/Authorized';
import { Route } from '@/models/connect';
import { ConnectProps, ConnectState, UserModelState } from '@/models/connect';
import { ConnectProps, ConnectState, UserModelState, Route } from '@/models/connect';
import { connect } from 'dva';
import pathToRegexp from 'path-to-regexp';
import React from 'react';
......@@ -11,7 +10,7 @@ interface AuthComponentProps extends ConnectProps {
}
const getRouteAuthority = (path: string, routeData: Route[]) => {
let authorities: string[] | string | undefined = void 0;
let authorities: string[] | string | undefined = undefined;
routeData.forEach(route => {
// match prefix
if (pathToRegexp(`${route.path}(.*)`).test(path)) {
......
import React from 'react';
const Welcome = () => (
export default () => (
<p style={{ textAlign: 'center' }}>
ζƒ³θ¦ζ·»εŠ ζ›΄ε€šι‘΅ι’οΌŸθ―·ε‚θ€ƒ{' '}
<a href="https://umijs.org/guide/block.html" target="_blank" rel="noopener noreferrer">
......@@ -9,5 +9,3 @@ const Welcome = () => (
。
</p>
);
Welcome.title = 'ζ¬’θΏŽδ½Ώη”¨';
export default Welcome;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment