style: loading screens (#750)

* fix: dashboard workspace activity mutation

* style: loading screens
This commit is contained in:
Aaryan Khandelwal 2023-04-08 18:20:00 +05:30 committed by GitHub
parent 1026ae3eb1
commit c81bc4e5d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 95 additions and 85 deletions

View File

@ -10,12 +10,11 @@ import Container from "layouts/container";
import AppHeader from "layouts/app-layout/app-header"; import AppHeader from "layouts/app-layout/app-header";
import AppSidebar from "layouts/app-layout/app-sidebar"; import AppSidebar from "layouts/app-layout/app-sidebar";
import SettingsNavbar from "layouts/settings-navbar"; import SettingsNavbar from "layouts/settings-navbar";
import { WorkspaceAuthorizationLayout } from "./workspace-authorization-wrapper";
// components // components
import { NotAuthorizedView, JoinProject } from "components/auth-screens"; import { NotAuthorizedView, JoinProject } from "components/auth-screens";
import { CommandPalette } from "components/command-palette"; import { CommandPalette } from "components/command-palette";
// ui // ui
import { PrimaryButton } from "components/ui"; import { PrimaryButton, Spinner } from "components/ui";
// icons // icons
import { LayerDiagonalIcon } from "components/icons"; import { LayerDiagonalIcon } from "components/icons";
@ -63,82 +62,79 @@ const ProjectAuthorizationWrapped: React.FC<Props> = ({
const settingsLayout = router.pathname.includes("/settings"); const settingsLayout = router.pathname.includes("/settings");
return ( return (
<WorkspaceAuthorizationLayout> <Container meta={meta}>
<Container meta={meta}> <CommandPalette />
<CommandPalette /> <div className="flex h-screen w-full overflow-x-hidden">
<div className="flex h-screen w-full overflow-x-hidden"> <AppSidebar toggleSidebar={toggleSidebar} setToggleSidebar={setToggleSidebar} />
<AppSidebar toggleSidebar={toggleSidebar} setToggleSidebar={setToggleSidebar} /> {loading ? (
{loading ? ( <div className="h-full w-full grid place-items-center p-4">
<div className="container h-screen flex justify-center items-center p-4 text-2xl font-semibold"> <div className="flex flex-col items-center gap-3 text-center">
<p>Loading...</p> <h3 className="text-xl">Setting up your project...</h3>
<Spinner />
</div> </div>
) : error?.status === 401 || error?.status === 403 ? ( </div>
<JoinProject /> ) : error?.status === 401 || error?.status === 403 ? (
) : error?.status === 404 ? ( <JoinProject />
<div className="container h-screen grid place-items-center"> ) : error?.status === 404 ? (
<div className="text-center space-y-4"> <div className="container h-screen grid place-items-center">
<p className="text-2xl font-semibold">No such project exist. Create one?</p> <div className="text-center space-y-4">
<PrimaryButton <p className="text-2xl font-semibold">No such project exist. Create one?</p>
onClick={() => { <PrimaryButton
const e = new KeyboardEvent("keydown", { key: "p" }); onClick={() => {
document.dispatchEvent(e); const e = new KeyboardEvent("keydown", { key: "p" });
}} document.dispatchEvent(e);
> }}
Create project
</PrimaryButton>
</div>
</div>
) : settingsLayout && (memberType?.isGuest || memberType?.isViewer) ? (
<NotAuthorizedView
actionButton={
<Link href={`/${workspaceSlug}/projects/${projectId}/issues`}>
<a>
<PrimaryButton className="flex items-center gap-1">
<LayerDiagonalIcon height={16} width={16} color="white" /> Go to issues
</PrimaryButton>
</a>
</Link>
}
type="project"
/>
) : (
<main className="flex h-screen w-full min-w-0 flex-col overflow-y-auto">
{!noHeader && (
<AppHeader
breadcrumbs={breadcrumbs}
left={left}
right={right}
setToggleSidebar={setToggleSidebar}
/>
)}
<div
className={`flex w-full flex-grow flex-col ${
noPadding ? "" : settingsLayout ? "p-8 lg:px-28" : "p-8"
} ${
bg === "primary"
? "bg-primary"
: bg === "secondary"
? "bg-secondary"
: "bg-primary"
}`}
> >
{settingsLayout && ( Create project
<div className="mb-12 space-y-6"> </PrimaryButton>
<div> </div>
<h3 className="text-3xl font-semibold">Project Settings</h3> </div>
<p className="mt-1 text-gray-600"> ) : settingsLayout && (memberType?.isGuest || memberType?.isViewer) ? (
This information will be displayed to every member of the project. <NotAuthorizedView
</p> actionButton={
</div> <Link href={`/${workspaceSlug}/projects/${projectId}/issues`}>
<SettingsNavbar /> <a>
<PrimaryButton className="flex items-center gap-1">
<LayerDiagonalIcon height={16} width={16} color="white" /> Go to issues
</PrimaryButton>
</a>
</Link>
}
type="project"
/>
) : (
<main className="flex h-screen w-full min-w-0 flex-col overflow-y-auto">
{!noHeader && (
<AppHeader
breadcrumbs={breadcrumbs}
left={left}
right={right}
setToggleSidebar={setToggleSidebar}
/>
)}
<div
className={`flex w-full flex-grow flex-col ${
noPadding ? "" : settingsLayout ? "p-8 lg:px-28" : "p-8"
} ${
bg === "primary" ? "bg-primary" : bg === "secondary" ? "bg-secondary" : "bg-primary"
}`}
>
{settingsLayout && (
<div className="mb-12 space-y-6">
<div>
<h3 className="text-3xl font-semibold">Project Settings</h3>
<p className="mt-1 text-gray-600">
This information will be displayed to every member of the project.
</p>
</div> </div>
)} <SettingsNavbar />
{children} </div>
</div> )}
</main> {children}
)} </div>
</div> </main>
</Container> )}
</WorkspaceAuthorizationLayout> </div>
</Container>
); );
}; };

View File

@ -1,8 +1,13 @@
import { useRouter } from "next/router";
import useSWR from "swr"; import useSWR from "swr";
import { CURRENT_USER } from "constants/fetch-keys"; // services
import userService from "services/user.service"; import userService from "services/user.service";
import { useRouter } from "next/router"; // ui
import { Spinner } from "components/ui";
// fetch-keys
import { CURRENT_USER } from "constants/fetch-keys";
type Props = { type Props = {
children: React.ReactNode; children: React.ReactNode;
@ -14,7 +19,14 @@ export const UserAuthorizationLayout: React.FC<Props> = ({ children }) => {
const { data: currentUser, error } = useSWR(CURRENT_USER, () => userService.currentUser()); const { data: currentUser, error } = useSWR(CURRENT_USER, () => userService.currentUser());
if (!currentUser && !error) { if (!currentUser && !error) {
return <div className="grid place-items-center h-screen">Loading...</div>; return (
<div className="h-screen grid place-items-center p-4">
<div className="flex flex-col items-center gap-3 text-center">
<h3 className="text-xl">Loading your profile...</h3>
<Spinner />
</div>
</div>
);
} }
if (error?.status === 401) { if (error?.status === 401) {

View File

@ -12,15 +12,15 @@ import Container from "layouts/container";
import AppSidebar from "layouts/app-layout/app-sidebar"; import AppSidebar from "layouts/app-layout/app-sidebar";
import AppHeader from "layouts/app-layout/app-header"; import AppHeader from "layouts/app-layout/app-header";
import SettingsNavbar from "layouts/settings-navbar"; import SettingsNavbar from "layouts/settings-navbar";
import { UserAuthorizationLayout } from "./user-authorization-wrapper";
// components // components
import { NotAuthorizedView, NotAWorkspaceMember } from "components/auth-screens"; import { NotAuthorizedView, NotAWorkspaceMember } from "components/auth-screens";
import { CommandPalette } from "components/command-palette"; import { CommandPalette } from "components/command-palette";
// icons // icons
import { PrimaryButton } from "components/ui"; import { PrimaryButton, Spinner } from "components/ui";
import { LayerDiagonalIcon } from "components/icons"; import { LayerDiagonalIcon } from "components/icons";
// fetch-keys // fetch-keys
import { WORKSPACE_MEMBERS_ME } from "constants/fetch-keys"; import { WORKSPACE_MEMBERS_ME } from "constants/fetch-keys";
import { UserAuthorizationLayout } from "./user-authorization-wrapper";
type Meta = { type Meta = {
title?: string | null; title?: string | null;
@ -69,10 +69,12 @@ export const WorkspaceAuthorizationLayout: React.FC<Props> = ({
); );
if (!workspaceMemberMe && !error) if (!workspaceMemberMe && !error)
// TODO: show good loading UI
return ( return (
<div className="container h-screen flex justify-center items-center p-4 text-2xl font-semibold"> <div className="h-screen grid place-items-center p-4">
<p>Loading...</p> <div className="flex flex-col items-center gap-3 text-center">
<h3 className="text-xl">Setting up your workspace...</h3>
<Spinner />
</div>
</div> </div>
); );

View File

@ -99,7 +99,7 @@ const SignInPage: NextPage = () => {
> >
{isLoading && ( {isLoading && (
<div className="absolute top-0 left-0 z-50 flex h-full w-full flex-col items-center justify-center gap-y-3 bg-white"> <div className="absolute top-0 left-0 z-50 flex h-full w-full flex-col items-center justify-center gap-y-3 bg-white">
<h2 className="text-2xl text-gray-900">Signing in. Please wait...</h2> <h2 className="text-xl text-gray-900">Signing in. Please wait...</h2>
<Spinner /> <Spinner />
</div> </div>
)} )}