// @flow import type { Node } from 'react'; import type { OauthAppResponse } from 'services/api/oauth'; import React, { Component } from 'react'; import { FormattedMessage as Message } from 'react-intl'; import { Helmet } from 'react-helmet'; import { LinkButton } from 'components/ui/form'; import { COLOR_GREEN, COLOR_BLUE } from 'components/ui'; import { restoreScroll } from 'components/ui/scroll/scroll'; import { ContactLink } from 'components/contact'; import styles from './applicationsIndex.scss'; import messages from './ApplicationsIndex.intl.json'; import cubeIcon from './icons/cube.svg'; import loadingCubeIcon from './icons/loading-cube.svg'; import toolsIcon from './icons/tools.svg'; import ApplicationItem from './ApplicationItem'; type Props = { clientId?: ?string, displayForGuest: bool, applications: Array, isLoading: bool, deleteApp: (string) => Promise, resetApp: (string, bool) => Promise, }; type State = { expandedApp: ?string, }; export default class ApplicationsIndex extends Component { state = { expandedApp: null, }; appsRefs: {[key: string]: ?HTMLDivElement} = {}; componentDidUpdate(prevProps: Props) { const { applications, isLoading, clientId } = this.props; if (isLoading !== prevProps.isLoading && applications.length) { if (clientId && applications.some((app) => app.clientId === clientId)) { requestAnimationFrame(() => this.onTileClick(clientId)); } } } render() { const { displayForGuest, applications, isLoading, resetApp, deleteApp } = this.props; const { expandedApp } = this.state; let content: Node; if (displayForGuest) { content = (
); } else if (isLoading) { content = (
); } else if (applications.length > 0) { content = (
{applications.map((app: OauthAppResponse) => (
{this.appsRefs[app.clientId] = elem;}}>
))}
); } else { content = (
); } return (
{(pageTitle: string) => (

{pageTitle}

)}
), }} />
), }} />
{content}
); } onTileClick = (clientId: string) => { const expandedApp = this.state.expandedApp === clientId ? null : clientId; this.setState({expandedApp}, () => { if (expandedApp !== null) { // TODO: @SleepWalker: мб у тебя есть идея, как это сделать более правильно и менее дёргано? setTimeout(() => restoreScroll(this.appsRefs[clientId]), 150); } }); }; }