-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
231 additions
and
132 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './mentions'; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as types from './types'; | ||
|
||
export const mentionSearch = value => ({ | ||
type: types.MENTION_SEARCH, | ||
value, | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* global describe, it, expect */ | ||
import * as actions from './mentions'; | ||
import * as types from './types'; | ||
|
||
describe('Actions', () => { | ||
describe('Mentions', () => { | ||
it('Creates an action to search for persons', () => { | ||
const value = 'John'; | ||
|
||
const expected = { | ||
type: types.MENTION_SEARCH, | ||
value, | ||
}; | ||
|
||
expect(actions.mentionSearch(value)).toEqual(expected); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export const MENTION_SEARCH = 'MENTION_SEARCH'; |
66 changes: 66 additions & 0 deletions
66
src/components/Home/AutocompleteEditor/AutocompleteEditor.jsx
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { Component } from 'react'; | ||
import { CompositeDecorator, EditorState } from 'draft-js'; | ||
import Editor from 'draft-js-plugins-editor'; | ||
import 'draft-js-mention-plugin/lib/plugin.css'; | ||
import createMentionPlugin from 'draft-js-mention-plugin'; | ||
|
||
const mentionPlugin = createMentionPlugin(); | ||
const { MentionSuggestions } = mentionPlugin; | ||
const plugins = [mentionPlugin]; | ||
|
||
const styles = { | ||
root: { | ||
padding: 20, | ||
width: 600, | ||
}, | ||
editor: { | ||
border: '1px solid #ddd', | ||
cursor: 'text', | ||
fontSize: 16, | ||
minHeight: 40, | ||
padding: 10, | ||
}, | ||
}; | ||
|
||
class AutocompleteEditor extends Component { | ||
constructor() { | ||
super(); | ||
|
||
this.state = { | ||
editorState: EditorState.createEmpty(), | ||
}; | ||
|
||
this.focus = () => this.refs.editor.focus(); | ||
this.onChange = editorState => this.setState({ editorState }); | ||
this.onSearchChange = this.onSearchChange.bind(this); | ||
} | ||
|
||
onSearchChange({ value }) { | ||
const { onMentionSearch } = this.props; | ||
onMentionSearch(value); | ||
} | ||
|
||
render() { | ||
const { mentionSuggestions } = this.props; | ||
|
||
return ( | ||
<div style={styles.root}> | ||
<div style={styles.editor} onClick={this.focus}> | ||
<Editor | ||
editorState={this.state.editorState} | ||
onChange={this.onChange} | ||
ref="editor" | ||
plugins={plugins} | ||
spellCheck | ||
/> | ||
<MentionSuggestions | ||
onSearchChange={this.onSearchChange} | ||
suggestions={mentionSuggestions} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default AutocompleteEditor; |
20 changes: 0 additions & 20 deletions
20
src/components/Home/AutocompleteEditor/HandleSpan/index.jsx
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
src/components/Home/AutocompleteEditor/HashtagSpan/index.jsx
This file was deleted.
Oops, something went wrong.
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,68 +1,3 @@ | ||
import React, { Component } from 'react'; | ||
import { CompositeDecorator, EditorState } from 'draft-js'; | ||
import Editor from 'draft-js-plugins-editor'; | ||
import 'draft-js-mention-plugin/lib/plugin.css'; | ||
import createMentionPlugin, { defaultSuggestionsFilter } from 'draft-js-mention-plugin'; | ||
import mentions from '../../../data/mentions'; | ||
|
||
const mentionPlugin = createMentionPlugin(); | ||
const { MentionSuggestions } = mentionPlugin; | ||
const plugins = [mentionPlugin]; | ||
|
||
const styles = { | ||
root: { | ||
padding: 20, | ||
width: 600, | ||
}, | ||
editor: { | ||
border: '1px solid #ddd', | ||
cursor: 'text', | ||
fontSize: 16, | ||
minHeight: 40, | ||
padding: 10, | ||
}, | ||
}; | ||
|
||
class AutocompleteEditor extends Component { | ||
constructor() { | ||
super(); | ||
|
||
this.state = { | ||
editorState: EditorState.createEmpty(), | ||
suggestions: mentions, | ||
}; | ||
|
||
this.focus = () => this.refs.editor.focus(); | ||
this.onChange = editorState => this.setState({ editorState }); | ||
this.onSearchChange = this.onSearchChange.bind(this); | ||
} | ||
|
||
onSearchChange({ value }) { | ||
this.setState({ | ||
suggestions: defaultSuggestionsFilter(value, mentions), | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div style={styles.root}> | ||
<div style={styles.editor} onClick={this.focus}> | ||
<Editor | ||
editorState={this.state.editorState} | ||
onChange={this.onChange} | ||
ref="editor" | ||
plugins={plugins} | ||
spellCheck | ||
/> | ||
<MentionSuggestions | ||
onSearchChange={this.onSearchChange} | ||
suggestions={this.state.suggestions} | ||
onAddMention={this.onAddMention} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
import AutocompleteEditor from './AutocompleteEditor'; | ||
|
||
export default AutocompleteEditor; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { connect } from 'react-redux'; | ||
import { mentionSearch } from '../../actions/mentions'; | ||
import AutocompleteEditor from '../../components/Home/AutocompleteEditor'; | ||
import * as mentions from '../../selectors/mentions'; | ||
|
||
const mapStateToProps = state => ({ | ||
mentionSuggestions: mentions.getSuggestions(state), | ||
}); | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
onMentionSearch: value => dispatch(mentionSearch(value)), | ||
}); | ||
|
||
const AutocompleteEditorContainer = connect( | ||
mapStateToProps, | ||
mapDispatchToProps, | ||
)(AutocompleteEditor); | ||
|
||
export default AutocompleteEditorContainer; |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { combineReducers } from 'redux'; | ||
import mentions from './mentions'; | ||
|
||
const reducer = combineReducers({ | ||
mentions, | ||
}); | ||
|
||
export default reducer; |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import mentions from '../../../../data/mentions'; | ||
|
||
const initialState = mentions; | ||
|
||
export default function reducer(state = initialState, action) { | ||
switch (action.type) { | ||
default: | ||
return state; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { combineReducers } from 'redux'; | ||
import entities from './entities'; | ||
import ui from './ui'; | ||
|
||
const reducer = combineReducers({ | ||
entities, | ||
ui, | ||
}); | ||
|
||
export default reducer; |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { combineReducers } from 'redux'; | ||
import mentions from './mentions'; | ||
|
||
const reducer = combineReducers({ | ||
mentions, | ||
}); | ||
|
||
export default reducer; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import mentions from './mentions'; | ||
|
||
export default mentions; |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as types from '../../../../actions/mentions/types'; | ||
|
||
const initialState = { | ||
search: '', | ||
}; | ||
|
||
export default function reducer(state = initialState, action) { | ||
switch (action.type) { | ||
case types.MENTION_SEARCH: | ||
return { ...state, search: action.value }; | ||
default: | ||
return state; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* global describe, it, expect */ | ||
import deepFreeze from 'deep-freeze'; | ||
import * as types from '../../../../actions/mentions/types'; | ||
import reducer from './mentions'; | ||
|
||
describe('Home', () => { | ||
describe('UI Reducer', () => { | ||
describe('Mentions', () => { | ||
it('Returns the initial state', () => { | ||
expect(reducer(undefined, {})).toEqual({ | ||
search: '', | ||
}); | ||
}); | ||
|
||
it('Updates mention search value', () => { | ||
const state = { | ||
search: 'Joh', | ||
}; | ||
|
||
deepFreeze(state); | ||
|
||
const action = { | ||
type: types.MENTION_SEARCH, | ||
value: 'John', | ||
}; | ||
|
||
const expected = { | ||
search: 'John', | ||
}; | ||
|
||
expect(reducer(state, action)).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
}); |
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,8 +1,10 @@ | ||
import { combineReducers } from 'redux'; | ||
import { routerReducer as routing } from 'react-router-redux'; | ||
import home from './home'; | ||
|
||
const reducer = combineReducers({ | ||
routing, | ||
home, | ||
}); | ||
|
||
export default reducer; |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const mentionSuggestions = (props, propName, componentName) => { | ||
if (!List.isList(props[propName])) { | ||
return new Error( | ||
`Invalid prop \`${propName}\` supplied to \`${componentName}\`. should be an instance of immutable list.` | ||
); | ||
} | ||
return undefined; | ||
}, |
Oops, something went wrong.