import React from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePureComponent from 'react-immutable-pure-component' import { defineMessages, injectIntl } from 'react-intl' import { openPopover } from '../actions/popover' import { showToast } from '../actions/toasts' import { addShortcut, removeShortcut, } from '../actions/shortcuts' import { PLACEHOLDER_MISSING_HEADER_SRC, BREAKPOINT_EXTRA_SMALL, TOAST_TYPE_SUCCESS, } from '../constants' import { me } from '../initial_state' import Responsive from '../features/ui/util/responsive_component' import GroupActionButton from './group_action_button' import Button from './button' import Block from './block' import Heading from './heading' import Image from './image' import Icon from './icon' import TabBar from './tab_bar' import Pills from './pills' import Text from './text' class GroupHeader extends ImmutablePureComponent { handleOnOpenGroupOptions = () => { const { relationships } = this.props const isAdmin = !!relationships ? relationships.get('admin') : false const isModerator = !!relationships ? relationships.get('moderator') : false this.props.onOpenGroupOptions(this.infoBtn, this.props.group, { isAdmin, isModerator, }) } handleToggleShortcut = () => { const { group, isShortcut } = this.props const groupId = !!group ? group.get('id') : null if (!groupId) return if (isShortcut) { this.props.onRemoveShortcut(groupId) } else { this.props.onAddShortcut(groupId) } } handleCopySlug = () => { const { group } = this.props const url = !!group ? !!group.get('slug') ? `https://gab.com/g/${group.get('slug')}` : undefined : undefined if (!url) return const textarea = document.createElement('textarea') textarea.textContent = url textarea.style.position = 'fixed' document.body.appendChild(textarea) try { textarea.select() document.execCommand('copy') } catch (e) { // } document.body.removeChild(textarea) this.props.onShowCopyToast() } setInfoBtn = (c) => { this.infoBtn = c; } render() { const { children, group, intl, isXS, isShortcut, relationships, } = this.props const coverSrc = !!group ? group.get('cover_image_url') : '' const coverSrcMissing = coverSrc.indexOf(PLACEHOLDER_MISSING_HEADER_SRC) > -1 || !coverSrc const title = !!group ? group.get('title') : undefined const slug = !!group ? !!group.get('slug') ? `g/${group.get('slug')}` : undefined : undefined const isPrivate = !!group ? group.get('is_private') : false const isAdminOrMod = !!relationships ? (relationships.get('admin') || relationships.get('moderator')) : false const tabs = !group ? [] : [ { to: `/groups/${group.get('id')}`, title: 'Timeline', }, ] if (isAdminOrMod && group) { tabs.push({ to: `/groups/${group.get('id')}/members`, title: 'Members', }) } if (isAdminOrMod && group && isPrivate) { tabs.push({ to: `/groups/${group.get('id')}/requests`, title: 'Requests', }) } if (isXS && group) { tabs.push({ to: `/groups/${group.get('id')}/about`, title: 'About', }) } return (