-
Notifications
You must be signed in to change notification settings - Fork 14
Ht4 #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maximgatilin
wants to merge
6
commits into
romabelka:master
Choose a base branch
from
maximgatilin:HT4
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ht4 #23
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
adfe309
#HT4 Change config and fix bug with offset
maximgatilin 64cc828
#HT4 Use custom component for rows in events table
maximgatilin d40f110
#HT4 Make possible to drag event and drop it into basket(without db r…
maximgatilin 1b62cac
#HT4 Delete event from Redux store after deleting it from db
maximgatilin f6ff4c2
#HT4 Create drag preview for event
maximgatilin 1e799e9
#HT4 Change basket color on hover
maximgatilin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import React, {Component} from 'react' | ||
| import {DropTarget} from 'react-dnd' | ||
| import {deleteEvent} from '../../ducks/events' | ||
| import {connect} from 'react-redux' | ||
|
|
||
| class Basket extends Component { | ||
| render() { | ||
| const {connectDropTarget, hovered} = this.props; | ||
| const basketColor = hovered ? 'red': '#888'; | ||
| const style = { | ||
| width: '300px', | ||
| height: '100px', | ||
| border: `1px solid ${basketColor}`, | ||
| textAlign: 'center', | ||
| lineHeight: '100px', | ||
| color: basketColor | ||
| }; | ||
| return connectDropTarget(<div style={style}>Basket</div>); | ||
| } | ||
| } | ||
|
|
||
| const spec = { | ||
| drop(props, monitor) { | ||
| const item = monitor.getItem(); | ||
| const {deleteEvent} = props; | ||
| deleteEvent(item.id); | ||
| } | ||
| }; | ||
|
|
||
| const collect = (connect, monitor) => ({ | ||
| connectDropTarget: connect.dropTarget(), | ||
| canDrop: monitor.canDrop(), | ||
| hovered: monitor.isOver() | ||
| }); | ||
|
|
||
| export default connect( | ||
| null, | ||
| { | ||
| deleteEvent | ||
| }) | ||
| (DropTarget(['event'], spec, collect)(Basket)) |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import React, { Component } from 'react' | ||
| import {connect} from 'react-redux' | ||
| import {eventSelector} from '../../ducks/events' | ||
|
|
||
| class EventDragPreview extends Component { | ||
| static propTypes = { | ||
|
|
||
| }; | ||
|
|
||
| render() { | ||
| return ( | ||
| <div> | ||
| <h3 style={{ | ||
| width: '600px', | ||
| border: '1px solid black', | ||
| textAlign: 'center', | ||
| background: '#aaa' | ||
| }}> | ||
| {this.props.event.title} | ||
| </h3> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default connect((state, props) => ({ | ||
| event: eventSelector(state, props) | ||
| }))(EventDragPreview) |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import React, { Component } from 'react' | ||
| import {DragSource} from 'react-dnd' | ||
| import {getEmptyImage} from 'react-dnd-html5-backend' | ||
| import DragPreview from './EventDragPreview' | ||
|
|
||
| class EventRow extends Component { | ||
| static propTypes = { | ||
|
|
||
| }; | ||
|
|
||
| componentDidMount() { | ||
| this.props.connectPreview(getEmptyImage()) | ||
| } | ||
|
|
||
| handleClick = (data) => () => { | ||
| this.props.onRowClick(data.uid); | ||
| }; | ||
|
|
||
| render() { | ||
| const cellStyle = { | ||
| display: 'inline-block', | ||
| marginRight: '15px', | ||
| width: '200px' | ||
| }; | ||
| const {style, event, connectDragSource} = this.props; | ||
| return connectDragSource(<div style={style} onClick={this.handleClick(event)}> | ||
| <span style={cellStyle}>{event.title}</span> | ||
| <span style={cellStyle}>{event.where}</span> | ||
| <span style={cellStyle}>{event.when}</span> | ||
| </div>) | ||
| } | ||
| } | ||
|
|
||
| const spec = { | ||
| beginDrag(props) { | ||
| return { | ||
| id: props.event.uid, | ||
| DragPreview | ||
| } | ||
| }, | ||
|
|
||
| endDrag() { | ||
| console.log('---', 'endDrag') | ||
| } | ||
| }; | ||
|
|
||
| const collect = (connect, monitor) => ({ | ||
| connectDragSource: connect.dragSource(), | ||
| connectPreview: connect.dragPreview(), | ||
| isDragging: monitor.isDragging() | ||
| }); | ||
|
|
||
| export default DragSource('event', spec, collect)(EventRow) |
This file contains hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
| import firebase from 'firebase' | ||
|
|
||
| export const appName = 'advreact-1610' | ||
| export const appName = 'react-course-f262b' | ||
|
|
||
| firebase.initializeApp({ | ||
| apiKey: "AIzaSyB31xpTtp4Jln_hb2kAbE4PGf6Mi8EgLyA", | ||
| authDomain: `${appName}.firebaseapp.com`, | ||
| databaseURL: `https://${appName}.firebaseio.com`, | ||
| projectId: appName, | ||
| storageBucket: "", | ||
| messagingSenderId: "397157634637" | ||
| apiKey: "AIzaSyAt-smU_1tqNdkj9pmSpVLxqaOjhDwf4dk", | ||
| storageBucket: "react-course-f262b.appspot.com", | ||
| messagingSenderId: "447165438476" | ||
| }) |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -18,6 +18,10 @@ export const FETCH_LAZY_REQUEST = `${prefix}/FETCH_LAZY_REQUEST` | |
| export const FETCH_LAZY_START = `${prefix}/FETCH_LAZY_START` | ||
| export const FETCH_LAZY_SUCCESS = `${prefix}/FETCH_LAZY_SUCCESS` | ||
|
|
||
| export const DELETE_EVENT_REQUEST = `${prefix}/DELETE_EVENT_REQUEST` | ||
| export const DELETE_EVENT_START = `${prefix}/DELETE_EVENT_START` | ||
| export const DELETE_EVENT_SUCCESS = `${prefix}/DELETE_EVENT_SUCCESS` | ||
|
|
||
| export const SELECT_EVENT = `${prefix}/SELECT_EVENT` | ||
|
|
||
|
|
||
|
|
@@ -63,6 +67,9 @@ export default function reducer(state = new ReducerRecord(), action) { | |
|
|
||
| case SELECT_EVENT: | ||
| return state.update('selected', selected => selected.add(payload.uid)) | ||
| case DELETE_EVENT_SUCCESS: | ||
| return state | ||
| .deleteIn(['entities', action.payload.uid]); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Да, единственное что - лучше бы из person тоже удалять этот ивент. |
||
|
|
||
| default: | ||
| return state | ||
|
|
@@ -82,6 +89,8 @@ export const eventListSelector = createSelector(entitiesSelector, entities => en | |
| export const selectedEventsSelector = createSelector(entitiesSelector, selectionSelector, (entities, selection) => | ||
| selection.map(uid => entities.get(uid)) | ||
| ) | ||
| export const idSelector = (state, props) => props.id | ||
| export const eventSelector = createSelector(entitiesSelector, idSelector, (entities, id) => entities.get(id)) | ||
|
|
||
| /** | ||
| * Action Creators | ||
|
|
@@ -106,6 +115,13 @@ export function fetchLazy() { | |
| } | ||
| } | ||
|
|
||
| export function deleteEvent(uid) { | ||
| return { | ||
| type: DELETE_EVENT_REQUEST, | ||
| payload: { uid } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sagas | ||
| * */ | ||
|
|
@@ -154,6 +170,21 @@ export const fetchLazySaga = function * () { | |
| } | ||
| } | ||
|
|
||
| export const deleteEventSaga = function * ({payload}) { | ||
| const ref = firebase.database().ref(`events/${payload.uid}`); | ||
|
|
||
| yield put({ | ||
| type: DELETE_EVENT_START | ||
| }); | ||
|
|
||
| yield call([ref, ref.remove]); | ||
|
|
||
| yield put({ | ||
| type: DELETE_EVENT_SUCCESS, | ||
| payload | ||
| }) | ||
| }; | ||
|
|
||
| //lazy fetch FB | ||
| /* | ||
| firebase.database().ref('events') | ||
|
|
@@ -165,6 +196,7 @@ firebase.database().ref('events') | |
| export function* saga() { | ||
| yield all([ | ||
| takeEvery(FETCH_ALL_REQUEST, fetchAllSaga), | ||
| takeEvery(DELETE_EVENT_REQUEST, deleteEventSaga), | ||
| fetchLazySaga() | ||
| ]) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@romabelka Правильно ли здесь применен
.deleteIn? (Нет опыта с ImmutableJS)