2019-09-18 19:52:39 +02:00
|
|
|
import React, { Component } from "react";
|
|
|
|
import { MuiThemeProvider, CssBaseline, withStyles } from "@material-ui/core";
|
|
|
|
import { setHyperspaceTheme, darkMode } from "./utilities/themes";
|
|
|
|
import AppLayout from "./components/AppLayout";
|
|
|
|
import { styles } from "./App.styles";
|
2019-10-03 17:16:21 +02:00
|
|
|
import { Route, withRouter } from "react-router-dom";
|
2019-09-18 19:52:39 +02:00
|
|
|
import AboutPage from "./pages/About";
|
|
|
|
import Settings from "./pages/Settings";
|
|
|
|
import { getUserDefaultBool, getUserDefaultTheme } from "./utilities/settings";
|
|
|
|
import ProfilePage from "./pages/ProfilePage";
|
2020-01-07 17:24:53 +01:00
|
|
|
import TimelinePage from "./pages/Timeline";
|
2019-09-18 19:52:39 +02:00
|
|
|
import Conversation from "./pages/Conversation";
|
|
|
|
import NotificationsPage from "./pages/Notifications";
|
2020-03-13 21:41:45 +01:00
|
|
|
import AnnouncementsPage from "./pages/Announcements";
|
2019-09-18 19:52:39 +02:00
|
|
|
import SearchPage from "./pages/Search";
|
|
|
|
import Composer from "./pages/Compose";
|
|
|
|
import WelcomePage from "./pages/Welcome";
|
|
|
|
import MessagesPage from "./pages/Messages";
|
|
|
|
import RecommendationsPage from "./pages/Recommendations";
|
2019-09-23 20:00:11 +02:00
|
|
|
import Blocked from "./pages/Blocked";
|
2019-09-18 19:52:39 +02:00
|
|
|
import You from "./pages/You";
|
2019-11-01 22:51:30 +01:00
|
|
|
import RequestsPage from "./pages/Requests";
|
2019-11-01 23:41:33 +01:00
|
|
|
import ActivityPage from "./pages/Activity";
|
2019-09-18 19:52:39 +02:00
|
|
|
import { withSnackbar } from "notistack";
|
|
|
|
import { PrivateRoute } from "./interfaces/overrides";
|
|
|
|
import { userLoggedIn } from "./utilities/accounts";
|
|
|
|
import { isDarwinApp } from "./utilities/desktop";
|
2019-03-27 22:39:25 +01:00
|
|
|
let theme = setHyperspaceTheme(getUserDefaultTheme());
|
2019-03-28 00:24:52 +01:00
|
|
|
|
2019-10-03 17:16:21 +02:00
|
|
|
interface IAppState {
|
|
|
|
theme: any;
|
|
|
|
showLayout: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
class App extends Component<any, IAppState> {
|
2019-09-18 19:52:39 +02:00
|
|
|
offline: any;
|
2019-10-03 17:16:21 +02:00
|
|
|
unlisten: any;
|
2019-03-26 02:37:02 +01:00
|
|
|
|
2019-09-18 19:52:39 +02:00
|
|
|
constructor(props: any) {
|
|
|
|
super(props);
|
2019-03-30 22:13:49 +01:00
|
|
|
|
2019-09-18 19:52:39 +02:00
|
|
|
this.state = {
|
2019-10-03 17:16:21 +02:00
|
|
|
theme: theme,
|
|
|
|
showLayout:
|
|
|
|
userLoggedIn() && !window.location.hash.includes("#/welcome")
|
2019-09-18 19:52:39 +02:00
|
|
|
};
|
2019-03-27 22:39:25 +01:00
|
|
|
}
|
|
|
|
|
2019-09-18 19:52:39 +02:00
|
|
|
componentWillMount() {
|
|
|
|
let newTheme = darkMode(
|
|
|
|
this.state.theme,
|
|
|
|
getUserDefaultBool("darkModeEnabled")
|
|
|
|
);
|
2019-10-03 17:16:21 +02:00
|
|
|
this.setState({
|
|
|
|
theme: newTheme,
|
|
|
|
showLayout:
|
|
|
|
userLoggedIn() && !window.location.hash.includes("#/welcome")
|
|
|
|
});
|
2019-03-27 22:39:25 +01:00
|
|
|
}
|
|
|
|
|
2019-09-18 19:52:39 +02:00
|
|
|
componentDidMount() {
|
|
|
|
this.removeBodyBackground();
|
2019-10-03 17:16:21 +02:00
|
|
|
this.unlisten = this.props.history.listen(
|
|
|
|
(location: Location, action: any) => {
|
|
|
|
this.setState({
|
|
|
|
showLayout:
|
|
|
|
userLoggedIn() &&
|
|
|
|
!location.pathname.includes("/welcome")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2019-09-18 19:52:39 +02:00
|
|
|
}
|
2019-03-27 22:39:25 +01:00
|
|
|
|
2019-09-18 19:52:39 +02:00
|
|
|
componentDidUpdate() {
|
|
|
|
this.removeBodyBackground();
|
|
|
|
}
|
2019-05-17 17:42:30 +02:00
|
|
|
|
2019-10-03 17:16:21 +02:00
|
|
|
componentWillUnmount() {
|
|
|
|
this.unlisten();
|
|
|
|
}
|
2019-05-17 17:42:30 +02:00
|
|
|
|
2019-09-18 19:52:39 +02:00
|
|
|
removeBodyBackground() {
|
|
|
|
if (isDarwinApp()) {
|
|
|
|
document.body.style.backgroundColor = "transparent";
|
|
|
|
}
|
2019-05-17 17:42:30 +02:00
|
|
|
}
|
|
|
|
|
2019-09-18 19:52:39 +02:00
|
|
|
render() {
|
|
|
|
this.removeBodyBackground();
|
2019-04-07 23:25:39 +02:00
|
|
|
|
2019-09-18 19:52:39 +02:00
|
|
|
return (
|
|
|
|
<MuiThemeProvider theme={this.state.theme}>
|
|
|
|
<CssBaseline />
|
|
|
|
<Route path="/welcome" component={WelcomePage} />
|
|
|
|
<div>
|
2019-10-03 17:16:21 +02:00
|
|
|
{this.state.showLayout ? <AppLayout /> : null}
|
2020-01-07 17:24:53 +01:00
|
|
|
<PrivateRoute
|
|
|
|
exact
|
|
|
|
path="/"
|
|
|
|
render={(props: any) => (
|
|
|
|
<TimelinePage
|
|
|
|
{...props}
|
|
|
|
stream="/streaming/user"
|
|
|
|
timeline="/timelines/home"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<PrivateRoute
|
|
|
|
path="/home"
|
|
|
|
render={(props: any) => (
|
|
|
|
<TimelinePage
|
|
|
|
{...props}
|
|
|
|
stream="/streaming/user"
|
|
|
|
timeline="/timelines/home"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<PrivateRoute
|
|
|
|
path="/local"
|
|
|
|
render={(props: any) => (
|
|
|
|
<TimelinePage
|
|
|
|
{...props}
|
|
|
|
stream="/streaming/public/local"
|
|
|
|
timeline="/timelines/public?local=true"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<PrivateRoute
|
|
|
|
path="/public"
|
|
|
|
render={(props: any) => (
|
|
|
|
<TimelinePage
|
|
|
|
{...props}
|
|
|
|
stream="/streaming/public"
|
|
|
|
timeline="/timelines/public"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2019-09-18 19:52:39 +02:00
|
|
|
<PrivateRoute path="/messages" component={MessagesPage} />
|
2020-03-13 21:41:45 +01:00
|
|
|
<PrivateRoute
|
|
|
|
path="/announcements"
|
|
|
|
component={AnnouncementsPage}
|
|
|
|
/>
|
2019-09-18 19:52:39 +02:00
|
|
|
<PrivateRoute
|
|
|
|
path="/notifications"
|
|
|
|
component={NotificationsPage}
|
|
|
|
/>
|
|
|
|
<PrivateRoute
|
|
|
|
path="/profile/:profileId"
|
|
|
|
component={ProfilePage}
|
|
|
|
/>
|
|
|
|
<PrivateRoute
|
|
|
|
path="/conversation/:conversationId"
|
|
|
|
component={Conversation}
|
|
|
|
/>
|
|
|
|
<PrivateRoute path="/search" component={SearchPage} />
|
|
|
|
<PrivateRoute path="/settings" component={Settings} />
|
2019-10-03 17:16:21 +02:00
|
|
|
<PrivateRoute path="/blocked" component={Blocked} />
|
2019-09-18 19:52:39 +02:00
|
|
|
<PrivateRoute path="/you" component={You} />
|
|
|
|
<PrivateRoute path="/about" component={AboutPage} />
|
|
|
|
<PrivateRoute path="/compose" component={Composer} />
|
|
|
|
<PrivateRoute
|
|
|
|
path="/recommended"
|
|
|
|
component={RecommendationsPage}
|
|
|
|
/>
|
2019-11-01 22:51:30 +01:00
|
|
|
<PrivateRoute path="/requests" component={RequestsPage} />
|
2019-11-01 23:41:33 +01:00
|
|
|
<PrivateRoute path="/activity" component={ActivityPage} />
|
2019-09-18 19:52:39 +02:00
|
|
|
</div>
|
|
|
|
</MuiThemeProvider>
|
|
|
|
);
|
|
|
|
}
|
2019-03-25 20:53:33 +01:00
|
|
|
}
|
|
|
|
|
2019-10-03 17:16:21 +02:00
|
|
|
// @ts-ignore
|
|
|
|
export default withStyles(styles)(withSnackbar(withRouter(App)));
|