revite/src/pages/RevoltApp.tsx

231 lines
8.3 KiB
TypeScript
Raw Normal View History

import { Docked, OverlappingPanels, ShowIf } from "react-overlapping-panels";
import { Switch, Route, useLocation, Link } from "react-router-dom";
import styled, { css } from "styled-components/macro";
2021-06-19 07:34:53 -04:00
import { useEffect, useState } from "preact/hooks";
2021-06-19 15:24:11 -04:00
import ContextMenus from "../lib/ContextMenus";
2021-07-05 06:23:23 -04:00
import { isTouchscreenDevice } from "../lib/isTouchscreenDevice";
2021-08-01 13:11:18 -04:00
import { Titlebar } from "../components/native/Titlebar";
2021-07-05 06:23:23 -04:00
import BottomNavigation from "../components/navigation/BottomNavigation";
2021-06-19 10:29:04 -04:00
import LeftSidebar from "../components/navigation/LeftSidebar";
import RightSidebar from "../components/navigation/RightSidebar";
import { useSystemAlert } from "../updateWorker";
import Open from "./Open";
import Channel from "./channels/Channel";
2021-06-19 15:24:11 -04:00
import Developer from "./developer/Developer";
import Discover from "./discover/Discover";
2021-07-05 06:23:23 -04:00
import Friends from "./friends/Friends";
import Home from "./home/Home";
2021-08-12 11:07:41 -04:00
import InviteBot from "./invite/InviteBot";
2021-06-19 17:37:12 -04:00
import ChannelSettings from "./settings/ChannelSettings";
2021-07-05 06:23:23 -04:00
import ServerSettings from "./settings/ServerSettings";
import Settings from "./settings/Settings";
2021-06-19 15:00:30 -04:00
const AppContainer = styled.div`
background-size: cover !important;
background-position: center center !important;
`;
export const StatusBar = styled.div`
height: 40px;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
font-size: 13px;
//gap: 14px;
gap: 8px;
user-select: none;
.button {
padding: 5px;
border: 1px solid white;
border-radius: var(--border-radius);
}
a {
cursor: pointer;
color: var(--foreground);
}
.title {
flex-grow: 1;
text-align: center;
}
.actions {
gap: 12px;
display: flex;
padding-right: 4px;
}
`;
const Routes = styled.div.attrs({ "data-component": "routes" })<{
borders: boolean;
}>`
2021-07-05 06:25:20 -04:00
min-width: 0;
display: flex;
position: relative;
2021-07-05 06:25:20 -04:00
flex-direction: column;
2021-07-05 06:25:20 -04:00
background: var(--primary-background);
${() =>
isTouchscreenDevice &&
css`
overflow: hidden;
`}
${(props) =>
props.borders &&
css`
border-start-start-radius: 8px;
`}
2021-06-19 15:00:30 -04:00
`;
2021-06-19 07:34:53 -04:00
export default function App() {
2021-07-05 06:25:20 -04:00
const path = useLocation().pathname;
const fixedBottomNav =
2022-01-10 13:18:43 -05:00
path === "/" ||
path === "/settings" ||
path.startsWith("/friends") ||
path.startsWith("/discover");
2021-07-05 06:25:20 -04:00
const inChannel = path.includes("/channel");
const inServer = path.includes("/server");
2021-07-05 06:25:20 -04:00
const inSpecial =
(path.startsWith("/friends") && isTouchscreenDevice) ||
path.startsWith("/invite") ||
path.includes("/settings");
2021-07-05 06:23:23 -04:00
const alert = useSystemAlert();
2022-03-01 14:44:38 -05:00
const [statusBar, setStatusBar] = useState(false);
useEffect(() => setStatusBar(true), [alert]);
2021-07-05 06:25:20 -04:00
return (
2021-08-01 09:22:08 -04:00
<>
{alert && statusBar && (
<StatusBar>
<div className="title">{alert.text}</div>
<div className="actions">
{alert.actions?.map((action) =>
action.type === "internal" ? (
<Link to={action.href}>
<div className="button">{action.text}</div>
</Link>
) : action.type === "external" ? (
<a
href={action.href}
target="_blank"
rel="noreferrer">
<div className="button">{action.text}</div>{" "}
</a>
) : null,
)}
{alert.dismissable !== false && (
<a onClick={() => setStatusBar(false)}>
<div className="button">{"Dismiss"}</div>
</a>
)}
</div>
</StatusBar>
)}
<AppContainer>
{window.isNative && !window.native.getConfig().frame && (
<Titlebar />
)}
<OverlappingPanels
width="100vw"
height={
(alert && statusBar ? "calc(" : "") +
(window.isNative && !window.native.getConfig().frame
? "calc(var(--app-height) - var(--titlebar-height))"
: "var(--app-height)") +
(alert && statusBar ? " - 40px)" : "")
}
leftPanel={
inSpecial
? undefined
: { width: 290, component: <LeftSidebar /> }
}
rightPanel={
!inSpecial && inChannel
? { width: 236, component: <RightSidebar /> }
: undefined
}
bottomNav={{
component: <BottomNavigation />,
2022-01-10 13:18:43 -05:00
showIf: fixedBottomNav ? ShowIf.Always : ShowIf.Left,
height: 50,
}}
docked={isTouchscreenDevice ? Docked.None : Docked.Left}>
<Routes borders={inServer}>
<Switch>
<Route
path="/server/:server/channel/:channel/settings/:page"
component={ChannelSettings}
/>
<Route
path="/server/:server/channel/:channel/settings"
component={ChannelSettings}
/>
<Route
path="/server/:server/settings/:page"
component={ServerSettings}
/>
<Route
path="/server/:server/settings"
component={ServerSettings}
/>
<Route
path="/channel/:channel/settings/:page"
component={ChannelSettings}
/>
<Route
path="/channel/:channel/settings"
component={ChannelSettings}
/>
<Route
path="/channel/:channel/:message"
component={Channel}
/>
<Route
path="/server/:server/channel/:channel/:message"
component={Channel}
/>
2021-07-08 17:47:56 -04:00
<Route
path="/server/:server/channel/:channel"
component={Channel}
/>
<Route path="/server/:server" component={Channel} />
<Route
path="/channel/:channel"
component={Channel}
/>
<Route
path="/settings/:page"
component={Settings}
/>
<Route path="/settings" component={Settings} />
2021-06-19 15:24:11 -04:00
<Route path="/discover" component={Discover} />
<Route path="/dev" component={Developer} />
<Route path="/friends" component={Friends} />
<Route path="/open/:id" component={Open} />
<Route path="/bot/:id" component={InviteBot} />
<Route path="/" component={Home} />
</Switch>
</Routes>
<ContextMenus />
</OverlappingPanels>
</AppContainer>
2021-08-01 09:22:08 -04:00
</>
2021-07-05 06:25:20 -04:00
);
2021-07-05 06:23:23 -04:00
}