mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-16 18:26:16 +01:00
fix duplicate loading of plugins
This commit is contained in:
@@ -27,13 +27,32 @@ type Props = {
|
|||||||
t: string => string
|
t: string => string
|
||||||
};
|
};
|
||||||
|
|
||||||
class Index extends Component<Props> {
|
type State = {
|
||||||
|
pluginsLoaded: boolean
|
||||||
|
};
|
||||||
|
|
||||||
|
class Index extends Component<Props, State> {
|
||||||
|
|
||||||
|
constructor(props: Props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
pluginsLoaded: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.fetchIndexResources();
|
this.props.fetchIndexResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pluginLoaderCallback = () => {
|
||||||
|
this.setState({
|
||||||
|
pluginsLoaded: true
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { indexResources, loading, error, t } = this.props;
|
const { indexResources, loading, error, t } = this.props;
|
||||||
|
const { pluginsLoaded } = this.state;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
@@ -47,7 +66,7 @@ class Index extends Component<Props> {
|
|||||||
return <Loading />;
|
return <Loading />;
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<PluginLoader>
|
<PluginLoader loaded={ pluginsLoaded } callback={ this.pluginLoaderCallback }>
|
||||||
<App />
|
<App />
|
||||||
</PluginLoader>
|
</PluginLoader>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ import { getUiPluginsLink } from "../modules/indexResource";
|
|||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
loaded: boolean,
|
||||||
children: React.Node,
|
children: React.Node,
|
||||||
link: string
|
link: string,
|
||||||
|
callback: () => void
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
finished: boolean,
|
|
||||||
message: string
|
message: string
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -23,18 +24,20 @@ class PluginLoader extends React.Component<Props, State> {
|
|||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
finished: false,
|
|
||||||
message: "booting"
|
message: "booting"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
const { loaded } = this.props;
|
||||||
|
if (!loaded) {
|
||||||
this.setState({
|
this.setState({
|
||||||
message: "loading plugin information"
|
message: "loading plugin information"
|
||||||
});
|
});
|
||||||
|
|
||||||
this.getPlugins(this.props.link);
|
this.getPlugins(this.props.link);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getPlugins = (link: string): Promise<any> => {
|
getPlugins = (link: string): Promise<any> => {
|
||||||
return apiClient
|
return apiClient
|
||||||
@@ -43,11 +46,7 @@ class PluginLoader extends React.Component<Props, State> {
|
|||||||
.then(JSON.parse)
|
.then(JSON.parse)
|
||||||
.then(pluginCollection => pluginCollection._embedded.plugins)
|
.then(pluginCollection => pluginCollection._embedded.plugins)
|
||||||
.then(this.loadPlugins)
|
.then(this.loadPlugins)
|
||||||
.then(() => {
|
.then(this.props.callback);
|
||||||
this.setState({
|
|
||||||
finished: true
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
loadPlugins = (plugins: Plugin[]) => {
|
loadPlugins = (plugins: Plugin[]) => {
|
||||||
@@ -87,8 +86,9 @@ class PluginLoader extends React.Component<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { message, finished } = this.state;
|
const { loaded } = this.props;
|
||||||
if (finished) {
|
const { message } = this.state;
|
||||||
|
if (loaded) {
|
||||||
return <div>{this.props.children}</div>;
|
return <div>{this.props.children}</div>;
|
||||||
}
|
}
|
||||||
return <Loading message={message} />;
|
return <Loading message={message} />;
|
||||||
|
|||||||
Reference in New Issue
Block a user