| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- /*
- Copyright (C) 2017 Cloudbase Solutions SRL
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- import React from 'react'
- import { Link } from 'react-router-dom'
- import styled from 'styled-components'
- import { observer } from 'mobx-react'
- import NavigationMini from '../../NavigationModule/NavigationMini/NavigationMini'
- import NotificationDropdown from '../../../ui/Dropdowns/NotificationDropdown/NotificationDropdown'
- import UserDropdown from '../../../ui/Dropdowns/UserDropdown/UserDropdown'
- import AboutModal from '../../../smart/AboutModal/AboutModal'
- import type { User as UserType } from '../../../../@types/User'
- import notificationStore from '../../../../stores/NotificationStore'
- import backgroundImage from './images/star-bg.jpg'
- import logoImage from './images/logo.svg'
- const Wrapper = styled.div<any>`
- display: flex;
- height: 64px;
- background: url('${backgroundImage}');
- align-items: center;
- padding-right: 22px;
- justify-content: space-between;
- `
- const Logo = styled(Link)`
- width: 240px;
- height: 48px;
- background: url('${logoImage}') no-repeat;
- cursor: pointer;
- `
- const UserDropdownStyled = styled(UserDropdown)`
- margin-left: 16px;
- `
- const Menu = styled.div<any>`
- display: flex;
- align-items: center;
- `
- const User = styled.div<any>`
- display: flex;
- align-items: center;
- `
- type State = {
- showAbout: boolean,
- }
- type Props = {
- user?: UserType | null,
- onUserItemClick: (userItem: { label: React.ReactNode, value: string }) => void,
- testMode?: boolean,
- }
- @observer
- class DetailsPageHeader extends React.Component<Props, State> {
- state = {
- showAbout: false,
- }
- pollTimeout: number | undefined
- stopPolling!: boolean
- UNSAFE_componentWillMount() {
- if (this.props.testMode) {
- return
- }
- this.stopPolling = false
- this.pollData(true)
- }
- componentWillUnmount() {
- clearTimeout(this.pollTimeout)
- this.stopPolling = true
- }
- handleNotificationsClose() {
- notificationStore.saveSeen()
- }
- handleUserItemClick(item: { label: React.ReactNode, value: string }) {
- switch (item.value) {
- case 'about':
- this.setState({ showAbout: true })
- break
- default:
- this.props.onUserItemClick(item)
- }
- }
- async pollData(showLoading?: boolean) {
- if (this.stopPolling) {
- return
- }
- await notificationStore.loadData(showLoading)
- this.pollTimeout = setTimeout(() => { this.pollData() }, 15000)
- }
- render() {
- return (
- <Wrapper>
- <Menu>
- <NavigationMini />
- <Logo to="/" />
- </Menu>
- <User>
- <NotificationDropdown
- white
- items={notificationStore.notificationItems}
- onClose={() => this.handleNotificationsClose()}
- />
- <UserDropdownStyled
- white
- user={this.props.user}
- onItemClick={item => { this.handleUserItemClick(item) }}
- />
- </User>
- {this.state.showAbout ? (
- <AboutModal onRequestClose={() => { this.setState({ showAbout: false }) }} />
- ) : null}
- </Wrapper>
- )
- }
- }
- export default DetailsPageHeader
|