From 12e7faca48cea0438b4f7f553b09b9cf808c0046 Mon Sep 17 00:00:00 2001 From: David Emory Date: Thu, 10 May 2018 09:20:32 -0400 Subject: [PATCH] feat(manager): Clean up manage-subscription page --- lib/public/components/UserAccount.js | 159 +++++++++++++-------- lib/public/containers/ActiveUserAccount.js | 41 +----- 2 files changed, 105 insertions(+), 95 deletions(-) diff --git a/lib/public/components/UserAccount.js b/lib/public/components/UserAccount.js index b767a4d4a..5c1beb2cf 100644 --- a/lib/public/components/UserAccount.js +++ b/lib/public/components/UserAccount.js @@ -17,7 +17,9 @@ export default class UserAccount extends Component { } componentWillMount () { - this.props.onComponentMount(this.props) + this.props.onComponentMount(this.props, () => { + this.setState({ loadedProjectsAndFeed: true }) + }) } _onClickGet = () => this.props.getUser(this.props.user.profile.user_id) @@ -29,7 +31,6 @@ export default class UserAccount extends Component { render () { const {user} = this.props const messages = getComponentMessages('UserAccount') - const removeIconStyle = {cursor: 'pointer'} const subscriptions = user.profile.app_metadata.datatools.find(dt => dt.client_id === process.env.AUTH0_CLIENT_ID).subscriptions const ACCOUNT_SECTIONS = [ { @@ -95,25 +96,20 @@ export default class UserAccount extends Component { {getMessage(messages, 'notifications.subscriptions')} }> - + {subscriptions && subscriptions.length + ? + :
  • No subscriptions.
  • + } ) @@ -180,67 +176,110 @@ export default class UserAccount extends Component { } } -class SubscriptionListItem extends Component { - _onClickRemoveSubscriptionType = () => { - const {removeUserSubscription, subscription, user} = this.props - removeUserSubscription(user.profile, subscription.type) + +class SubscriptionsManager extends Component { + render () { + const { subscriptions } = this.props + + const projectSub = subscriptions.find(sub => sub.type === 'project-updated') + const feedSub = subscriptions.find(sub => sub.type === 'feed-updated') + return
    + {projectSub && ( +
    +

    Watched Projects

    + {projectSub.target.length + ? ( + + {projectSub.target.map((target, k) => + + )} + + ) + : No projects currently being watched + } +
    + )} + {feedSub && ( +
    +

    Watched Feeds

    + {feedSub.target.length + ? ( + + {feedSub.target.map((target, k) => + + )} + + ) + : No feeds currently being watched + } +
    + )} +
    + } +} + +class WatchedProject extends Component { + _onClickRemoveSubscriptionTarget = () => { + const {target, updateUserSubscription, user} = this.props + updateUserSubscription(user.profile, target, 'project-updated') } render () { - const {removeIconStyle, subscription} = this.props + const {projects, target} = this.props + const project = projects && projects.find(p => p.id === target) + const projectLink = project + ? {project.name} + : {target} (Deleted) return ( -
  • - {subscription.type.replace('-', ' ')}{' '} - -
      - {subscription.target.length - ? subscription.target.map(target => ( - - )) - :
    • No feeds subscribed to.
    • - } -
    -
  • + + {projectLink} + + ) } } -class SubscriptionTarget extends Component { +class WatchedFeed extends Component { _onClickRemoveSubscriptionTarget = () => { - const {subscription, target, updateUserSubscription, user} = this.props - updateUserSubscription(user.profile, target, subscription.type) + const {target, updateUserSubscription, user} = this.props + updateUserSubscription(user.profile, target, 'feed-updated') } render () { - const {projects, removeIconStyle, target} = this.props - let fs = null // this.props.projects ? this.props.projects.reduce(proj => proj.feedSources.filter(fs => fs.id === target)) : null + const {projects, target} = this.props + // Find the FeedSource and Project, if present + let feedSource + let project if (projects) { for (var i = 0; i < projects.length; i++) { - const feed = projects[i].feedSources - ? projects[i].feedSources.find(fs => fs.id === target) - : null - fs = feed || fs + if (!projects[i].feedSources) continue + const fs = projects[i].feedSources.find(fs => fs.id === target) + if (fs) { + feedSource = fs + project = projects[i] + break + } } } - const feedLink = fs - ? {fs.name} - : {target} + + const fsLink = feedSource + ? + {project.name} + {' / '} + {feedSource.name} + + : {target} (Deleted) return ( -
  • - {feedLink} - {' '} - -
  • + + {fsLink} + + ) } } diff --git a/lib/public/containers/ActiveUserAccount.js b/lib/public/containers/ActiveUserAccount.js index 32c591131..15ba32e40 100644 --- a/lib/public/containers/ActiveUserAccount.js +++ b/lib/public/containers/ActiveUserAccount.js @@ -4,7 +4,7 @@ import { browserHistory } from 'react-router' import UserAccount from '../components/UserAccount' import { setVisibilitySearchText } from '../../manager/actions/visibilityFilter' import { fetchProjects } from '../../manager/actions/projects' -import { fetchFeedSource } from '../../manager/actions/feeds' +import { fetchProjectFeeds } from '../../manager/actions/feeds' import { updateUserData, fetchUser, @@ -30,40 +30,11 @@ const mapDispatchToProps = (dispatch, ownProps) => { if (!ownProps.routeParams.subpage) { browserHistory.push('/settings/profile') } - if (!initialProps.projects) { - dispatch(fetchProjects()) - .then(() => { - const subscriptions = initialProps.user.profile.app_metadata.datatools.find(dt => dt.client_id === process.env.AUTH0_CLIENT_ID).subscriptions - if (subscriptions) { - Promise.all( - subscriptions.map(sub => { - console.log(sub) - sub.target.map(target => { - console.log('queuing feed source ', target) - return (dispatch(fetchFeedSource(target))) - }) - }) - ).then(results => { - console.log('got feed sources', results) - }) - } - }) - } else { - const subscriptions = initialProps.user.profile.app_metadata.datatools.find(dt => dt.client_id === process.env.AUTH0_CLIENT_ID).subscriptions - if (subscriptions) { - Promise.all( - subscriptions.map(sub => { - console.log(sub) - sub.target.map(target => { - console.log('queuing feed source ', target) - return (dispatch(fetchFeedSource(target))) - }) - }) - ).then(results => { - console.log('got feed sources', results) - }) - } - } + // Get all projects and their contained feeds (for subscription management) + dispatch(fetchProjects()) + .then((projects) => + Promise.all(projects.map(project => dispatch(fetchProjectFeeds(project.id)))) + ) }, searchTextChanged: (text) => dispatch(setVisibilitySearchText(text)), updateUserName: (user, permissions) => dispatch(updateUserData(user, permissions)),