From 0b99e465b68bd7099cf1df499053c831a73f56c8 Mon Sep 17 00:00:00 2001 From: Roy Meissner Date: Wed, 6 Jun 2018 11:16:32 +0200 Subject: [PATCH] Revert "Revert "Hide carousel when logged in and show recently used decks instead"" This reverts commit 9cd5a1c32799f38e9164aaa82719fc1f2ce0747a. --- .../user/userprofile/fetchHomeUserDecks.js | 23 +++++++++++++ components/Home/Home.js | 33 +++++++++++++------ components/User/UserProfile/PopularDecks.js | 10 +++++- 3 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 actions/user/userprofile/fetchHomeUserDecks.js diff --git a/actions/user/userprofile/fetchHomeUserDecks.js b/actions/user/userprofile/fetchHomeUserDecks.js new file mode 100644 index 000000000..4f6f5815a --- /dev/null +++ b/actions/user/userprofile/fetchHomeUserDecks.js @@ -0,0 +1,23 @@ +import async from 'async'; +import { fetchUserDecks } from './fetchUserDecks'; +import fetchUser from './fetchUser'; + +export default function fetchHomeUserDecks(context, payload, done) { + async.series([ + (callback) => { + context.executeAction(fetchUser, {params:{username: payload.username, id: payload.userid}}, callback); + }, + (callback) => { + context.executeAction(fetchUserDecks, { + deckListType: undefined, + params: { + username: payload.username, + sort: 'lastUpdate', + status: 'any', + roles: 'editor,owner' + } + }, callback); + } + ]); + done(); +} diff --git a/components/Home/Home.js b/components/Home/Home.js index 262f6af69..3c3e48e31 100644 --- a/components/Home/Home.js +++ b/components/Home/Home.js @@ -5,6 +5,10 @@ import {NavLink, navigateAction} from 'fluxible-router'; import { FormattedMessage, defineMessages} from 'react-intl'; import LocaleSwitcher from '../LocaleSwitcher/LocaleSwitcher'; import {Button} from 'semantic-ui-react'; +import UserProfileStore from '../../stores/UserProfileStore'; +import { connectToStores } from 'fluxible-addons-react'; +import PopularDecks from '../User/UserProfile/PopularDecks'; +import fetchHomeUserDecks from '../../actions/user/userprofile/fetchHomeUserDecks'; class Home extends React.Component { @@ -13,6 +17,12 @@ class Home extends React.Component { url: '/featured' }); }; + + componentDidMount() { + if(this.props.UserProfileStore.userid) + this.context.executeAction(fetchHomeUserDecks, {username: this.props.UserProfileStore.username, id: this.props.UserProfileStore.userid}); + } + render() { const heightStyle = { height: '100px' @@ -24,19 +34,21 @@ class Home extends React.Component { const compMessageStyle = { background: '#1E78BB' }; - + let optionalCarousel =

; + let optionalUserDecks = ''; + if(this.props.UserProfileStore.userid){ + optionalCarousel = ''; + optionalUserDecks =

Recently edited decks

See More
; + } return (
-
-

- - -
+ {optionalCarousel}
+ {optionalUserDecks}

@@ -246,9 +258,10 @@ Home.contextTypes = { executeAction: React.PropTypes.func.isRequired }; +Home = connectToStores(Home, [UserProfileStore], (context, props) => { + return { + UserProfileStore: context.getStore(UserProfileStore).getState() + }; +}); export default Home; - - - -//export default Home; diff --git a/components/User/UserProfile/PopularDecks.js b/components/User/UserProfile/PopularDecks.js index c228c5cf5..0bc93096f 100644 --- a/components/User/UserProfile/PopularDecks.js +++ b/components/User/UserProfile/PopularDecks.js @@ -3,12 +3,20 @@ import DeckCard from './DeckCard'; import { connectToStores } from 'fluxible-addons-react'; import UserProfileStore from '../../../stores/UserProfileStore'; import { isEmpty } from './../../../common'; +import classNames from 'classnames/bind'; class PublicUserDecks extends React.Component { render() { let size = 0; let content = this.props.decks; + let cardsClasses = classNames({ + 'ui': true, + 'three': this.props.fourCards === undefined, + 'four': this.props.fourCards, + 'stackable': true, + 'cards': true + }); if(!isEmpty(content)){ // if no sort property is given the order of decks is preserved if(this.props.sort){ @@ -29,7 +37,7 @@ class PublicUserDecks extends React.Component { size = content.length; else size = content.length < 3 ? content.length : this.props.size; - return (
+ return (
{[...Array(size).keys()].map( (i) => )}
); } else {