Client:OAuth2: add list loader

This commit is contained in:
Timofey Boyko 2023-11-14 13:34:22 +03:00
parent 20b79e4833
commit 3d766424e0
6 changed files with 71 additions and 16 deletions

View File

@ -2,5 +2,4 @@ import styled from "styled-components";
export const OAuthContainer = styled.div` export const OAuthContainer = styled.div`
width: 100%; width: 100%;
margin-top: 5px;
`; `;

View File

@ -16,6 +16,7 @@ import { OAuthContainer } from "./StyledOAuth";
import { OAuthProps } from "./OAuth.types"; import { OAuthProps } from "./OAuth.types";
import InfoDialog from "./sub-components/InfoDialog"; import InfoDialog from "./sub-components/InfoDialog";
import PreviewDialog from "./sub-components/PreviewDialog"; import PreviewDialog from "./sub-components/PreviewDialog";
import OAuthLoader from "./sub-components/List/Loader";
const MIN_LOADER_TIME = 500; const MIN_LOADER_TIME = 500;
@ -70,7 +71,6 @@ const OAuth = ({
}); });
React.useEffect(() => { React.useEffect(() => {
console.log(isInit);
if (isInit) return setIsLoading(false); if (isInit) return setIsLoading(false);
startLoadingRef.current = new Date(); startLoadingRef.current = new Date();
getData(); getData();
@ -84,11 +84,16 @@ const OAuth = ({
<OAuthContainer> <OAuthContainer>
<> <>
{isLoading ? ( {isLoading ? (
<div>Loading...</div> <OAuthLoader viewAs={viewAs} currentDeviceType={currentDeviceType} />
) : isEmptyClientList ? ( ) : isEmptyClientList ? (
<OAuthEmptyScreen t={t} /> <OAuthEmptyScreen t={t} />
) : ( ) : (
<List t={t} clients={clientList} viewAs={viewAs} /> <List
t={t}
clients={clientList}
viewAs={viewAs}
currentDeviceType={currentDeviceType}
/>
)} )}
</> </>
{infoDialogVisible && <InfoDialog visible={infoDialogVisible} />} {infoDialogVisible && <InfoDialog visible={infoDialogVisible} />}

View File

@ -0,0 +1,46 @@
import React from "react";
//@ts-ignore
import RectangleLoader from "@docspace/common/components/Loaders/RectangleLoader";
import { DeviceUnionType } from "@docspace/common/hooks/useViewEffect";
//@ts-ignore
import Loaders from "@docspace/common/components/Loaders";
//@ts-ignore
import { ViewAsType } from "SRC_DIR/store/OAuthStore";
import { OAuthContainer } from "../../StyledOAuth";
import { StyledContainer } from ".";
const OAuthLoader = ({
viewAs,
currentDeviceType,
}: {
viewAs: ViewAsType;
currentDeviceType: DeviceUnionType;
}) => {
const buttonHeight = currentDeviceType !== "desktop" ? "40px" : "32px";
const listLoader =
viewAs === "table" ? <Loaders.TableLoader /> : <Loaders.Rows />;
return (
<OAuthContainer>
<StyledContainer>
<RectangleLoader
className="description"
width={"100%"}
height={"16px"}
/>
<RectangleLoader
className="add-button"
width={"220px"}
height={buttonHeight}
/>
{listLoader}
</StyledContainer>
</OAuthContainer>
);
};
export default OAuthLoader;

View File

@ -15,22 +15,20 @@ import TableView from "./TableView";
import RowView from "./RowView"; import RowView from "./RowView";
import RegisterNewButton from "../RegisterNewButton"; import RegisterNewButton from "../RegisterNewButton";
import { DeviceUnionType } from "@docspace/common/hooks/useViewEffect";
const StyledContainer = styled.div` export const StyledContainer = styled.div`
width: 100%; width: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
.header {
margin-bottom: 8px;
}
.description { .description {
margin-bottom: 8px; margin-bottom: 20px;
max-width: 700px;
} }
button { .add-button {
width: fit-content; width: fit-content;
margin-bottom: 12px; margin-bottom: 12px;
@ -41,9 +39,10 @@ interface ListProps {
t: any; t: any;
clients: ClientProps[]; clients: ClientProps[];
viewAs: ViewAsType; viewAs: ViewAsType;
currentDeviceType: DeviceUnionType;
} }
const List = ({ clients, viewAs }: ListProps) => { const List = ({ clients, viewAs, currentDeviceType }: ListProps) => {
const { t } = useTranslation(["OAuth", "Common"]); const { t } = useTranslation(["OAuth", "Common"]);
return ( return (
@ -61,7 +60,7 @@ const List = ({ clients, viewAs }: ListProps) => {
> >
{t("OAuthAppDescription")} {t("OAuthAppDescription")}
</Text> </Text>
<RegisterNewButton t={t} /> <RegisterNewButton t={t} currentDeviceType={currentDeviceType} />
<Consumer> <Consumer>
{(context: { sectionWidth: number; sectionHeight: number }) => ( {(context: { sectionWidth: number; sectionHeight: number }) => (
<> <>

View File

@ -1,3 +1,6 @@
import { DeviceUnionType } from "@docspace/common/hooks/useViewEffect";
export interface RegisterNewButtonProps { export interface RegisterNewButtonProps {
t: any; t: any;
currentDeviceType: DeviceUnionType;
} }

View File

@ -1,11 +1,13 @@
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { isMobile } from "react-device-detect";
import Button from "@docspace/components/button"; import Button from "@docspace/components/button";
import { RegisterNewButtonProps } from "./RegisterNewButton.types"; import { RegisterNewButtonProps } from "./RegisterNewButton.types";
const RegisterNewButton = ({ t }: RegisterNewButtonProps) => { const RegisterNewButton = ({
t,
currentDeviceType,
}: RegisterNewButtonProps) => {
const navigate = useNavigate(); const navigate = useNavigate();
const onClick = () => { const onClick = () => {
@ -15,7 +17,8 @@ const RegisterNewButton = ({ t }: RegisterNewButtonProps) => {
return ( return (
<Button <Button
//@ts-ignore //@ts-ignore
size={isMobile ? "normal" : "small"} className="add-button"
size={currentDeviceType !== "desktop" ? "normal" : "small"}
label={t("RegisterNewApp")} label={t("RegisterNewApp")}
primary={true} primary={true}
onClick={onClick} onClick={onClick}