// @flow import type { OauthAppResponse } from 'services/api/oauth'; import React from 'react'; import { restoreScroll } from 'components/ui/scroll/scroll'; import { FormattedMessage as Message } from 'react-intl'; import { LinkButton } from 'components/ui/form'; import { COLOR_GREEN } from 'components/ui'; import messages from '../ApplicationsIndex.intl.json'; import styles from '../applicationsIndex.scss'; import ApplicationItem from './ApplicationItem'; type Props = { applications: Array, deleteApp: string => Promise, resetApp: (string, bool) => Promise, resetClientId: () => void, clientId: ?string }; type State = { expandedApp: ?string }; export default class ApplicationsList extends React.Component { state = { expandedApp: null }; appsRefs: { [key: string]: ?HTMLDivElement } = {}; componentDidMount() { this.checkForActiveApp(); } componentDidUpdate() { this.checkForActiveApp(); } render() { const { applications, resetApp, deleteApp } = this.props; const { expandedApp } = this.state; return (
{applications.map((app) => (
{ this.appsRefs[app.clientId] = elem; }} >
))}
); } checkForActiveApp() { const { applications, clientId } = this.props; const { expandedApp } = this.state; if ( clientId && expandedApp !== clientId && applications.some((app) => app.clientId === clientId) ) { requestAnimationFrame(() => this.onTileClick(clientId, {noReset: true})); } } onTileClick = (clientId: string, { noReset = false }: { noReset?: bool } = {}) => { const { clientId: initialClientId, resetClientId } = this.props; const expandedApp = this.state.expandedApp === clientId ? null : clientId; if (initialClientId && noReset !== true) { resetClientId(); } this.setState({ expandedApp }, () => { if (expandedApp !== null) { // TODO: @SleepWalker: мб у тебя есть идея, как это сделать более правильно и менее дёргано? setTimeout(() => restoreScroll(this.appsRefs[clientId]), 150); } }); }; }