shellphone.app/app/messages/pages/messages.tsx

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-08-01 16:28:47 +00:00
import { Suspense, useEffect } from "react";
2021-08-01 16:52:23 +00:00
import dynamic from "next/dynamic";
import type { BlitzPage } from "blitz";
2021-08-01 03:05:40 +00:00
import { Routes } from "blitz";
2021-08-01 16:52:23 +00:00
import { atom, useAtom } from "jotai";
2021-07-31 14:33:18 +00:00
import Layout from "../../core/layouts/layout";
import ConversationsList from "../components/conversations-list";
2021-08-01 07:40:18 +00:00
import NewMessageButton from "../components/new-message-button";
import useRequireOnboarding from "../../core/hooks/use-require-onboarding";
2021-08-01 16:28:47 +00:00
import useNotifications from "../../core/hooks/use-notifications";
2021-07-31 14:33:18 +00:00
const Messages: BlitzPage = () => {
useRequireOnboarding();
2021-08-01 16:28:47 +00:00
const { subscription, subscribe } = useNotifications();
2021-08-01 07:40:18 +00:00
const setIsOpen = useAtom(bottomSheetOpenAtom)[1];
2021-07-31 14:33:18 +00:00
2021-08-01 16:28:47 +00:00
useEffect(() => {
if (!subscription) {
subscribe();
}
}, [subscription?.endpoint]);
2021-07-31 14:33:18 +00:00
return (
2021-08-01 03:05:40 +00:00
<>
2021-07-31 14:33:18 +00:00
<div className="flex flex-col space-y-6 p-6">
2021-08-01 07:40:18 +00:00
<h2 className="text-3xl font-bold">Messages</h2>
2021-07-31 14:33:18 +00:00
</div>
<Suspense fallback="Loading...">
<ConversationsList />
</Suspense>
2021-08-01 07:40:18 +00:00
<NewMessageButton onClick={() => setIsOpen(true)} />
<NewMessageBottomSheet />
2021-08-01 03:05:40 +00:00
</>
);
};
2021-07-31 14:33:18 +00:00
2021-08-01 16:52:23 +00:00
const NewMessageBottomSheet = dynamic(() => import("../components/new-message-bottom-sheet"), {
ssr: false,
loading: () => null,
});
export const bottomSheetOpenAtom = atom(false);
2021-08-01 03:05:40 +00:00
Messages.getLayout = (page) => <Layout title="Messages">{page}</Layout>;
2021-08-01 10:36:32 +00:00
Messages.authenticate = { redirectTo: Routes.SignIn().pathname };
2021-07-31 14:33:18 +00:00
export default Messages;