diff --git a/ui/src/views/Deployment.tsx b/ui/src/views/Deployment.tsx index 6be9abdd..13792ef4 100644 --- a/ui/src/views/Deployment.tsx +++ b/ui/src/views/Deployment.tsx @@ -24,7 +24,7 @@ import { } from "../models" import { subscribeEvents } from "../apis" -import Main from "./Main" +import Main from "./main" import ReviewModal from "../components/ReviewModal" import Spin from "../components/Spin" import DeploymentDescriptor from "../components/DeploymentDescriptor" diff --git a/ui/src/views/Home.tsx b/ui/src/views/Home.tsx index 40a9842b..29f82cdd 100644 --- a/ui/src/views/Home.tsx +++ b/ui/src/views/Home.tsx @@ -8,7 +8,7 @@ import { homeSlice, listRepos, perPage, sync, homeSlice as slice } from '../redu import { RequestStatus } from '../models' import { subscribeEvents } from "../apis" -import Main from './Main' +import Main from './main' import SyncButton from "../components/SyncButton" import RepoList from '../components/RepoList' import Pagination from '../components/Pagination' 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/Repo.tsx b/ui/src/views/Repo.tsx index 62d6d356..72d42ba9 100644 --- a/ui/src/views/Repo.tsx +++ b/ui/src/views/Repo.tsx @@ -8,7 +8,7 @@ import { useAppSelector, useAppDispatch } from '../redux/hooks' import { init, activate, repoSlice as slice } from '../redux/repo' import ActivateButton from "../components/ActivateButton" -import Main from './Main' +import Main from './main' import RepoHome from './RepoHome' import RepoLock from "./RepoLock"; import RepoDeploy from './RepoDeploy' diff --git a/ui/src/views/Settings.tsx b/ui/src/views/Settings.tsx index ee3c0f33..7e9f7aef 100644 --- a/ui/src/views/Settings.tsx +++ b/ui/src/views/Settings.tsx @@ -6,7 +6,7 @@ import { Button, Tag, Descriptions, Input } from "antd" import { useAppSelector, useAppDispatch } from "../redux/hooks" import { fetchMe, checkSlack } from "../redux/settings" -import Main from "./Main" +import Main from "./main" export default function Settings(): JSX.Element { const { user, isSlackEnabled } = useAppSelector(state => state.settings, shallowEqual) 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 + + : + <>} + + + + + +