Skip to content

Commit

Permalink
Revert "[WIP] Issue setlife-network#22"
Browse files Browse the repository at this point in the history
This reverts commit 18c4c0e.
  • Loading branch information
Federico Madoery committed Jan 8, 2019
1 parent 18c4c0e commit 8702089
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 151 deletions.
4 changes: 2 additions & 2 deletions config/paths.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path')
const fs = require('fs')
var path = require('path')
var fs = require('fs')

const projectDirectory = fs.realpathSync(process.cwd())
const resolve = relativePath => path.resolve(projectDirectory, relativePath)
Expand Down
87 changes: 6 additions & 81 deletions web/components/BlockList.jsx
Original file line number Diff line number Diff line change
@@ -1,87 +1,12 @@
import React from 'react';
import { connect } from 'react-redux';
import moment from 'moment';
import { cloneDeep } from 'lodash';

import SetBlock from './SetBlock';
import Text from './Text';
import { DEFAULT_SETBLOCKS } from '../constants';

import {
setEnableSubmit, updateUnsavedSetblocks,
} from '../reducers/environment';

class BlockList extends React.Component {

completeWithEmptySetBlocks(setBlocks) {
const defaultSetBlocks = cloneDeep(DEFAULT_SETBLOCKS);
let replacedBlocks = 0;
setBlocks = _.orderBy(setBlocks, ['blockTime'], ['asc']); // Use Lodash to sort array by 'name'
setBlocks = _.uniqBy(setBlocks, 'blockTime'); // Use Lodash to delete repeated blockTimes
if (setBlocks && setBlocks.length > 0) { // To avoid iterate if the array is empty, return default
defaultSetBlocks.forEach((setBlock, index, theArray) => {
if (setBlocks && replacedBlocks < setBlocks.length && setBlock.blockTime === setBlocks[replacedBlocks].blockTime) {
theArray[index] = setBlocks[replacedBlocks];
replacedBlocks++;
}
});
}
return defaultSetBlocks
}

updateUnsavedSetBlock(selectedDay, index, editedSetBlock ) {
const { unsavedSetBlocks } = this.props
let dayEdited = unsavedSetBlocks[selectedDay];
dayEdited[index] = editedSetBlock; // index 0 = SetBlock with blockTime 1
this.props.updateUnsavedSetblocks({
...unsavedSetBlocks,
[selectedDay]: dayEdited
})
this.props.setEnableSubmit(true)
}

export default class BlockList extends React.Component {
render() {
const {
editModeSchedule, currentWeeklySetblocks, unsavedSetBlocks, selectedDay
} = this.props;
const selectedDayFormatted = moment(selectedDay).format('YYYY-MM-DD')
let setBlocksByDate = _.groupBy(currentWeeklySetblocks, 'date');
let setBlocks = setBlocksByDate[selectedDayFormatted];

if (editModeSchedule && unsavedSetBlocks ) {
// As it is your schedule, you can see the empty blocks, to complete then, that's why it is completed with the missing ones
return this.completeWithEmptySetBlocks(setBlocks).map((setBlock, index) => {
return (
<SetBlock
data={setBlock}
key={setBlock.id || (index + selectedDayFormatted)}
editMode={editModeSchedule}
updateSetBlock={(editedSetBlock) => this.updateUnsavedSetBlock(selectedDayFormatted, index, editedSetBlock )}
/>
)
})
} else if (!editModeSchedule && setBlocks) {
return setBlocks.map((setBlock, index) => {
return <SetBlock data={setBlock} key={setBlock.id || index} />
})
} else {
return (
<Text weight='600' align='center'> This user hasn't committed any Setblocks for this day </Text>
)
}
return (
<div className='BlockList'>
<h6>BlockList</h6>
</div>
);
}
}

const mapStateToProps = ({ environment }) => {
return {
...environment
};
};

const mapDispatchToProps = (dispatch) => {
return {
setEnableSubmit: (enableSubmit) => dispatch(setEnableSubmit(enableSubmit)),
updateUnsavedSetblocks: (unsavedSetBlocks) => dispatch(updateUnsavedSetblocks(unsavedSetBlocks))
};
};
export default connect(mapStateToProps, mapDispatchToProps)(BlockList);
2 changes: 1 addition & 1 deletion web/components/CommitBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import moment from 'moment';
import { connect } from 'react-redux';
import { Check } from 'styled-icons/feather/Check.cjs'

import Text from './Text';
import Card from './Card';
import Flex from './Flex';
import Text from './Text';

import { createSetBlock, setEditModeSchedule, updateSetBlock } from '../reducers/environment';

Expand Down
5 changes: 2 additions & 3 deletions web/components/DayBlock.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from 'react';
import { connect } from 'react-redux';
import moment from 'moment';
import React from 'react';


import Card from './Card';
import Flex from './Flex';
import Text from './Text';
import Card from './Card';

class DayBlock extends React.Component {

Expand Down
2 changes: 1 addition & 1 deletion web/components/NavigationBar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { connect } from 'react-redux';
import _ from 'lodash'
var _ = require('lodash');

import NavLinkItem from './NavLinkItem';

Expand Down
76 changes: 57 additions & 19 deletions web/components/SchedulePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ import moment from 'moment';
import { connect } from 'react-redux';
import { cloneDeep } from 'lodash';

import BlockList from './BlockList';
import CommitBlock from './CommitBlock';
import Flex from './Flex';
import LoadingDots from './Loading';
import ScheduleHeader from './ScheduleHeader';
import SideBar from './SideBar';
import Flex from './Flex';
import SetBlock from './SetBlock';
import Text from './Text';

import { DEFAULT_SETBLOCKS } from '../constants';
import LoadingDots from './Loading';
import CommitBlock from './CommitBlock';
import { DEFAULT_SETBLOCKS } from '../constants/index';

import {
fetchCurrentTeamMemberById,
setEditModeSchedule,
setEnableSubmit,
setSelectedDay,
updateUnsavedSetblocks
} from '../reducers/environment';
Expand All @@ -25,6 +23,7 @@ import {
class SchedulePage extends React.Component {
state = {
daysOfWeek: [],
enableSubmit: false,
}

componentDidMount() {
Expand Down Expand Up @@ -70,7 +69,7 @@ class SchedulePage extends React.Component {
// This only take effect if change the currentTeamMember
if ((editModeSchedule && currentTeamMember !== nextProps.currentTeamMember) || selectedDay !== nextProps.selectedDay) {
this.makeSetBlocksForEdit(nextProps.currentWeeklySetblocks);
this.props.setEnableSubmit(false)
this.setState({ enableSubmit: false })
}
}

Expand All @@ -87,21 +86,61 @@ class SchedulePage extends React.Component {
let replacedBlocks = 0;
setBlocks = _.orderBy(setBlocks, ['blockTime'], ['asc']); // Use Lodash to sort array by 'name'
setBlocks = _.uniqBy(setBlocks, 'blockTime'); // Use Lodash to delete repeated blockTimes
if (setBlocks && setBlocks.length > 0) { // To avoid iterate if the array is empty, return default
defaultSetBlocks.forEach((setBlock, index, theArray) => {
if (setBlocks && replacedBlocks < setBlocks.length && setBlock.blockTime === setBlocks[replacedBlocks].blockTime) {
theArray[index] = setBlocks[replacedBlocks];
replacedBlocks++;
}
});
}
defaultSetBlocks.forEach((setBlock, index, theArray) => {
if (setBlocks && replacedBlocks < setBlocks.length && setBlock.blockTime === setBlocks[replacedBlocks].blockTime) {
theArray[index] = setBlocks[replacedBlocks];
replacedBlocks++;
}
});
return defaultSetBlocks
}

updateUnsavedSetBlock(selectedDay, index, editedSetBlock ) {
const { unsavedSetBlocks } = this.props
let dayEdited = unsavedSetBlocks[selectedDay];
dayEdited[index] = editedSetBlock; // index 0 = SetBlock with blockTime 1
this.props.updateUnsavedSetblocks({
...unsavedSetBlocks,
[selectedDay]: dayEdited
})
this.setState({ enableSubmit: true })
}

renderSetBlocks = (selectedDay) => {
const { editModeSchedule, currentWeeklySetblocks, unsavedSetBlocks } = this.props;
selectedDay = moment(selectedDay).format('YYYY-MM-DD')
const setBlocksByDate = _.groupBy(currentWeeklySetblocks, 'date')
let setBlocks = setBlocksByDate[selectedDay];

if (editModeSchedule && unsavedSetBlocks) {
// If the match.params don't have a teamMemberId are u seeing your schedule
// As it is your schedule, you can see the empty blocks, to complete then, that's why it is completed with the missing ones
return this.completeWithEmptySetBlocks(setBlocks).map((setBlock, index) => {
return (
<SetBlock
data={setBlock}
key={setBlock.id || (index + selectedDay)}
editMode={editModeSchedule}
updateSetBlock={(editedSetBlock) => this.updateUnsavedSetBlock(selectedDay, index, editedSetBlock )}
/>
)
})
} else if (!editModeSchedule && setBlocks) {
return setBlocks.map((setBlock, index) => {
return <SetBlock data={setBlock} key={setBlock.id || index} />
})
} else {
return (
<Text weight='600' align='center'> This user hasn't committed any Setblocks for this day </Text>
)
}
}

renderIfItReady() {
const {
match, currentTeamMember, fetchingData, editModeSchedule, enableSubmit
match, currentTeamMember, fetchingData, selectedDay, editModeSchedule
} = this.props
const { enableSubmit } = this.state

if (fetchingData) {
return ( // If you are waiting for the API to respond, render a loading
Expand All @@ -122,7 +161,7 @@ class SchedulePage extends React.Component {
{match.params.teamMemberId ? currentTeamMember.name : 'Your'}
{' Schedule\'s Page'}
</Text>
<BlockList />
{this.renderSetBlocks(selectedDay)}
{editModeSchedule && (<CommitBlock enableSubmit={enableSubmit} />)}
</Flex>
)
Expand Down Expand Up @@ -173,7 +212,6 @@ const mapDispatchToProps = (dispatch) => {
fetchCurrentTeamMemberById: (params) => dispatch(fetchCurrentTeamMemberById(params)),
setSelectedDay: (selectedDay) => dispatch(setSelectedDay(selectedDay)),
setEditModeSchedule: (editMode) => dispatch(setEditModeSchedule(editMode)),
setEnableSubmit: (enableSubmit) => dispatch(setEnableSubmit(enableSubmit)),
updateUnsavedSetblocks: (unsavedSetBlocks) => dispatch(updateUnsavedSetblocks(unsavedSetBlocks))
};
};
Expand Down
6 changes: 3 additions & 3 deletions web/components/SetBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React from 'react';
import { connect } from 'react-redux';
import { Edit3 } from 'styled-icons/feather/Edit3.cjs'

import Box from './Box';
import Card from './Card';
import Flex from './Flex';
import Text from './Text';
import Card from './Card';
import Modal from './Modal';
import Box from './Box';
import Input from './Input';
import Text from './Text';


class SetBlock extends React.Component {
Expand Down
2 changes: 1 addition & 1 deletion web/components/SideBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import { withRouter } from 'react-router-dom';
import { connect } from 'react-redux';

import DayBlock from './DayBlock';
import Flex from './Flex';
import DayBlock from './DayBlock';

import { setEditModeSchedule, setSelectedDay } from '../reducers/environment';

Expand Down
5 changes: 2 additions & 3 deletions web/components/TeamMember.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';

import Card from './Card';
import Flex from './Flex';
import Image from './Image';
import Text from './Text';

import Card from './Card';
import Image from './Image';

export default class TeamMember extends React.Component {
render() {
Expand Down
Loading

0 comments on commit 8702089

Please sign in to comment.