Skip to content

Commit

Permalink
#64 Uniform codebase (#67)
Browse files Browse the repository at this point in the history
* Remove all index.js except main one + rename actions to match `domain/action/status` nomenclature

* Rename selectors

* Hound review
  • Loading branch information
HugoGresse authored Aug 5, 2019
1 parent 7a6bf7a commit 93ebe5a
Show file tree
Hide file tree
Showing 37 changed files with 176 additions and 195 deletions.
4 changes: 2 additions & 2 deletions src/admin/AdminRoot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react'
import {
getProjectsSelector,
getSortedProjectsSelector,
isProjectsLoadedSelector
} from './project/core/projectSelectors'
import { connect } from 'react-redux'
Expand All @@ -22,7 +22,7 @@ class AdminRoot extends Component {
}

const mapStateToProps = state => ({
projects: getProjectsSelector(state),
projects: getSortedProjectsSelector(state),
isProjectsLoaded: isProjectsLoadedSelector(state)
})

Expand Down
4 changes: 2 additions & 2 deletions src/admin/SideBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getUserSelector } from './auth/authSelectors'
import { didSignIn, signOut } from './auth/authActions'
import { authProvider } from '../firebase'
import { Link } from 'react-router-dom'
import { getProjectsSelector } from './project/core/projectSelectors'
import { getSortedProjectsSelector } from './project/core/projectSelectors'

const Wrapper = styled(Box)`
background: ${COLORS.EXTRA_LIGHT_GRAY};
Expand Down Expand Up @@ -73,7 +73,7 @@ class SideBar extends Component {

const mapStateToProps = state => ({
user: getUserSelector(state),
projects: getProjectsSelector(state)
projects: getSortedProjectsSelector(state)
})

const mapDispatchToProps = Object.assign(
Expand Down
4 changes: 2 additions & 2 deletions src/admin/auth/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Box from '../../baseComponents/design/Box'
import { StyledFirebaseAuth } from 'react-firebaseui'
import { auth, authProvider } from '../../firebase'
import { connect } from 'react-redux'
import { getLoginErrorSelector, isLogged } from './authSelectors'
import { getLoginErrorSelector, isLoggedSelector } from './authSelectors'
import { didSignIn, signOut } from './authActions'

const Wrapper = styled(Box)`
Expand Down Expand Up @@ -90,7 +90,7 @@ class Login extends Component {
}

const mapStateToProps = state => ({
isLoggedIn: isLogged(state),
isLoggedIn: isLoggedSelector(state),
loginError: getLoginErrorSelector(state)
})

Expand Down
4 changes: 2 additions & 2 deletions src/admin/auth/authActions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { LOGIN_ERROR, LOGIN_SUCCESS, LOGOUT } from './authActionTypes'
import { isLogged } from './authSelectors'
import { isLoggedSelector } from './authSelectors'
import { authProvider } from '../../firebase'

