1
0
mirror of https://github.com/spacebarchat/client.git synced 2024-11-22 02:12:38 +01:00

house keeping

This commit is contained in:
Puyodead1 2024-04-01 15:13:49 -04:00
parent fe6961acc2
commit 4b021ecafa
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC
6 changed files with 132 additions and 48 deletions

View File

@ -11,7 +11,6 @@ import { arch, locale, platform, version } from "@tauri-apps/plugin-os";
import { reaction } from "mobx";
import ErrorBoundary from "./components/ErrorBoundary";
import Loader from "./components/Loader";
import OfflineBanner from "./components/banners/OfflineBanner";
import { UnauthenticatedGuard } from "./components/guards/UnauthenticatedGuard";
import { BannerContext } from "./contexts/BannerContext";
import useLogger from "./hooks/useLogger";
@ -22,6 +21,7 @@ import { useAppStore } from "./stores/AppStore";
import { Globals } from "./utils/Globals";
// @ts-expect-error no types
import FPSStats from "react-fps-stats";
import VeryImportantBanner from "./components/banners/VeryImportantBanner";
import { isTauri } from "./utils/Utils";
function App() {
@ -69,6 +69,13 @@ function App() {
};
};
const hasVeryImportantBannerShown = localStorage.getItem("very_important_banner_dismissed");
if (!hasVeryImportantBannerShown) {
bannerContext.setContent({
element: <VeryImportantBanner />,
});
}
isTauri && loadAsyncGlobals();
Globals.load();
app.loadSettings();
@ -79,14 +86,14 @@ function App() {
return dispose;
}, []);
React.useEffect(() => {
if (!app.isNetworkConnected)
bannerContext.setContent({
forced: true,
element: <OfflineBanner />,
});
else bannerContext.close();
}, [app.isNetworkConnected, bannerContext]);
// React.useEffect(() => {
// if (!app.isNetworkConnected)
// bannerContext.setContent({
// forced: true,
// element: <OfflineBanner />,
// });
// else bannerContext.close();
// }, [app.isNetworkConnected, bannerContext]);
return (
<ErrorBoundary section="app">

View File

@ -21,48 +21,48 @@ function Banner() {
const logger = useLogger("Banner");
const bannerContext = React.useContext(BannerContext);
if (!bannerContext.content) return null;
return (
<AnimatePresence>
{bannerContext.content && (
<Container
variants={{
show: {
// slide down
y: 0,
transition: {
delayChildren: 0.3,
staggerChildren: 0.2,
},
<Container
variants={{
show: {
// slide down
y: 0,
transition: {
delayChildren: 0.3,
staggerChildren: 0.2,
},
hide: {
// slide up
y: "-100%",
transition: {
delayChildren: 0.3,
staggerChildren: 0.2,
},
},
hide: {
// slide up
y: "-100%",
transition: {
delayChildren: 0.3,
staggerChildren: 0.2,
},
}}
initial="hide"
animate="show"
exit="hide"
onAnimationComplete={() => {
logger.debug("animation complete");
}}
style={bannerContext.content.style}
>
{bannerContext.content.element}
{!bannerContext.content.forced && (
<CloseWrapper
onClick={() => {
bannerContext.close();
}}
>
<Icon icon="mdiClose" color="var(--text)" size="24px" />
</CloseWrapper>
)}
</Container>
)}
},
}}
initial="hide"
animate="show"
exit="hide"
onAnimationComplete={() => {
logger.debug("animation complete");
}}
style={bannerContext.content.style}
>
{bannerContext.content.element}
{!bannerContext.content.forced && (
<CloseWrapper
onClick={() => {
bannerContext.close();
}}
>
<Icon icon="mdiClose" color="var(--text)" size="24px" />
</CloseWrapper>
)}
</Container>
</AnimatePresence>
);
}

View File

@ -0,0 +1,39 @@
import styled from "styled-components";
import { modalController } from "../../controllers/modals";
import Button from "../Button";
const Wrapper = styled.div`
display: flex;
flex-direction: row;
background-color: var(--primary);
flex: 1;
justify-content: center;
align-items: center;
`;
const Text = styled.span`
padding: 10px;
`;
function VeryImportantBanner() {
return (
<Wrapper>
<Text>We have a suprise for you!</Text>
<Button
onClick={() => {
modalController.push({
type: "very_important",
});
}}
style={{
backgroundColor: "var(--primary-light)",
border: "1px solid var(--primary-dark)",
}}
>
Show me
</Button>
</Wrapper>
);
}
export default VeryImportantBanner;

View File

@ -0,0 +1,36 @@
import { useContext } from "react";
import styled from "styled-components";
import { BannerContext } from "../../contexts/BannerContext";
import { ModalProps } from "../../controllers/modals/types";
import { Modal } from "./ModalComponents";
const Text = styled.span`
padding: 10px;
justify-content: center;
align-items: center;
display: flex;
flex: 1;
`;
export function VeryImportantModal({ ...props }: ModalProps<"very_important">) {
const bannerContext = useContext(BannerContext);
return (
<Modal
{...props}
actions={[
{
onClick: () => {
localStorage.setItem("very_important_banner_dismissed", "true");
bannerContext.close();
return true;
},
confirmation: true,
children: <span>I've been clowned</span>,
palette: "primary",
},
]}
>
<Text>April fools! 🤡</Text>
</Modal>
);
}

View File

@ -15,6 +15,7 @@ import {
LeaveServerModal,
SettingsModal,
} from "../../components/modals";
import { VeryImportantModal } from "../../components/modals/VeryImportantModal";
import { Modal } from "./types";
function randomUUID() {
@ -187,4 +188,5 @@ export const modalController = new ModalControllerExtended({
// modify_displayname: ModifyDisplayname,
// changelog_usernames: ChangelogUsernames,
settings: SettingsModal,
very_important: VeryImportantModal,
});

View File

@ -10,7 +10,7 @@ export type Modal = {
key?: string;
} & (
| {
type: "add_server" | "create_server" | "join_server" | "settings";
type: "add_server" | "create_server" | "join_server" | "settings" | "very_important";
}
| {
type: "error";