mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-26 00:50:56 -05:00
feat: add Revolt discover (note: has CORS issues)
This commit is contained in:
parent
56925b3ea2
commit
abecd0ec11
7 changed files with 172 additions and 33 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
import { Route, Switch } from "react-router";
|
import { Route, Switch } from "react-router";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
|
|
||||||
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
|
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
|
||||||
|
|
||||||
|
@ -13,8 +14,10 @@ import ServerSidebar from "./left/ServerSidebar";
|
||||||
|
|
||||||
export default observer(() => {
|
export default observer(() => {
|
||||||
const layout = useApplicationState().layout;
|
const layout = useApplicationState().layout;
|
||||||
|
const { pathname } = useLocation();
|
||||||
const isOpen =
|
const isOpen =
|
||||||
isTouchscreenDevice || layout.getSectionState(SIDEBAR_CHANNELS, true);
|
!pathname.startsWith("/discover") &&
|
||||||
|
(isTouchscreenDevice || layout.getSectionState(SIDEBAR_CHANNELS, true));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarBase>
|
<SidebarBase>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Plus, LinkExternal } from "@styled-icons/boxicons-regular";
|
import { Plus } from "@styled-icons/boxicons-regular";
|
||||||
import { Cog, Compass } from "@styled-icons/boxicons-solid";
|
import { Cog, Compass } from "@styled-icons/boxicons-solid";
|
||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
import { Link, useHistory, useLocation, useParams } from "react-router-dom";
|
import { Link, useHistory, useLocation, useParams } from "react-router-dom";
|
||||||
|
@ -249,7 +249,9 @@ export default observer(() => {
|
||||||
).length;
|
).length;
|
||||||
|
|
||||||
const homeActive =
|
const homeActive =
|
||||||
typeof server === "undefined" && !path.startsWith("/invite");
|
typeof server === "undefined" &&
|
||||||
|
!path.startsWith("/invite") &&
|
||||||
|
!path.startsWith("/discover");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ServersBase>
|
<ServersBase>
|
||||||
|
@ -386,7 +388,7 @@ export default observer(() => {
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</ServerCircle>
|
</ServerCircle>
|
||||||
{/*<ServerCircle>
|
<ServerCircle>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content={
|
content={
|
||||||
<div
|
<div
|
||||||
|
@ -395,22 +397,21 @@ export default observer(() => {
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
gap: "4px",
|
gap: "4px",
|
||||||
}}>
|
}}>
|
||||||
<div>Discover Public Servers</div>
|
<div>Discover Revolt</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
placement="right">
|
placement="right">
|
||||||
<div className="circle">
|
<div className="circle">
|
||||||
<IconButton>
|
<IconButton>
|
||||||
<a
|
<Link to="/discover">
|
||||||
href="#"
|
<a>
|
||||||
target="_blank"
|
<Compass size={32} />
|
||||||
rel="noreferrer">
|
</a>
|
||||||
<Compass size={32} />
|
</Link>
|
||||||
</a>
|
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</ServerCircle>*/}
|
</ServerCircle>
|
||||||
</ServerList>
|
</ServerList>
|
||||||
<PaintCounter small />
|
<PaintCounter small />
|
||||||
{!isTouchscreenDevice && (
|
{!isTouchscreenDevice && (
|
||||||
|
|
|
@ -27,7 +27,7 @@ export default class Layout implements Store, Persistent<Data> {
|
||||||
* The last 'major section' that the user had open.
|
* The last 'major section' that the user had open.
|
||||||
* This is either the home tab or a channel ID (for a server channel).
|
* This is either the home tab or a channel ID (for a server channel).
|
||||||
*/
|
*/
|
||||||
private lastSection: "home" | string;
|
private lastSection: "home" | "discover" | string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The last path the user had open in the home tab.
|
* The last path the user had open in the home tab.
|
||||||
|
@ -143,9 +143,19 @@ export default class Layout implements Store, Persistent<Data> {
|
||||||
* @returns Last path
|
* @returns Last path
|
||||||
*/
|
*/
|
||||||
@computed getLastPath() {
|
@computed getLastPath() {
|
||||||
return this.lastSection === "home"
|
return this.lastSection === "discover"
|
||||||
? this.lastHomePath
|
? "/discover"
|
||||||
: this.getLastOpened(this.lastSection);
|
: this.lastSection === "home"
|
||||||
|
? this.lastHomePath!
|
||||||
|
: this.getLastOpened(this.lastSection)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the last opened section.
|
||||||
|
* @param section Section name
|
||||||
|
*/
|
||||||
|
@action setLastSection(section: string) {
|
||||||
|
this.lastSection = section;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,6 +19,7 @@ import RightSidebar from "../components/navigation/RightSidebar";
|
||||||
import Open from "./Open";
|
import Open from "./Open";
|
||||||
import Channel from "./channels/Channel";
|
import Channel from "./channels/Channel";
|
||||||
import Developer from "./developer/Developer";
|
import Developer from "./developer/Developer";
|
||||||
|
import Discover from "./discover/Discover";
|
||||||
import Friends from "./friends/Friends";
|
import Friends from "./friends/Friends";
|
||||||
import Home from "./home/Home";
|
import Home from "./home/Home";
|
||||||
import InviteBot from "./invite/InviteBot";
|
import InviteBot from "./invite/InviteBot";
|
||||||
|
@ -82,6 +83,7 @@ export default function App() {
|
||||||
path === "/" || path === "/settings" || path.startsWith("/friends");
|
path === "/" || path === "/settings" || path.startsWith("/friends");
|
||||||
const inChannel = path.includes("/channel");
|
const inChannel = path.includes("/channel");
|
||||||
const inServer = path.includes("/server");
|
const inServer = path.includes("/server");
|
||||||
|
const inDiscover = path.startsWith("/discover");
|
||||||
const inSpecial =
|
const inSpecial =
|
||||||
(path.startsWith("/friends") && isTouchscreenDevice) ||
|
(path.startsWith("/friends") && isTouchscreenDevice) ||
|
||||||
path.startsWith("/invite") ||
|
path.startsWith("/invite") ||
|
||||||
|
@ -116,7 +118,11 @@ export default function App() {
|
||||||
}
|
}
|
||||||
bottomNav={{
|
bottomNav={{
|
||||||
component: <BottomNavigation />,
|
component: <BottomNavigation />,
|
||||||
showIf: fixedBottomNav ? ShowIf.Always : ShowIf.Left,
|
showIf: inDiscover
|
||||||
|
? 0
|
||||||
|
: fixedBottomNav
|
||||||
|
? ShowIf.Always
|
||||||
|
: ShowIf.Left,
|
||||||
height: 50,
|
height: 50,
|
||||||
}}
|
}}
|
||||||
docked={isTouchscreenDevice ? Docked.None : Docked.Left}>
|
docked={isTouchscreenDevice ? Docked.None : Docked.Left}>
|
||||||
|
@ -172,6 +178,8 @@ export default function App() {
|
||||||
/>
|
/>
|
||||||
<Route path="/settings" component={Settings} />
|
<Route path="/settings" component={Settings} />
|
||||||
|
|
||||||
|
<Route path="/discover" component={Discover} />
|
||||||
|
|
||||||
<Route path="/dev" component={Developer} />
|
<Route path="/dev" component={Developer} />
|
||||||
<Route path="/friends" component={Friends} />
|
<Route path="/friends" component={Friends} />
|
||||||
<Route path="/open/:id" component={Open} />
|
<Route path="/open/:id" component={Open} />
|
||||||
|
|
109
src/pages/discover/Discover.tsx
Normal file
109
src/pages/discover/Discover.tsx
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
import { LeftArrowAlt } from "@styled-icons/boxicons-regular";
|
||||||
|
import { Compass } from "@styled-icons/boxicons-solid";
|
||||||
|
import { useHistory } from "react-router-dom";
|
||||||
|
import styled, { css } from "styled-components";
|
||||||
|
|
||||||
|
import { useEffect, useState } from "preact/hooks";
|
||||||
|
|
||||||
|
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
|
||||||
|
|
||||||
|
import { useApplicationState } from "../../mobx/State";
|
||||||
|
|
||||||
|
import { useIntermediate } from "../../context/intermediate/Intermediate";
|
||||||
|
|
||||||
|
import Header from "../../components/ui/Header";
|
||||||
|
import IconButton from "../../components/ui/IconButton";
|
||||||
|
import Preloader from "../../components/ui/Preloader";
|
||||||
|
|
||||||
|
const Container = styled.div`
|
||||||
|
flex-grow: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
${() =>
|
||||||
|
isTouchscreenDevice
|
||||||
|
? css`
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
position: fixed;
|
||||||
|
background: var(--background);
|
||||||
|
`
|
||||||
|
: css`
|
||||||
|
background: var(--secondary-background);
|
||||||
|
`}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Frame = styled.iframe<{ loaded: boolean }>`
|
||||||
|
border: 0;
|
||||||
|
|
||||||
|
${(props) =>
|
||||||
|
props.loaded
|
||||||
|
? css`
|
||||||
|
flex-grow: 1;
|
||||||
|
`
|
||||||
|
: css`
|
||||||
|
display: none;
|
||||||
|
`}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Loader = styled.div`
|
||||||
|
flex-grow: 1;
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default function Discover() {
|
||||||
|
const layout = useApplicationState().layout;
|
||||||
|
const { openLink } = useIntermediate();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
|
const [loaded, setLoaded] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => layout.setLastSection("discover"), []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function onMessage(message: MessageEvent) {
|
||||||
|
let data = JSON.parse(message.data);
|
||||||
|
if (data.source === "discover") {
|
||||||
|
switch (data.type) {
|
||||||
|
case "navigate": {
|
||||||
|
openLink(data.url);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("message", onMessage);
|
||||||
|
return () => window.removeEventListener("message", onMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container>
|
||||||
|
{isTouchscreenDevice && (
|
||||||
|
<Header placement="primary">
|
||||||
|
<IconButton
|
||||||
|
onClick={() => history.push(layout.getLastPath())}>
|
||||||
|
<LeftArrowAlt
|
||||||
|
size={27}
|
||||||
|
style={{ marginInlineEnd: "8px" }}
|
||||||
|
/>
|
||||||
|
</IconButton>
|
||||||
|
<Compass size={27} />
|
||||||
|
Discover
|
||||||
|
</Header>
|
||||||
|
)}
|
||||||
|
{!loaded && (
|
||||||
|
<Loader>
|
||||||
|
<Preloader type="ring" />
|
||||||
|
</Loader>
|
||||||
|
)}
|
||||||
|
<Frame
|
||||||
|
loaded={loaded}
|
||||||
|
crossOrigin="anonymous"
|
||||||
|
onLoad={() => setLoaded(true)}
|
||||||
|
src="https://rvlt.gg/discover/servers?embedded=true"
|
||||||
|
/>
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
|
@ -103,19 +103,18 @@ export default observer(() => {
|
||||||
Create a group
|
Create a group
|
||||||
</CategoryButton>
|
</CategoryButton>
|
||||||
</Link>
|
</Link>
|
||||||
{/*<a
|
<Link to="/discover">
|
||||||
href="#"
|
<a>
|
||||||
target="_blank"
|
<CategoryButton
|
||||||
rel="noreferrer">
|
action="chevron"
|
||||||
<CategoryButton
|
icon={<Compass size={32} />}
|
||||||
action="external"
|
description={
|
||||||
icon={<Compass size={32} />}
|
"Find a community based on your hobbies or interests."
|
||||||
description={
|
}>
|
||||||
"Find a community based on your hobbies or interests."
|
Join a community
|
||||||
}>
|
</CategoryButton>
|
||||||
Join a community
|
</a>
|
||||||
</CategoryButton>
|
</Link>
|
||||||
</a>*/}
|
|
||||||
|
|
||||||
{client.servers.get(
|
{client.servers.get(
|
||||||
"01F7ZSBSFHQ8TA81725KQCSDDP",
|
"01F7ZSBSFHQ8TA81725KQCSDDP",
|
||||||
|
|
|
@ -30,6 +30,8 @@ export default function Invite() {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const client = useContext(AppContext);
|
const client = useContext(AppContext);
|
||||||
|
|
||||||
|
const layout = useApplicationState().layout;
|
||||||
|
|
||||||
const status = useContext(StatusContext);
|
const status = useContext(StatusContext);
|
||||||
const { code } = useParams<{ code: string }>();
|
const { code } = useParams<{ code: string }>();
|
||||||
const [processing, setProcessing] = useState(false);
|
const [processing, setProcessing] = useState(false);
|
||||||
|
@ -47,7 +49,7 @@ export default function Invite() {
|
||||||
}
|
}
|
||||||
}, [client, code, invite, status]);
|
}, [client, code, invite, status]);
|
||||||
|
|
||||||
if (code === undefined) return <Redirect to="/" />;
|
if (code === undefined) return <Redirect to={layout.getLastPath()} />;
|
||||||
|
|
||||||
if (typeof invite === "undefined") {
|
if (typeof invite === "undefined") {
|
||||||
return (
|
return (
|
||||||
|
@ -72,7 +74,11 @@ export default function Invite() {
|
||||||
<Button contrast>
|
<Button contrast>
|
||||||
<ArrowBack
|
<ArrowBack
|
||||||
size={32}
|
size={32}
|
||||||
onClick={() => history.push("/")}
|
onClick={() =>
|
||||||
|
history.push(
|
||||||
|
layout.getLastPath(),
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -95,7 +101,10 @@ export default function Invite() {
|
||||||
: undefined,
|
: undefined,
|
||||||
}}>
|
}}>
|
||||||
<div className={styles.leave}>
|
<div className={styles.leave}>
|
||||||
<ArrowBack size={32} onClick={() => history.push("/")} />
|
<ArrowBack
|
||||||
|
size={32}
|
||||||
|
onClick={() => history.push(layout.getLastPath())}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!processing && (
|
{!processing && (
|
||||||
|
|
Loading…
Reference in a new issue