export const didSignIn = (user, error) => {
return (dispatch, getState) => {
if (isLogged(getState())) {
if (isLoggedSelector(getState())) {
return
}

Expand Down
8 changes: 4 additions & 4 deletions src/admin/auth/authSelectors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const getAuth = state => state.adminAuth
export const getAuthSelector = state => state.adminAuth

export const isLogged = state => getAuth(state).isLogin
export const isLoggedSelector = state => getAuthSelector(state).isLogin

export const getUserSelector = state => getAuth(state).user
export const getUserSelector = state => getAuthSelector(state).user

export const getLoginErrorSelector = state => getAuth(state).error
export const getLoginErrorSelector = state => getAuthSelector(state).error
4 changes: 2 additions & 2 deletions src/admin/notification/Notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ErrorIcon from '@material-ui/icons/Error'
import withStyles from '@material-ui/core/styles/withStyles'
import green from '@material-ui/core/colors/green'
import amber from '@material-ui/core/colors/amber'
import { getLastNotifications } from './notificationSelectors'
import { getLastNotificationsSelector } from './notificationSelectors'
import Snackbar from '@material-ui/core/Snackbar'
import { clearNotification } from './notifcationActions'

Expand Down Expand Up @@ -97,7 +97,7 @@ class Notifications extends Component {
}

const mapStateToProps = state => ({
notification: getLastNotifications(state)
notification: getLastNotificationsSelector(state)
})

const mapDispatchToProps = Object.assign(
Expand Down
2 changes: 1 addition & 1 deletion src/admin/notification/notificationSelectors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const getNotifications = state => state.adminNotifications
export const getLastNotifications = state =>
export const getLastNotificationsSelector = state =>
getNotifications(state).notifications[0]
4 changes: 2 additions & 2 deletions src/admin/project/Project.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from 'react'
import { connect } from 'react-redux'
import { getProjectsSelector } from './core/projectSelectors'
import { getSortedProjectsSelector } from './core/projectSelectors'
import { selectProject } from './core/projectActions'

class Project extends Component {
Expand All @@ -14,7 +14,7 @@ class Project extends Component {
}

const mapStateToProps = state => ({
projects: getProjectsSelector(state)
projects: getSortedProjectsSelector(state)
})

const mapDispatchToProps = Object.assign(
Expand Down
23 changes: 12 additions & 11 deletions src/admin/project/core/projectActionTypes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
export const GET_PROJECTS_SUCCESS = 'admin/getProjects/success'
export const GET_PROJECTS_ERROR = 'admin/getProjects/error'
export const GET_PROJECT_SUCCESS = 'admin/getProject/success'
export const GET_PROJECT_ERROR = 'admin/getProject/error'
export const SELECT_PROJECT = 'admin/selectProject'
export const GET_PROJECT_VOTE_ITEMS_SUCCESS = 'admin/getProjectVoteItem/success'
export const GET_PROJECT_VOTE_ITEMS_ERROR = 'admin/getProjectVoteItem/error'
export const GET_PROJECTS_SUCCESS = 'admin/projects/get/success'
export const GET_PROJECTS_ERROR = 'admin/projects/get/error'
export const GET_PROJECT_SUCCESS = 'admin/project/get/success'
export const GET_PROJECT_ERROR = 'admin/project/get/error'
export const SELECT_PROJECT = 'admin/project/select'
export const GET_PROJECT_VOTE_ITEMS_SUCCESS =
'admin/project/getVoteItem/success'
export const GET_PROJECT_VOTE_ITEMS_ERROR = 'admin/project/getVoteItem/error'

export const EDIT_PROJECT_SUCCESS = 'admin/editProject/success'
export const EDIT_PROJECT_ERROR = 'admin/editProject/error'
export const EDIT_PROJECT_SUCCESS = 'admin/project/edit/success'
export const EDIT_PROJECT_ERROR = 'admin/project/edit/error'

export const ADD_PROJECT_SUCCESS = 'admin/addProject/success'
export const ADD_PROJECT_ERROR = 'admin/addProject/error'
export const ADD_PROJECT_SUCCESS = 'admin/project/add/success'
export const ADD_PROJECT_ERROR = 'admin/project/add/error'
4 changes: 2 additions & 2 deletions src/admin/project/core/projectSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getSelectedProjectIdSelector = state =>

// MEMOIZED

export const getProjectsSelector = createSelector(
export const getSortedProjectsSelector = createSelector(
getProjectsData,
projectsData => {
return projectsData.projects.sort((a, b) => {
Expand All @@ -27,7 +27,7 @@ export const getProjectsSelector = createSelector(
)

export const getSelectedProjectSelector = createSelector(
getProjectsSelector,
getSortedProjectsSelector,
getSelectedProjectIdSelector,
(projects, selectedProjectId) => {
if (!projects || projects.length < 1) {
Expand Down
4 changes: 2 additions & 2 deletions src/admin/project/dashboard/VoteTimeline.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { getVotesByHour } from './dashboardSelectors'
import { getVotesByHourSelector } from './dashboardSelectors'
import Paper from '@material-ui/core/Paper'
import CircularProgress from '@material-ui/core/CircularProgress'
import XAxis from 'recharts/es6/cartesian/XAxis'
Expand Down Expand Up @@ -82,7 +82,7 @@ class VoteTimeline extends Component {
}

const mapStateToProps = state => ({
votesByHour: getVotesByHour(state)
votesByHour: getVotesByHourSelector(state)
})

export default connect(
Expand Down
12 changes: 6 additions & 6 deletions src/admin/project/dashboard/dashboardActionTypes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const GET_SESSION_VOTES_SUCCESS = 'admin/getSessionVotes/success'
export const GET_SESSION_VOTES_ERROR = 'admin/getSessionVotes/error'
export const CLEAR_SESSION_VOTES = 'admin/clearSessionVotes'
export const GET_USER_VOTES_SUCCESS = 'admin/getUserVotes/success'
export const GET_USER_VOTES_ERROR = 'admin/getUserVotes/error'
export const CLEAR_USER_VOTES = 'admin/clearUserVotes'
export const GET_SESSION_VOTES_SUCCESS =
'admin/dashboard/getSessionVotes/success'
export const GET_SESSION_VOTES_ERROR = 'admin/dashboard/getSessionVotes/error'
export const CLEAR_SESSION_VOTES = 'admin/dashboard/clearSessionVotes'
export const GET_USER_VOTES_SUCCESS = 'admin/dashboard/getUserVotes/success'
export const GET_USER_VOTES_ERROR = 'admin/dashboard/getUserVotes/error'
6 changes: 3 additions & 3 deletions src/admin/project/dashboard/dashboardSelectors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSelector } from 'reselect'
import {
getSessionsList,
getSessionsListSelector,
isSessionLoadedSelector
} from '../../../core/sessions/sessionsSelectors'

Expand All @@ -13,7 +13,7 @@ const getUserVotes = state => getDashboardData(state).userVotes

export const getMostVotedSessionSelector = createSelector(
getSessionVotes,
getSessionsList,
getSessionsListSelector,
isSessionLoadedSelector,
(sessionVotes, sessionlist, isSessionLoaded) => {
if (Object.keys(sessionlist).length <= 0 || !isSessionLoaded) {
Expand Down Expand Up @@ -54,7 +54,7 @@ export const getMostVotedSessionSelector = createSelector(
}
)

export const getVotesByHour = createSelector(
export const getVotesByHourSelector = createSelector(
getUserVotes,
userVotes => {
let tempDate
Expand Down
10 changes: 5 additions & 5 deletions src/core/sessions/sessionsActionTypes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const GET_SESSIONS_SUCCESS = 'core/getSessions/success'
export const GET_SESSIONS_LOADING = 'core/getSessions/loading'
export const GET_SESSIONS_ERROR = 'core/getSessions/error'
export const CLEAR_SESSIONS = 'core/clearSessions'
export const SET_SESSIONS_FILTER = 'core/setSessionsFilter'
export const GET_SESSIONS_SUCCESS = 'core/sessions/get/success'
export const GET_SESSIONS_LOADING = 'core/session/get/loading'
export const GET_SESSIONS_ERROR = 'core/sessions/get/error'
export const CLEAR_SESSIONS = 'core/sessions/clear'
export const SET_SESSIONS_FILTER = 'core/sessions/filter'
37 changes: 20 additions & 17 deletions src/core/sessions/sessionsSelectors.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { createSelector } from 'reselect'
import groupBy from 'lodash/groupBy'
import { getDateFromStartTime } from './sessionsUtils'
import { getProjectSelectedDate } from '../../feedback/project/projectSelectors'
import { getSpeakersList } from '../../feedback/speaker/core'
import { getProjectSelectedDateSelector } from '../../feedback/project/projectSelectors'
import { getSpeakersListSelector } from '../../feedback/speaker/core/speakerSelectors'

export const getSessions = state => state.sessions
export const getSessionsSelector = state => state.sessions

export const getSessionsList = state => getSessions(state).list
export const getSessionsListSelector = state => getSessionsSelector(state).list

export const getSessionsFilter = state => getSessions(state).filter || ''
export const getSessionsFilterSelector = state =>
getSessionsSelector(state).filter || ''

export const getSessionsLoadError = state =>
getSessions(state).errorSessionsLoad
getSessionsSelector(state).errorSessionsLoad

export const isSessionsLoadingSelector = state => getSessions(state).loading
export const isSessionsLoadingSelector = state =>
getSessionsSelector(state).loading

export const isSessionLoadedSelector = state => getSessions(state).loaded
export const isSessionLoadedSelector = state =>
getSessionsSelector(state).loaded

// MEMOIZED SELECTORS HERE

export const getSessionsAsArray = createSelector(
getSessionsList,
export const getSessionsAsArraySelector = createSelector(
getSessionsListSelector,
sessions => {
return Object.keys(sessions).reduce((acc, id) => {
acc.push(sessions[id])
Expand All @@ -29,8 +32,8 @@ export const getSessionsAsArray = createSelector(
}
)

export const getSessionsDates = createSelector(
getSessionsAsArray,
export const getSessionsDatesSelector = createSelector(
getSessionsAsArraySelector,
sessions => {
return sessions
.reduce((acc, session) => {
Expand All @@ -44,11 +47,11 @@ export const getSessionsDates = createSelector(
}
)

export const getCurrentSessionsGroupByTrack = createSelector(
getSessionsAsArray,
getSessionsFilter,
getProjectSelectedDate,
getSpeakersList,
export const getCurrentSessionsGroupByTrackSelector = createSelector(
getSessionsAsArraySelector,
getSessionsFilterSelector,
getProjectSelectedDateSelector,
getSpeakersListSelector,
(sessions, filter, date, speakers) => {
const cleanedFilterInput = filter.toLowerCase().trim()

Expand Down
14 changes: 7 additions & 7 deletions src/feedback/AppLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import { withStyles } from '@material-ui/core'
import '../App.css'
import { connect } from 'react-redux'
import { setFavicon } from './layout/utils'
import { authActions } from './auth'
import * as authActions from './auth/authActions'
import {
getProjectLoadError,
getProjectLoadErrorSelector,
getProjectSelector,
getProjectVotesError
getProjectVotesErrorSelector
} from './project/projectSelectors'
import * as projectActions from './project/projectActions'
import Error from '../baseComponents/customComponent/Error'
import LoaderMatchParent from '../baseComponents/customComponent/LoaderMatchParent'
import { getLoginErrorSelector } from './auth/authSelectors'
import Footer from './layout/Footer'
import { getSessionsDates } from '../core/sessions/sessionsSelectors'
import { getSessionsDatesSelector } from '../core/sessions/sessionsSelectors'

const styles = theme => ({
loading: {
Expand Down Expand Up @@ -112,9 +112,9 @@ class AppLayout extends Component {

const mapStateToProps = state => ({
project: getProjectSelector(state),
dates: getSessionsDates(state),
projectLoadError: getProjectLoadError(state),
projectVotesError: getProjectVotesError(state),
dates: getSessionsDatesSelector(state),
projectLoadError: getProjectLoadErrorSelector(state),
projectVotesError: getProjectVotesErrorSelector(state),
loginError: getLoginErrorSelector(state)
})

Expand Down
6 changes: 3 additions & 3 deletions src/feedback/auth/authActionTypes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS'
export const LOGIN_ERROR = 'LOGIN_ERROR'
export const LOGOUT = 'LOGOUT'
export const LOGIN_SUCCESS = 'login/success'
export const LOGIN_ERROR = 'login/error'
export const LOGOUT = 'logout'
4 changes: 2 additions & 2 deletions src/feedback/auth/authActions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { authProvider } from '../../firebase'
import { LOGIN_ERROR, LOGIN_SUCCESS, LOGOUT } from './authActionTypes'
import { isLogged } from './authSelectors'
import { isLoggedSelector } from './authSelectors'
import { getVotes } from '../vote/voteActions'

export const signIn = () => {
return (dispatch, getState) => {
if (isLogged(getState())) {
if (isLoggedSelector(getState())) {
return
}
authProvider.onAuthStateChanged(user => {
Expand Down
8 changes: 4 additions & 4 deletions src/feedback/auth/authSelectors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const getAuth = state => state.auth
export const getAuthSelector = state => state.auth

export const isLogged = state => getAuth(state).isLogin
export const isLoggedSelector = state => getAuthSelector(state).isLogin

export const getUser = state => getAuth(state).user
export const getUserSelector = state => getAuthSelector(state).user

export const getLoginErrorSelector = state => getAuth(state).error
export const getLoginErrorSelector = state => getAuthSelector(state).error
5 changes: 0 additions & 5 deletions src/feedback/auth/index.js

This file was deleted.

19 changes: 0 additions & 19 deletions src/feedback/layout/logo.svg

This file was deleted.

16 changes: 8 additions & 8 deletions src/feedback/project/projectActionTypes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const GET_PROJECT_SUCCESS = 'GET_PROJECT_SUCCESS'
export const GET_PROJECT_ERROR = 'GET_PROJECT_ERROR'
export const GET_PROJECT_VOTE_ITEMS_SUCCESS = 'GET_PROJECT_VOTE_ITEMS_SUCCESS'
export const GET_PROJECT_VOTE_ITEMS_ERROR = 'GET_PROJECT_VOTE_ITEMS_ERROR'
export const GET_PROJECT_VOTE_RESULT_SUCCESS = 'GET_PROJECT_VOTE_RESULT_SUCCESS'
export const GET_PROJECT_VOTE_RESULT_ERROR = 'GET_PROJECT_VOTE_RESULT_ERROR'
export const INCREMENT_VOTE_LOCALY = 'INCREMENT_VOTE_LOCALY'
export const SET_SELECTED_DATE = 'SET_SELECTED_DATE'
export const GET_PROJECT_SUCCESS = 'project/get/success'
export const GET_PROJECT_ERROR = 'project/get/error'
export const GET_PROJECT_VOTE_ITEMS_SUCCESS = 'project/getVoteItems/success'
export const GET_PROJECT_VOTE_ITEMS_ERROR = 'project/getVoteItems/error'
export const GET_PROJECT_VOTE_RESULT_SUCCESS = 'project/getVoteResult/success'
export const GET_PROJECT_VOTE_RESULT_ERROR = 'project/getVoteResult/error'
export const INCREMENT_VOTE_LOCALLY = 'project/incrementVoteLocally'
export const SET_SELECTED_DATE = 'project/setSelectedDate'
Loading

0 comments on commit 93ebe5a

Please sign in to comment.