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

#23 added superpowers switch

This commit is contained in:
Fedor Katurov 2021-03-19 14:15:04 +07:00
parent e38090c755
commit 756840f173
16 changed files with 178 additions and 25 deletions

View file

@ -1,6 +1,6 @@
import React, { FC, useEffect } from 'react';
import React, { FC, useCallback, useEffect } from 'react';
import { selectNode, selectNodeComments } from '~/redux/node/selectors';
import { selectUser } from '~/redux/auth/selectors';
import { selectAuthIsTester, selectUser } from '~/redux/auth/selectors';
import { useDispatch } from 'react-redux';
import { NodeComments } from '~/components/node/NodeComments';
import styles from './styles.module.scss';
@ -15,11 +15,12 @@ import { Footer } from '~/components/main/Footer';
import { BorisStats } from '~/components/boris/BorisStats';
import { useShallowSelect } from '~/utils/hooks/useShallowSelect';
import { selectBorisStats } from '~/redux/boris/selectors';
import { authSetUser } from '~/redux/auth/actions';
import { authSetState, authSetUser } from '~/redux/auth/actions';
import { nodeLoadNode } from '~/redux/node/actions';
import { borisLoadStats } from '~/redux/boris/actions';
import { Container } from '~/containers/main/Container';
import StickyBox from 'react-sticky-box/dist/esnext';
import { BorisSuperpowers } from '~/components/boris/BorisSuperpowers';
type IProps = {};
@ -30,6 +31,7 @@ const BorisLayout: FC<IProps> = () => {
const user = useShallowSelect(selectUser);
const stats = useShallowSelect(selectBorisStats);
const comments = useShallowSelect(selectNodeComments);
const is_tester = useShallowSelect(selectAuthIsTester);
useEffect(() => {
const last_comment = comments[0];
@ -55,6 +57,13 @@ const BorisLayout: FC<IProps> = () => {
dispatch(borisLoadStats());
}, [dispatch]);
const setBetaTester = useCallback(
(is_tester: boolean) => {
dispatch(authSetState({ is_tester }));
},
[dispatch]
);
return (
<Container>
<div className={styles.wrap}>
@ -102,6 +111,10 @@ const BorisLayout: FC<IProps> = () => {
<p className="grey">//&nbsp;Такова&nbsp;жизнь.</p>
</div>
<div>
{user.is_user && <BorisSuperpowers active={is_tester} onChange={setBetaTester} />}
</div>
<div className={styles.stats__wrap}>
<BorisStats stats={stats} />
</div>