diff --git a/app/javascript/gabsocial/components/welcome_reminders.js b/app/javascript/gabsocial/components/welcome_reminders.js new file mode 100644 index 00000000..3591089e --- /dev/null +++ b/app/javascript/gabsocial/components/welcome_reminders.js @@ -0,0 +1,182 @@ +import React from 'react' +import ImmutablePropTypes from 'react-immutable-proptypes' +import ImmutablePureComponent from 'react-immutable-pure-component' +import { connect } from 'react-redux' +import moment from 'moment-mini' +import { openModal } from '../actions/modal' +import { + CX, + MODAL_COMPOSE, + MODAL_EDIT_PROFILE, + BREAKPOINT_EXTRA_SMALL, + PLACEHOLDER_MISSING_HEADER_SRC, +} from '../constants' +import { me } from '../initial_state' +import { + isMobile, + getWindowDimension, +} from '../utils/is_mobile' +import Button from '../components/button' +import Icon from '../components/icon' +import Text from '../components/text' +import { makeGetAccount } from '../selectors' + +const initialState = getWindowDimension() + +class WelcomeReminders extends ImmutablePureComponent { + + state = { + isXS: isMobile(initialState.width), + profileComplete: false, + visible: false, + } + + componentDidMount() { + this.handleResize() + this.handleSetVisible(this.props.account) + window.addEventListener('resize', this.handleResize, false) + } + + componentDidUpdate(prevProps) { + const { account } = this.props + console.log("Welcome updated") + this.handleSetVisible(account) + } + + componentWillUnmount() { + window.removeEventListener('resize', this.handleResize, false) + } + + handleSetVisible = (account) => { + if (!account) return + + const createdAt = account.get('created_at') + const diff = moment().diff(createdAt, 'days') + + // Don't show to accounts older than 7 days old + if (diff > 7) { + this.setState({ visible: false }) + return + } + + const hasFollowing = account.get('following_count') > 0 + const hasStatuses = account.get('statuses_count') > 0 + + const avatarSrc = account.get('avatar') + const avatarMissing = !avatarSrc ? true : avatarSrc.indexOf(PLACEHOLDER_MISSING_HEADER_SRC) > -1 + + const headerSrc = !!account ? account.get('header') : undefined + const headerMissing = !headerSrc ? true : headerSrc.indexOf(PLACEHOLDER_MISSING_HEADER_SRC) > -1 + const profileComplete = !avatarMissing && !headerMissing + + const visible = !hasFollowing || !hasStatuses || !profileComplete + + this.setState({ visible, profileComplete }) + } + + handleResize = () => { + const { width } = getWindowDimension() + this.setState({ isXS: isMobile(width) }) + } + + onOpenComposeModal = () => { + this.props.dispatch(openModal(MODAL_COMPOSE)) + } + + onOpenEditProfileModal = () => { + this.props.dispatch(openModal(MODAL_EDIT_PROFILE)) + } + + render() { + const { account } = this.props + const { + isXS, + visible, + profileComplete, + } = this.state + + if (!visible || !account) return false + + return ( +