From 9a82bd0bbf243833710f9ec004fbe002e87d8edb Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 2 Apr 2022 20:49:31 +0900 Subject: [PATCH 1/3] Move the `main` view into the `main` dir --- ui/src/views/Main.tsx | 180 ---------------------------------- ui/src/views/main/Content.tsx | 63 ++++++++++++ ui/src/views/main/Header.tsx | 90 +++++++++++++++++ ui/src/views/main/index.tsx | 75 ++++++++++++++ 4 files changed, 228 insertions(+), 180 deletions(-) delete mode 100644 ui/src/views/Main.tsx create mode 100644 ui/src/views/main/Content.tsx create mode 100644 ui/src/views/main/Header.tsx create mode 100644 ui/src/views/main/index.tsx diff --git a/ui/src/views/Main.tsx b/ui/src/views/Main.tsx deleted file mode 100644 index e15004dd..00000000 --- a/ui/src/views/Main.tsx +++ /dev/null @@ -1,180 +0,0 @@ -import { useEffect, useState } from "react" -import { shallowEqual } from "react-redux" -import { Layout, Menu, Row, Col, Result, Button, Drawer, Avatar, Dropdown, Badge} from "antd" -import { SettingFilled } from "@ant-design/icons" -import { Helmet } from "react-helmet" -import moment from "moment" - -import { useAppSelector, useAppDispatch } from "../redux/hooks" -import { init, searchDeployments, searchReviews, fetchLicense, notifyDeploymentEvent, notifyReviewmentEvent, mainSlice as slice } from "../redux/main" -import { subscribeEvents } from "../apis" - -import RecentActivities from "../components/RecentActivities" -import LicenseFooter from "../components/LicenseFooter" - -import Logo from "../logo.svg" - -const { Header, Content, Footer } = Layout - -// eslint-disable-next-line -export default function Main(props: any) { - const { - available, - authorized, - expired, - user, - deployments, - reviews, - license, - } = useAppSelector(state => state.main, shallowEqual) - const dispatch = useAppDispatch() - - useEffect(() => { - dispatch(init()) - dispatch(searchDeployments()) - dispatch(searchReviews()) - dispatch(fetchLicense()) - - const sub = subscribeEvents((event) => { - dispatch(slice.actions.handleDeploymentEvent(event)) - dispatch(slice.actions.handleReviewEvent(event)) - dispatch(notifyDeploymentEvent(event)) - dispatch(notifyReviewmentEvent(event)) - }) - - return () => { - sub.close() - } - }, [dispatch]) - - const onClickRetry = () => { - dispatch(slice.actions.setAvailable(true)) - dispatch(slice.actions.setExpired(false)) - } - - const [ isRecentActivitiesVisible, setRecentActivitiesVisible ] = useState(false) - - const showRecentActivities = () => { - setRecentActivitiesVisible(true) - } - - const onCloseRecentActivities = () => { - setRecentActivitiesVisible(false) - } - - // Count of recent activities. - const countActivities = deployments.length + reviews.length - - let content: React.ReactElement - if (!available) { - content = Retry]} - /> - } else if (!authorized) { - content = Sign in]} - /> - } else if (expired) { - content = Retry]} - /> - } else { - content = props.children - } - - return ( - - - Gitploy - {(deployments.length + reviews.length > 0)? - : - } - -
- - - - - Home - {(user?.admin)? Members: null} - - - - -
- - - - {content} - - - -
- - Gitploy ©{moment().format("YYYY")} Created by Gitploy.IO -
-
- ) -} diff --git a/ui/src/views/main/Content.tsx b/ui/src/views/main/Content.tsx new file mode 100644 index 00000000..ec1e3bbb --- /dev/null +++ b/ui/src/views/main/Content.tsx @@ -0,0 +1,63 @@ +import { shallowEqual } from "react-redux" +import { Row, Col, Result, Button} from "antd" + +import { useAppSelector, useAppDispatch } from "../../redux/hooks" +import { mainSlice as slice } from "../../redux/main" +import React from "react" + +export default function Content(props: React.PropsWithChildren): JSX.Element { + const { + available, + authorized, + expired, + } = useAppSelector(state => state.main, shallowEqual) + const dispatch = useAppDispatch() + + const onClickRetry = () => { + dispatch(slice.actions.setAvailable(true)) + dispatch(slice.actions.setExpired(false)) + } + + let content: React.ReactNode + if (!available) { + content = Retry]} + /> + } else if (!authorized) { + content = Sign in]} + /> + } else if (expired) { + content = Retry]} + /> + } else { + content = props.children + } + + return ( + + + {content} + + + ) +} \ No newline at end of file diff --git a/ui/src/views/main/Header.tsx b/ui/src/views/main/Header.tsx new file mode 100644 index 00000000..fc60c83e --- /dev/null +++ b/ui/src/views/main/Header.tsx @@ -0,0 +1,90 @@ +import { useState } from "react" +import { shallowEqual } from "react-redux" +import { Menu, Row, Col, Button, Drawer, Avatar, Dropdown, Badge, Space} from "antd" +import { SettingFilled } from "@ant-design/icons" + +import { useAppSelector } from "../../redux/hooks" + +import RecentActivities from "../../components/RecentActivities" + +import Logo from "../../logo.svg" + +export default function Header(): JSX.Element { + const { + authorized, + user, + deployments, + reviews, + } = useAppSelector(state => state.main, shallowEqual) + + const activitiesCount = deployments.length + reviews.length + + const [ isRecentActivitiesVisible, setRecentActivitiesVisible ] = useState(false) + + return ( + + + + + + + + Home + + {(user?.admin)? + + Members + + : + <>} + + + + + +