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.
Code Cleanup Alphabetical ordering of imports and actions (in redux) Implementation of BlockList to manage and render the Set Blocks, to improve the readability of Schedule Page by reducing your code length Enable Submit now is managed through redux UI Polish Fix alignment for Setblocks scheduled within the same day and make sure the setblock dots (on both the sidebar and the main page are perfect squares instead of rectangles - Was Fixed some commits ago in PR "Close Issue setlife-network#9" Fix alignment on the empty state UI "This user hasn't committed..." - Was Fixed some commits ago in PR "Close Issue setlife-network#9"
- Loading branch information
Federico Madoery
committed
Jan 8, 2019
1 parent
ccfba9f
commit 18c4c0e
Showing
10 changed files
with
151 additions
and
98 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,12 +1,87 @@ | ||
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() { | ||
return ( | ||
<div className='BlockList'> | ||
<h6>BlockList</h6> | ||
</div> | ||
); | ||
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> | ||
) | ||
} | ||
} | ||
} | ||
|
||
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.