-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add a chat switcher to the LHN #282
Merged
Merged
Changes from all commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
fa0e2e5
Rename directories and move files around a little
tgolen a45f4e5
Refactor the sidebar into separate components
tgolen 72b4bb9
Rename file
tgolen 30a715d
Add initial search form
tgolen ba49562
Hide and show the report list on blur and focus
tgolen f5d8207
Remove color
tgolen 804b5c5
Remove extra method
tgolen 1d04aad
Get the search options to appear
tgolen 989a4c2
Reset the view on tab and escape
tgolen 94e9d7d
Show focused option
tgolen 3578e59
Select the option and reset the component
tgolen 3ced899
Add keyboard shortcut lib
tgolen c15b31e
Enable the command+k keyboard shortcut
tgolen 5e33acc
Make the clear button do a full reset
tgolen a51e81b
Add some comments and shorten line
tgolen 358a970
Add some styles and the avatar to the list
tgolen 3527824
Merge branch 'master' into tgolen-chat-switcher
tgolen 7cc9ebb
Fix paths
tgolen 5c6ef87
Move focued index into the state
tgolen aa5ff2e
Make logic more explicit
tgolen 972832e
DRY up proptypes for insets
tgolen 632b596
Add more comments about using Set
tgolen fbe8937
More comment cleanup
tgolen 21116f8
Enable key listening when typing a comment
tgolen 8abe2c1
Rename and move inset prop types
tgolen 3b98fc9
Fix prop types for personal details
tgolen 9aa438e
Reference the color variables directly
tgolen 91d6b62
Give a proper icon for the clear text button
tgolen fe8daee
Moving the logo into the chat switcher
tgolen f336455
Switch to the round logo
tgolen 93cc7cd
Add indicator status styles
tgolen 8a07b33
Remove duplicate file
tgolen dd16527
Add missing semicolon
tgolen 0acc17c
Merge branch 'master' into tgolen-chat-switcher
tgolen 133c06a
Put the logo on the same line as the chat switcher
tgolen 34684ee
Reset the search when deleting all text
tgolen a6615aa
Fix some blur bugs
tgolen 976b545
Remove extra semicolon
tgolen 1b5813d
Fix display name
tgolen 0501a9f
Update the logo asset
shawnborton f21dd6a
Align the sidebarHeader area better
shawnborton d158608
Updating some styles of the list items
shawnborton 82dd0f0
Fix props warning
tgolen 410a516
Improve display name
tgolen 3af20fe
A few margin tweaks
shawnborton 15d718b
Fix truncated text
tgolen cc8da28
Add inset margin
tgolen 4961151
Merge branch 'tgolen-chat-switcher' of https://github.com/Expensify/R…
tgolen 3edaae7
Make the blur work better
tgolen dd3aa46
Show the clear button on focus
tgolen 8350c63
Fix sign in logo
shawnborton 2202e24
Turn off outline for text input
tgolen 935fc86
Change placeholder text color
shawnborton 2b53a62
Add a component which allows for focus and blur styles
tgolen 2dc1dcc
Merge branch 'tgolen-chat-switcher' of https://github.com/Expensify/R…
tgolen 179098e
remove outline style because mobile doesn't support it
tgolen a5ac9fe
Merge branch 'master' into tgolen-chat-switcher
tgolen 51c5146
Move the chat switcher list into a stateless component
tgolen 33b56ba
Move the search form into it's own stateless component
tgolen f4fe554
Fix lint errors and fix proptypes
tgolen 6c851d1
Focus styles for the search input
shawnborton 2197aa7
Use a background color for the images while they are loading
shawnborton e5009e4
Fix sidebarHeader height on mobile
shawnborton 5358226
Hide bottom of the sidebar when the chat switcher has focus
tgolen 0502d85
Fix some flex grow weirdness
shawnborton 5a9cda1
Simplify keyboard shortcut
tgolen 2f388d5
Use a state property for if the component is focused
tgolen 6e052d7
Use a variable for focused input
tgolen 3dbd102
Improve style merging
tgolen f259284
Merge branch 'master' into tgolen-chat-switcher
tgolen 28d7e02
Fix casing for HOC
tgolen f7bba83
Lint
tgolen b950723
Add a method for getting a chat report
tgolen e9ac597
Implement fetching the chat report and redirecting to it
tgolen 9aa1820
Put in the proper API params
tgolen 075ed9d
Improve comments and fix lint
tgolen a6efbfe
Some last minute testing fixes
tgolen 90e9c80
Merge branch 'master' into tgolen-chat-switcher
tgolen a359f1b
Fix some lint errors
tgolen 6ec2ffa
Get the report name for the new report
tgolen 26c8b5d
Remove redundant request
tgolen a8732f8
Always merge personal details
tgolen 9b3d307
Remove extra API call
tgolen 5fbde0a
lint
tgolen 6ca354b
Fix report name
tgolen 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React from 'react'; | ||
import {TextInput, StyleSheet} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import _ from 'underscore'; | ||
|
||
const propTypes = { | ||
// A ref to forward to the text input | ||
forwardedRef: PropTypes.func.isRequired, | ||
|
||
// Styles to apply to the text input when it has focus | ||
// eslint-disable-next-line react/forbid-prop-types | ||
styleFocusIn: PropTypes.any, | ||
|
||
// Styles to apply to the text input when it does not have focus | ||
// eslint-disable-next-line react/forbid-prop-types | ||
styleFocusOut: PropTypes.any, | ||
|
||
// General styles to apply to the text input | ||
// eslint-disable-next-line react/forbid-prop-types | ||
style: PropTypes.any, | ||
|
||
// A function to call when the input has been blurred | ||
onBlur: PropTypes.func.isRequired, | ||
|
||
// A function to call when the input has gotten focus | ||
onFocus: PropTypes.func.isRequired, | ||
}; | ||
const defaultProps = { | ||
styleFocusIn: null, | ||
styleFocusOut: null, | ||
style: null, | ||
}; | ||
|
||
class TextInputWithFocusStyles extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
isFocused: false, | ||
}; | ||
} | ||
|
||
render() { | ||
// Make full objects out of both the style coming from props, and the style we have in the state | ||
const propStyles = StyleSheet.flatten(this.props.style); | ||
const focusedStyle = this.state.isFocused | ||
? StyleSheet.flatten(this.props.styleFocusIn) | ||
: StyleSheet.flatten(this.props.styleFocusOut); | ||
|
||
// Merge the two styles together | ||
const style = StyleSheet.compose(propStyles, focusedStyle); | ||
|
||
// Omit the props that are used in this intermediary component and only pass down the props that | ||
// are necessary | ||
const propsToPassToTextInput = _.omit(this.props, [ | ||
'focusInStyle', | ||
'focusOutStyle', | ||
'onFocus', | ||
'onBlur', | ||
'style', | ||
]); | ||
return ( | ||
<TextInput | ||
ref={this.props.forwardedRef} | ||
style={style} | ||
onFocus={() => { | ||
this.setState({isFocused: true}); | ||
this.props.onFocus(); | ||
}} | ||
onBlur={() => { | ||
this.setState({isFocused: false}); | ||
this.props.onBlur(); | ||
}} | ||
/* eslint-disable-next-line react/jsx-props-no-spreading */ | ||
{...propsToPassToTextInput} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
TextInputWithFocusStyles.propTypes = propTypes; | ||
TextInputWithFocusStyles.defaultProps = defaultProps; | ||
|
||
export default React.forwardRef((props, ref) => ( | ||
/* eslint-disable-next-line react/jsx-props-no-spreading */ | ||
<TextInputWithFocusStyles {...props} forwardedRef={ref} /> | ||
)); |
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,93 @@ | ||
import _ from 'underscore'; | ||
|
||
const events = {}; | ||
|
||
/** | ||
* Checks if an event for that key is configured and if so, runs it. | ||
* @param {Event} event | ||
*/ | ||
function bindHandlerToKeyupEvent(event) { | ||
if (events[event.keyCode] === undefined) { | ||
return; | ||
} | ||
|
||
// The active callback is the last element in the array | ||
const eventCallbacks = events[event.keyCode]; | ||
const callback = eventCallbacks[eventCallbacks.length - 1]; | ||
|
||
const pressedModifiers = _.all(callback.modifiers, (modifier) => { | ||
if (modifier === 'shift' && !event.shiftKey) { | ||
return false; | ||
} | ||
if (modifier === 'control' && !event.ctrlKey) { | ||
return false; | ||
} | ||
if (modifier === 'alt' && !event.altKey) { | ||
return false; | ||
} | ||
if (modifier === 'meta' && !event.metaKey) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
|
||
if (!pressedModifiers) { | ||
return; | ||
} | ||
|
||
// If configured to do so, prevent input text control to trigger this event | ||
if (!callback.captureOnInputs && ( | ||
event.target.nodeName === 'INPUT' | ||
|| event.target.nodeName === 'TEXTAREA' | ||
|| event.target.contentEditable === 'true' | ||
)) { | ||
return; | ||
} | ||
|
||
if (_.isFunction(callback.callback)) { | ||
callback.callback(event); | ||
} | ||
event.preventDefault(); | ||
} | ||
|
||
// Make sure we don't add multiple listeners | ||
document.removeEventListener('keydown', bindHandlerToKeyupEvent); | ||
document.addEventListener('keydown', bindHandlerToKeyupEvent); | ||
roryabraham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Module storing the different keyboard shortcut | ||
* | ||
* We are using a push/pop model where new event are pushed at the end of an | ||
* array of events. When the event occur, we trigger the callback of the last | ||
* element. This allow us to replace shortcut from a page to a dialog without | ||
* having the page having to handle that logic. | ||
* | ||
* This is also following the convention of the PubSub module. | ||
* The "subClass" is used by pages to bind /unbind with no worries | ||
*/ | ||
const KeyboardShortcut = { | ||
/** | ||
* Subscribes to a keyboard event. | ||
* @param {string} key The key code to watch | ||
* @param {function} callback The callback to call | ||
* @param {string|array} modifiers Can either be shift or control | ||
* @param {bool} captureOnInputs Should we capture the event on inputs too? | ||
*/ | ||
subscribe(key, callback, modifiers = 'shift', captureOnInputs = false) { | ||
const keyCode = key.charCodeAt(0); | ||
if (events[keyCode] === undefined) { | ||
events[keyCode] = []; | ||
} | ||
events[keyCode].push({callback, modifiers: _.isArray(modifiers) ? modifiers : [modifiers], captureOnInputs}); | ||
}, | ||
|
||
/** | ||
* Unsubscribes to a keyboard event. | ||
* @param {int} keyCode The key code to stop watching | ||
*/ | ||
unsubscribe(keyCode) { | ||
delete events[keyCode]; | ||
} | ||
}; | ||
|
||
export default KeyboardShortcut; |
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 @@ | ||
/** | ||
* This is a no-op component for native devices because they wouldn't be able to support keyboard shortcuts like | ||
* a website. | ||
*/ | ||
const KeyboardShortcut = { | ||
subscribe() {}, | ||
unsubscribe() {}, | ||
}; | ||
|
||
export default KeyboardShortcut; |
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.
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.
I think you can:
and then:
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.
Hmm, I tried that, and
ViewPropTypes
isundefined
... Any idea why?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.
Maybe because it's deprecated and not exported from react-native-web: reactrondev/react-native-web-swiper#41
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.
hmmm... maybe
PropTypes.instanceOf(StyleSheet)
?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.
NAB if you can't find a good way to typecheck this, but I'd be shocked if there wasn't