revite/src/pages/home/Home.tsx

175 lines
5.8 KiB
TypeScript
Raw Normal View History

2021-07-05 06:23:23 -04:00
import { Home as HomeIcon } from "@styled-icons/boxicons-solid";
2021-06-19 15:24:11 -04:00
import { Link } from "react-router-dom";
2021-09-15 09:53:40 -04:00
import styled, { css } from "styled-components";
2021-06-19 15:24:11 -04:00
2021-07-05 06:23:23 -04:00
import styles from "./Home.module.scss";
2021-12-23 08:16:43 -05:00
import "./snow.scss";
2021-06-19 15:24:11 -04:00
import { Text } from "preact-i18n";
2021-12-23 08:16:43 -05:00
import { useContext, useMemo, useState } from "preact/hooks";
2021-09-15 09:53:40 -04:00
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
import { dispatch, getState } from "../../redux";
2021-07-05 06:23:23 -04:00
import { AppContext } from "../../context/revoltjs/RevoltClient";
import wideSVG from "../../../public/assets/wide.svg";
2021-08-17 08:52:02 -04:00
import Emoji from "../../components/common/Emoji";
import Tooltip from "../../components/common/Tooltip";
2021-06-19 15:24:11 -04:00
import Header from "../../components/ui/Header";
2021-08-17 08:52:02 -04:00
import CategoryButton from "../../components/ui/fluent/CategoryButton";
const CHANNELS_SIDEBAR_KEY = "sidebar_channels";
const IconConainer = styled.div`
cursor: pointer;
color: var(--secondary-foreground);
2021-09-15 09:53:40 -04:00
${!isTouchscreenDevice &&
css`
&:hover {
color: var(--foreground);
}
`}
2021-09-15 09:53:40 -04:00
`;
2021-12-23 08:16:43 -05:00
const Overlay = styled.div`
display: grid;
height: 100%;
> * {
grid-area: 1 / 1;
}
.content {
z-index: 1;
}
`;
2021-06-19 07:34:53 -04:00
export default function Home() {
const client = useContext(AppContext);
const [showChannels, setChannels] = useState(
getState().sectionToggle[CHANNELS_SIDEBAR_KEY] ?? true,
);
const toggleChannelSidebar = () => {
if (isTouchscreenDevice) {
2021-09-15 09:53:40 -04:00
return;
}
setChannels(!showChannels);
if (showChannels) {
dispatch({
type: "SECTION_TOGGLE_SET",
id: CHANNELS_SIDEBAR_KEY,
state: false,
});
} else {
dispatch({
type: "SECTION_TOGGLE_UNSET",
id: CHANNELS_SIDEBAR_KEY,
});
}
2021-09-15 09:53:40 -04:00
};
2021-12-23 08:16:43 -05:00
const snowflakes = useMemo(() => {
const flakes = [];
// Disable outside of December
if (new Date().getMonth() !== 11) return [];
for (let i = 0; i < 15; i++) {
flakes.push("❄️");
flakes.push("❄");
}
for (let i = 0; i < 2; i++) {
flakes.push("🎄");
flakes.push("☃️");
flakes.push("⛄");
}
return flakes;
}, []);
2021-07-05 06:25:20 -04:00
return (
<div className={styles.home}>
2021-12-23 08:16:43 -05:00
<Overlay>
<div class="snowfall">
{snowflakes.map((emoji, index) => (
<div key={index} class="snowflake">
{emoji}
</div>
))}
</div>
<div class="content">
<Header placement="primary">
<IconConainer onClick={toggleChannelSidebar}>
<HomeIcon size={24} />
</IconConainer>
<Text id="app.navigation.tabs.home" />
</Header>
<h3>
<Text id="app.special.modals.onboarding.welcome" />
<br />
<img src={wideSVG} />
</h3>
<div className={styles.actions}>
<Link to="/invite/Testers">
<CategoryButton
action="chevron"
icon={<Emoji emoji="😁" size={32} />}>
{client.servers.get(
"01F7ZSBSFHQ8TA81725KQCSDDP",
) ? (
<Text id="app.home.goto-testers" />
) : (
<Text id="app.home.join-testers" />
)}
</CategoryButton>
</Link>
<a
href="https://insrt.uk/donate"
target="_blank"
rel="noreferrer">
<CategoryButton
action="external"
icon={<Emoji emoji="💷" size={32} />}>
<Text id="app.home.donate" />
</CategoryButton>
</a>
<Link to="/settings/feedback">
<CategoryButton
action="chevron"
icon={<Emoji emoji="🎉" size={32} />}>
<Text id="app.home.feedback" />
</CategoryButton>
</Link>
<a
href="https://revolt.social"
target="_blank"
rel="noreferrer">
<CategoryButton
action="external"
icon={<Emoji emoji="🧭" size={32} />}>
<Text id="app.home.social" />
</CategoryButton>
</a>
<Tooltip
content={<Text id="app.home.settings-tooltip" />}>
<Link to="/settings">
<CategoryButton
action="chevron"
icon={<Emoji emoji="🔧" size={32} />}>
<Text id="app.home.settings" />
</CategoryButton>
</Link>
</Tooltip>
</div>
</div>
</Overlay>
2021-07-05 06:25:20 -04:00
</div>
);
2021-06-19 07:34:53 -04:00
}