import React, { CSSProperties } from "react"; import { fetchUser, fetchUserNovels, generateActivateLink } from "../../api/users"; import './User.sass' import NotFoundError from "../../components/NotFoundError"; import { Link } from "react-router-dom"; import Loading from "../../components/Loading"; import NovelItem from "../../ui/NovelItem/NovelItem"; import { connect } from "react-redux"; import Button from "../../ui/Button/Button"; import NotificationMessage from "../../ui/Notifications/NotificationMessage"; import { addNotification } from "../../store/ducks/notifications"; type Props = { match: { params: { userId: string } } currentUser: UserType addNotification: AddNotification } type State = { user: UserType | null novels: NovelType[] errorCode: number | null } class User extends React.Component { state: State = { user: null, novels: [], errorCode: null }; getAndSetUser = (id: number) => { fetchUser(id).then(user => { this.setState({ user }); document.title = `${user.username} / Unmei`; fetchUserNovels(id).then(novels => { this.setState({ novels }); }).catch((err: ApiError) => console.error(err)); }).catch((err: ApiError) => this.setState({ errorCode: err.code })); } componentDidUpdate(prevProps: Readonly, prevState: Readonly, _?: any) { const newUserId = parseInt(this.props.match.params.userId); const prevUserId = parseInt(prevProps.match.params.userId); if(newUserId !== prevUserId) { this.getAndSetUser(newUserId); } } componentDidMount() { const params = this.props.match.params; this.getAndSetUser(parseInt(params.userId)) } sendActivateLink = () => { generateActivateLink().then(() => { const notification = ( Сообщение успешно отправлено! ); this.props.addNotification(notification); }).catch((err: ApiError) => { const notification = ( Произошла ошибка! №{err.code}
{err.text}
); this.props.addNotification(notification); }); } render() { const { currentUser } = this.props; const { errorCode, user, novels } = this.state; if(errorCode === 100) return ; if(!user) return ; const style: CSSProperties = !user.is_activated ? { marginTop: '1rem' } : {}; const userNameStyle: CSSProperties = JSON.parse(localStorage.getItem('color-name') || 'false') && user.group.id !== 0 ? { color: user.group.color } : {}; return (
{!user.is_activated && user.id === currentUser.id && (

Ваш аккаунт не активирован!

Активируйте аккаунт, для доступа ко многим функциям. Так же актвация аккаунта позволит восстановить пароль.

)}
{user.cover ? (
{user.username}
{user.group.name}
) : (
{user.username}
{user.group.name}
)}
Новеллы
n.status === 'planned').length}>Запланированно
n.status === 'completed').length}>Пройдено
n.status === 'in_progress').length}>Прохожу
n.status === 'deferred').length}>Отложено
n.status === 'dropped').length}>Брошено
Список новелл пользователя:
Все новеллы
{novels.length > 0 ? novels.slice(0, 4).map((novel, id) => ) : (
У этого пользователя нет новелл!
)}
{/*
Список аниме пользователя:
В разработке...
Список манги и ранобэ пользователя:
В разработке...
Список игр пользователя:
В разработке...
Список фильмов пользователя:
В разработке...
Список сериалов пользователя:
В разработке...
*/}
); } } export default connect( (state: StoreState) => ({ currentUser: state.currentUser }), dispatch => ({ addNotification: (notification: React.ReactNode) => dispatch(addNotification(notification)) }) )(User);