Clear location.hash, when switch active app

This commit is contained in:
SleepWalker 2018-11-04 08:22:04 +02:00
parent 439453c258
commit 8e50b3f30d
3 changed files with 54 additions and 25 deletions

View File

@ -17,11 +17,12 @@ import ApplicationsList from './list';
type Props = { type Props = {
clientId?: ?string, clientId?: ?string,
resetClientId: () => void, // notify parent to remove clientId from current location.href
displayForGuest: bool, displayForGuest: bool,
applications: Array<OauthAppResponse>, applications: Array<OauthAppResponse>,
isLoading: bool, isLoading: bool,
deleteApp: string => Promise<any>, deleteApp: string => Promise<any>,
resetApp: (string, bool) => Promise<any> resetApp: (string, bool) => Promise<any>,
}; };
export default class ApplicationsIndex extends Component<Props> { export default class ApplicationsIndex extends Component<Props> {
@ -81,7 +82,8 @@ export default class ApplicationsIndex extends Component<Props> {
isLoading, isLoading,
resetApp, resetApp,
deleteApp, deleteApp,
clientId clientId,
resetClientId
} = this.props; } = this.props;
if (displayForGuest) { if (displayForGuest) {
@ -95,6 +97,7 @@ export default class ApplicationsIndex extends Component<Props> {
resetApp={resetApp} resetApp={resetApp}
deleteApp={deleteApp} deleteApp={deleteApp}
clientId={clientId} clientId={clientId}
resetClientId={resetClientId}
/> />
); );
} }

View File

@ -14,6 +14,7 @@ type Props = {
applications: Array<OauthAppResponse>, applications: Array<OauthAppResponse>,
deleteApp: string => Promise<any>, deleteApp: string => Promise<any>,
resetApp: (string, bool) => Promise<any>, resetApp: (string, bool) => Promise<any>,
resetClientId: () => void,
clientId: ?string clientId: ?string
}; };
@ -89,9 +90,14 @@ export default class ApplicationsList extends React.Component<Props, State> {
} }
onTileClick = (clientId: string) => { onTileClick = (clientId: string) => {
const { clientId: initialClientId, resetClientId } = this.props;
const expandedApp const expandedApp
= this.state.expandedApp === clientId ? null : clientId; = this.state.expandedApp === clientId ? null : clientId;
if (initialClientId !== clientId) {
resetClientId();
}
this.setState({ expandedApp }, () => { this.setState({ expandedApp }, () => {
if (expandedApp !== null) { if (expandedApp !== null) {
// TODO: @SleepWalker: мб у тебя есть идея, как это сделать более правильно и менее дёргано? // TODO: @SleepWalker: мб у тебя есть идея, как это сделать более правильно и менее дёргано?

View File

@ -1,24 +1,32 @@
// @flow // @flow
import type { Location, RouterHistory } from 'react-router';
import type { User } from 'components/user'; import type { User } from 'components/user';
import type { OauthAppResponse } from 'services/api/oauth'; import type { OauthAppResponse } from 'services/api/oauth';
import type { Location } from 'react-router';
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { fetchAvailableApps, resetApp, deleteApp } from 'components/dev/apps/actions'; import {
fetchAvailableApps,
resetApp,
deleteApp
} from 'components/dev/apps/actions';
import ApplicationsIndex from 'components/dev/apps/ApplicationsIndex'; import ApplicationsIndex from 'components/dev/apps/ApplicationsIndex';
class ApplicationsListPage extends Component<{ class ApplicationsListPage extends Component<
location: Location, {
user: User, location: Location,
apps: Array<OauthAppResponse>, history: RouterHistory,
fetchAvailableApps: () => Promise<void>, user: User,
deleteApp: (string) => Promise<void>, apps: Array<OauthAppResponse>,
resetApp: (string, bool) => Promise<void>, fetchAvailableApps: () => Promise<void>,
}, { deleteApp: string => Promise<void>,
isLoading: bool, resetApp: (string, bool) => Promise<void>
}> { },
{
isLoading: bool
}
> {
state = { state = {
isLoading: false, isLoading: false
}; };
componentDidMount() { componentDidMount() {
@ -38,22 +46,34 @@ class ApplicationsListPage extends Component<{
deleteApp={deleteApp} deleteApp={deleteApp}
resetApp={resetApp} resetApp={resetApp}
clientId={clientId} clientId={clientId}
resetClientId={this.resetClientId}
/> />
); );
} }
loadApplicationsList = async () => { loadApplicationsList = async () => {
this.setState({isLoading: true}); this.setState({ isLoading: true });
await this.props.fetchAvailableApps(); await this.props.fetchAvailableApps();
this.setState({isLoading: false}); this.setState({ isLoading: false });
};
resetClientId = () => {
const { history, location } = this.props;
if (location.hash) {
history.push({ ...location, hash: '' });
}
}; };
} }
export default connect((state) => ({ export default connect(
user: state.user, (state) => ({
apps: state.apps.available, user: state.user,
}), { apps: state.apps.available
fetchAvailableApps, }),
resetApp, {
deleteApp, fetchAvailableApps,
})(ApplicationsListPage); resetApp,
deleteApp
}
)(ApplicationsListPage);