mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-09-29 23:07:31 +05:30
#407: Refresh applications list on account switch
This commit is contained in:
parent
527b90d17e
commit
4727e0d88a
@ -96,7 +96,9 @@ export default class ApplicationsIndex extends Component<Props> {
|
|||||||
resetClientId={resetClientId}
|
resetClientId={resetClientId}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else if (displayForGuest) {
|
}
|
||||||
|
|
||||||
|
if (displayForGuest) {
|
||||||
return <Guest />;
|
return <Guest />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,37 +11,48 @@ import {
|
|||||||
} from 'components/dev/apps/actions';
|
} from 'components/dev/apps/actions';
|
||||||
import ApplicationsIndex from 'components/dev/apps/ApplicationsIndex';
|
import ApplicationsIndex from 'components/dev/apps/ApplicationsIndex';
|
||||||
|
|
||||||
class ApplicationsListPage extends Component<
|
interface Props {
|
||||||
{
|
location: Location;
|
||||||
location: Location,
|
history: RouterHistory;
|
||||||
history: RouterHistory,
|
user: User;
|
||||||
user: User,
|
apps: Array<OauthAppResponse>;
|
||||||
apps: Array<OauthAppResponse>,
|
fetchAvailableApps: () => Promise<void>;
|
||||||
fetchAvailableApps: () => Promise<void>,
|
deleteApp: string => Promise<void>;
|
||||||
deleteApp: string => Promise<void>,
|
resetApp: (string, bool) => Promise<void>;
|
||||||
resetApp: (string, bool) => Promise<void>
|
}
|
||||||
},
|
|
||||||
{
|
interface State {
|
||||||
isLoading: bool
|
isLoading: bool;
|
||||||
}
|
forceUpdate: bool;
|
||||||
> {
|
}
|
||||||
|
|
||||||
|
class ApplicationsListPage extends Component<Props, State> {
|
||||||
state = {
|
state = {
|
||||||
isLoading: false
|
isLoading: false,
|
||||||
|
forceUpdate: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
!this.props.user.isGuest && this.loadApplicationsList();
|
!this.props.user.isGuest && this.loadApplicationsList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate({ user }) {
|
||||||
|
if (this.props.user !== user) {
|
||||||
|
// eslint-disable-next-line react/no-did-update-set-state
|
||||||
|
this.setState({ forceUpdate: true });
|
||||||
|
this.loadApplicationsList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { user, apps, resetApp, deleteApp, location } = this.props;
|
const { user, apps, resetApp, deleteApp, location } = this.props;
|
||||||
const { isLoading } = this.state;
|
const { isLoading, forceUpdate } = this.state;
|
||||||
const clientId = location.hash.substr(1) || null;
|
const clientId = location.hash.substr(1) || null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ApplicationsIndex
|
<ApplicationsIndex
|
||||||
displayForGuest={user.isGuest}
|
displayForGuest={user.isGuest}
|
||||||
applications={apps}
|
applications={forceUpdate ? [] : apps}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
deleteApp={deleteApp}
|
deleteApp={deleteApp}
|
||||||
resetApp={resetApp}
|
resetApp={resetApp}
|
||||||
@ -54,7 +65,10 @@ class ApplicationsListPage extends Component<
|
|||||||
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,
|
||||||
|
forceUpdate: false,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
resetClientId = () => {
|
resetClientId = () => {
|
||||||
@ -66,14 +80,11 @@ class ApplicationsListPage extends Component<
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(
|
export default connect((state) => ({
|
||||||
(state) => ({
|
user: state.user,
|
||||||
user: state.user,
|
apps: state.apps.available,
|
||||||
apps: state.apps.available
|
}), {
|
||||||
}),
|
fetchAvailableApps,
|
||||||
{
|
resetApp,
|
||||||
fetchAvailableApps,
|
deleteApp,
|
||||||
resetApp,
|
})(ApplicationsListPage);
|
||||||
deleteApp
|
|
||||||
}
|
|
||||||
)(ApplicationsListPage);
|
|
||||||
|
Loading…
Reference in New Issue
Block a user