forked from setlife-network/setblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "[WIP] Issue setlife-network#22"
This reverts commit 18c4c0e.
- Loading branch information
Federico Madoery
committed
Jan 8, 2019
1 parent
18c4c0e
commit 8702089
Showing
10 changed files
with
98 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.