Improve load default store in home

This commit is contained in:
Yang Luo 2023-07-16 10:36:13 +08:00
parent ac76b1fb9b
commit 5dd0581a0e
4 changed files with 35 additions and 3 deletions

View File

@ -393,7 +393,7 @@ class App extends Component {
textAlign: "center", textAlign: "center",
} }
}> }>
Made with <span style={{color: "rgb(255, 255, 255)"}}></span> by <a style={{fontWeight: "bold", color: "black"}} target="_blank" rel="noreferrer" href="https://github.com/casbin/casibase">Casibase</a>, {Setting.isMobile() ? "Mobile" : "Desktop"} View Powered by <a style={{fontWeight: "bold", color: "black"}} target="_blank" rel="noreferrer" href="https://github.com/casbin/casibase">Casibase</a>
</Footer> </Footer>
); );
} }

View File

@ -252,6 +252,10 @@ class FileTree extends React.Component {
} }
isFileOk(file, action) { isFileOk(file, action) {
if (this.props.account.isAdmin) {
return true;
}
if (this.state.permissionMap === null) { if (this.state.permissionMap === null) {
return false; return false;
} }

View File

@ -11,7 +11,7 @@ class FileTreePage extends React.Component {
this.state = { this.state = {
classes: props, classes: props,
owner: props.match?.params?.owner !== undefined ? props.match.params.owner : "admin", owner: props.match?.params?.owner !== undefined ? props.match.params.owner : "admin",
storeName: props.match?.params?.storeName !== undefined ? props.match.params.storeName : "default", storeName: props.match?.params?.storeName !== undefined ? props.match.params.storeName : this.props.storeName,
store: null, store: null,
}; };
} }

View File

@ -1,20 +1,48 @@
import React from "react"; import React from "react";
import FileTreePage from "./FileTreePage"; import FileTreePage from "./FileTreePage";
import {Redirect} from "react-router-dom"; import {Redirect} from "react-router-dom";
import * as StoreBackend from "./backend/StoreBackend";
import * as Setting from "./Setting";
class HomePage extends React.Component { class HomePage extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
classes: props, classes: props,
store: null,
}; };
} }
UNSAFE_componentWillMount() {
this.getStores();
}
getStores() {
StoreBackend.getGlobalStores()
.then((res) => {
if (res.status === "ok") {
const stores = res.data;
const store = stores.filter(store => store.domain !== "https://cdn.example.com")[0];
if (store !== undefined) {
this.setState({
store: store,
});
}
} else {
Setting.showMessage("error", `Failed to get stores: ${res.msg}`);
}
});
}
render() { render() {
if (this.props.account.tag === "Video") { if (this.props.account.tag === "Video") {
return <Redirect to="/videos" />; return <Redirect to="/videos" />;
} else { } else {
return <FileTreePage account={this.props.account} />; if (this.state.store === null) {
return null;
} else {
return <FileTreePage account={this.props.account} storeName={this.state.store.name} />;
}
} }
} }
} }