From 8071a1644cf9da2302fd04f6b06ff71c4cffe12e Mon Sep 17 00:00:00 2001 From: muerwre Date: Thu, 4 Apr 2019 17:41:09 +0700 Subject: [PATCH] persisted user profile --- src/components/main/Header/index.tsx | 26 +++++++++++++++++++------- src/components/main/Header/style.scss | 18 ++++++++++++++---- src/redux/store.ts | 2 +- src/redux/user/reducer.ts | 7 +++++-- src/redux/user/sagas.ts | 4 ++-- src/styles/colors.scss | 2 +- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/components/main/Header/index.tsx b/src/components/main/Header/index.tsx index 0616868a..de7ad802 100644 --- a/src/components/main/Header/index.tsx +++ b/src/components/main/Header/index.tsx @@ -1,25 +1,37 @@ import * as React from 'react'; import { Logo } from "$components/main/Logo"; +import { connect } from 'react-redux'; +import { IUserProfile, IUserState } from "$redux/user/reducer"; const style = require('./style.scss'); -export const Header = () => ( +interface IHeaderProps { + username?: IUserProfile['username'], + is_user?: IUserProfile['is_user'], +} + +export const Component: React.FunctionComponent = ({ username, is_user }) => (
+ { + is_user && username && +
+
+ {username} +
+ }
depth
boris
flow
+
); -/* -
-
- gvorcek -
- */ +const mapStateToProps = ({ user: { profile: { username, is_user } } }: { user: IUserState }) => ({ username, is_user }); + +export const Header = connect(mapStateToProps)(Component); diff --git a/src/components/main/Header/style.scss b/src/components/main/Header/style.scss index e97570fa..99993863 100644 --- a/src/components/main/Header/style.scss +++ b/src/components/main/Header/style.scss @@ -14,6 +14,7 @@ .plugs { display: flex; + user-select: none; > div { //margin: 8px; @@ -31,6 +32,10 @@ display: block; } + &:first-child { + padding-left: $spc + $gap; + } + &:last-child { padding-right: 0; @@ -50,11 +55,16 @@ padding: 0 $gap; display: flex; align-items: center; + background: white; + color: $main_bg_color; + height: 20px; + border-radius: $input_radius; + font-size: $text_small; } .user_avatar { - width: 16px; - height: 16px; - background: transparentize(white, 0.5); - margin-right: $gap; + //width: 16px; + //height: 16px; + //background: transparentize(white, 0.5); + //margin-right: $gap; } diff --git a/src/redux/store.ts b/src/redux/store.ts index cd5fc2bc..ddde92df 100644 --- a/src/redux/store.ts +++ b/src/redux/store.ts @@ -12,7 +12,7 @@ import { routerMiddleware } from 'connected-react-router' const userPersistConfig: PersistConfig = { key: 'user', - whitelist: ['user', 'logo', 'provider', 'speed'], + whitelist: ['profile'], storage, }; diff --git a/src/redux/user/reducer.ts b/src/redux/user/reducer.ts index 8711b319..8d317ded 100644 --- a/src/redux/user/reducer.ts +++ b/src/redux/user/reducer.ts @@ -7,8 +7,10 @@ export interface IUserProfile { username: string, email: string, role: string, - activated: boolean, token: string, + + is_activated: boolean, + is_user: boolean, } export interface IUserFormStateLogin { @@ -58,7 +60,8 @@ const INITIAL_STATE: IUserState = { email: '', role: '', token: '', - activated: false, + is_activated: false, + is_user: false, }, form_state: { login: { diff --git a/src/redux/user/sagas.ts b/src/redux/user/sagas.ts index 168d38e5..621db035 100644 --- a/src/redux/user/sagas.ts +++ b/src/redux/user/sagas.ts @@ -14,9 +14,9 @@ function* sendLoginRequestSaga({ username, password }: ReturnType