Skip to content

Commit ca84ad2

Browse files
committed
Merge remote-tracking branch 'origin/master' into accent-colors
* origin/master: (35 commits) bump gradle plugin for android studio add @babel/[email protected] to make `yarn install` quieter import symbol and array method polyfills split "searched query" and "typed query" so we only execute the search when the user presses "search" pass the correct argument to navigation.navigate('FilterView') update some this.state references to use references from the current scope make pretty screen when there are no filters available prevent a crash in FilterView when no filters are passed prettify use some lets and spacing fix an accidentally quadratic filter lookup allow scrolling the Recents lists remove course filters from redux move the actual searching into CourseList CourseSearch: move filters into state & pass off searching to CourseList separate opening the filterview and activating browse mode make [active] a controlled prop in AnimatedSearchBox pass [title] to AnimatedSearchbox allow passing in title as a prop to AnimatedSearchBox remove ani* prefix from animated-searchbox style names ...
2 parents 911db96 + 7a24aa8 commit ca84ad2

File tree

25 files changed

+606
-630
lines changed

25 files changed

+606
-630
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
google()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.1.0-alpha09'
9+
classpath 'com.android.tools.build:gradle:3.1.3'
1010

1111
// NOTE: Do not place your application dependencies here; they belong
1212
// in the individual module build.gradle files

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
import 'core-js/es6/symbol'
2+
import 'core-js/es6/array'
3+
14
import './source/root.js'

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"htmlparser2": "3.9.2",
9090
"keyword-search": "0.1.1",
9191
"lodash": "4.17.10",
92+
"mem": "3.0.1",
9293
"moment": "2.22.2",
9394
"moment-timezone": "0.5.21",
9495
"p-props": "1.2.0",
@@ -109,11 +110,11 @@
109110
"react-native-restart": "0.0.6",
110111
"react-native-safari-view": "2.1.0",
111112
"react-native-search-bar": "3.4.2",
112-
"react-native-searchbar": "https://github.com/MosesEsan/react-native-searchbar.git#setValue-function",
113+
"react-native-searchbar-controlled": "1.0.0",
113114
"react-native-tableview-simple": "0.17.5",
114115
"react-native-typography": "1.3.0",
115116
"react-native-vector-icons": "5.0.0",
116-
"react-navigation": "2.10.0",
117+
"react-navigation": "2.11.2",
117118
"react-navigation-material-bottom-tabs": "0.3.0",
118119
"react-redux": "5.0.7",
119120
"redux": "3.7.2",
@@ -131,6 +132,7 @@
131132
"xml2js": "0.4.19"
132133
},
133134
"devDependencies": {
135+
"@babel/core": "7.0.0-beta.44",
134136
"ajv": "6.5.2",
135137
"babel-core": "6.26.0",
136138
"babel-eslint": "8.2.6",

source/flux/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,18 @@ import reduxThunk from 'redux-thunk'
77

88
import {app, type State as AppState} from './parts/app'
99
import {homescreen, type State as HomescreenState} from './parts/homescreen'
10-
import {menus, type State as MenusState} from './parts/menus'
1110
import {settings, type State as SettingsState} from './parts/settings'
1211
import {balances, type State as BalancesState} from './parts/balances'
1312
import {buildings, type State as BuildingsState} from './parts/buildings'
1413
import {help, type State as HelpState} from './parts/help'
1514
import {courses, type State as CoursesState} from './parts/courses'
1615

1716
export {init as initRedux} from './init'
18-
export {updateMenuFilters} from './parts/menus'
1917

2018
export type ReduxState = {
2119
app?: AppState,
2220
courses?: CoursesState,
2321
homescreen?: HomescreenState,
24-
menus?: MenusState,
2522
settings?: SettingsState,
2623
balances?: BalancesState,
2724
buildings?: BuildingsState,
@@ -33,7 +30,6 @@ export const makeStore = () => {
3330
app,
3431
courses,
3532
homescreen,
36-
menus,
3733
settings,
3834
balances,
3935
buildings,

source/flux/parts/courses.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,13 @@ import {
1414
formatFilterCombo,
1515
} from '../../views/sis/course-search/lib/format-filter-combo'
1616

17-
const UPDATE_COURSE_FILTERS = 'courses/UPDATE_COURSE_FILTERS'
1817
const LOAD_CACHED_COURSES = 'courses/LOAD_CACHED_COURSES'
1918
const COURSES_LOADED = 'courses/COURSES_LOADED'
2019

2120
type Dispatch<A: Action> = (action: A | Promise<A> | ThunkAction<A>) => any
2221
type GetState = () => ReduxState
2322
type ThunkAction<A: Action> = (dispatch: Dispatch<A>, getState: GetState) => any
2423

25-
type UpdateCourseFiltersAction = {|
26-
type: 'courses/UPDATE_COURSE_FILTERS',
27-
payload: Array<FilterType>,
28-
|}
29-
export function updateCourseFilters(
30-
filters: FilterType[],
31-
): UpdateCourseFiltersAction {
32-
return {type: UPDATE_COURSE_FILTERS, payload: filters}
33-
}
34-
3524
const UPDATE_RECENT_FILTERS = 'courses/UPDATE_RECENT_FILTERS'
3625

3726
type UpdateRecentFiltersAction = {|
@@ -151,7 +140,6 @@ export function updateRecentSearches(
151140
}
152141

153142
type Action =
154-
| UpdateCourseFiltersAction
155143
| LoadCachedCoursesAction
156144
| CoursesLoadedAction
157145
| UpdateRecentSearchesAction
@@ -160,7 +148,6 @@ type Action =
160148
| LoadRecentFiltersAction
161149

162150
export type State = {|
163-
filters: Array<FilterType>,
164151
allCourses: Array<CourseType>,
165152
readyState: 'not-loaded' | 'ready',
166153
validGEs: string[],
@@ -169,7 +156,6 @@ export type State = {|
169156
|}
170157

171158
const initialState = {
172-
filters: [],
173159
allCourses: [],
174160
readyState: 'not-loaded',
175161
validGEs: [],
@@ -179,9 +165,6 @@ const initialState = {
179165

180166
export function courses(state: State = initialState, action: Action) {
181167
switch (action.type) {
182-
case UPDATE_COURSE_FILTERS:
183-
return {...state, filters: action.payload}
184-
185168
case LOAD_RECENT_FILTERS:
186169
return {...state, recentFilters: action.payload}
187170

source/flux/parts/menus.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

source/views/components/filter/filter-view.js

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,80 @@
22
import * as React from 'react'
33
import {ScrollView, StyleSheet} from 'react-native'
44
import {type FilterType} from './types'
5-
import {type ReduxState} from '../../../flux'
65
import {FilterSection} from './section'
76
import {TableView} from 'react-native-tableview-simple'
8-
import {connect} from 'react-redux'
9-
import get from 'lodash/get'
7+
import {NoticeView} from '../notice'
108

119
const styles = StyleSheet.create({
1210
container: {
1311
flex: 1,
1412
},
1513
})
1614

17-
type NavigationState = {
18-
params: {
19-
title: string,
20-
pathToFilters: string[],
21-
onChange: (x: FilterType[]) => any,
22-
onLeave?: (filters: FilterType[]) => any,
23-
},
24-
}
25-
26-
type ReactProps = {
15+
type Props = {
2716
navigation: {
28-
state: NavigationState,
17+
state: {
18+
params: {|
19+
+title: string,
20+
+initialFilters: Array<FilterType>,
21+
+onDismiss: (filters: Array<FilterType>) => mixed,
22+
|},
23+
},
24+
addListener: (
25+
ev: string,
26+
(payload: mixed) => mixed,
27+
) => {remove: () => void},
2928
},
3029
}
3130

32-
type ReduxStateProps = {
33-
filters: FilterType[],
31+
type State = {
32+
filters: Array<FilterType>,
3433
}
3534

36-
type Props = ReactProps & ReduxStateProps
35+
export class FilterView extends React.Component<Props, State> {
36+
static navigationOptions({navigation}: Props) {
37+
let {title} = navigation.state.params
38+
return {title}
39+
}
3740

38-
class FilterViewComponent extends React.PureComponent<Props> {
39-
static navigationOptions = ({navigation}: Props) => {
40-
return {
41-
title: navigation.state.params.title,
42-
}
41+
state = {
42+
filters: [],
43+
}
44+
45+
static getDerivedStateFromProps(props: Props) {
46+
let {initialFilters: filters = []} = props.navigation.state.params
47+
return {filters}
48+
}
49+
50+
componentDidMount() {
51+
this._subscription = this.props.navigation.addListener('willBlur', () => {
52+
let {onDismiss} = this.props.navigation.state.params
53+
if (onDismiss) {
54+
onDismiss(this.state.filters)
55+
}
56+
})
4357
}
4458

4559
componentWillUnmount() {
46-
if (this.props.navigation.state.params.onLeave) {
47-
this.props.navigation.state.params.onLeave(this.props.filters)
48-
}
60+
this._subscription && this._subscription.remove()
4961
}
5062

63+
_subscription: ?{remove: () => void} = null
64+
5165
onFilterChanged = (filter: FilterType) => {
52-
const {onChange} = this.props.navigation.state.params
5366
// replace the changed filter in the array, maintaining position
54-
let result = this.props.filters.map(
55-
f => (f.key !== filter.key ? f : filter),
56-
)
57-
onChange(result)
67+
this.setState(state => {
68+
let edited = state.filters.map(f => (f.key !== filter.key ? f : filter))
69+
return {filters: edited}
70+
})
5871
}
5972

6073
render() {
61-
const contents = this.props.filters.map(filter => (
74+
if (!this.state.filters.length) {
75+
return <NoticeView text="No filters available" />
76+
}
77+
78+
const contents = this.state.filters.map(filter => (
6279
<FilterSection
6380
key={filter.key}
6481
filter={filter}
@@ -73,11 +90,3 @@ class FilterViewComponent extends React.PureComponent<Props> {
7390
)
7491
}
7592
}
76-
77-
function mapState(state: ReduxState, actualProps: ReactProps): ReduxStateProps {
78-
return {
79-
filters: get(state, actualProps.navigation.state.params.pathToFilters, []),
80-
}
81-
}
82-
83-
export const ConnectedFilterView = connect(mapState)(FilterViewComponent)

source/views/components/filter/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
export {ConnectedFilterView as FilterView} from './filter-view'
2+
export {FilterView} from './filter-view'
33
export type {FilterType, ListType, ToggleType, PickerType} from './types'
44
export {applyFiltersToItem} from './apply-filters'
55
export {stringifyFilters} from './stringify-filters'

source/views/components/searchable-alphabet-listview.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,10 @@ const styles = StyleSheet.create({
1414
},
1515
})
1616

17-
type Props = any
17+
type Props = any & {query: string}
1818

19-
export class SearchableAlphabetListView extends React.PureComponent<Props> {
20-
searchBar: any = null
21-
22-
_performSearch = (text: string | Object) => {
23-
// Android clear button returns an object
24-
if (typeof text !== 'string') {
25-
return this.props.onSearch(null)
26-
}
27-
28-
return this.props.onSearch(text)
29-
}
19+
export class SearchableAlphabetListView extends React.Component<Props> {
20+
_performSearch = (text: string) => this.props.onSearch(text)
3021

3122
// We need to make the search run slightly behind the UI,
3223
// so I'm slowing it down by 50ms. 0ms also works, but seems
@@ -36,12 +27,7 @@ export class SearchableAlphabetListView extends React.PureComponent<Props> {
3627
render() {
3728
return (
3829
<View style={styles.wrapper}>
39-
<SearchBar
40-
getRef={ref => (this.searchBar = ref)}
41-
onChangeText={this.performSearch}
42-
// if we don't use the arrow function here, searchBar ref is null...
43-
onSearchButtonPress={() => this.searchBar.unFocus()}
44-
/>
30+
<SearchBar onChange={this.performSearch} value={this.props.query} />
4531
<StyledAlphabetListView
4632
headerHeight={
4733
Platform.OS === 'ios'

0 commit comments

Comments
 (0)