Skip to content

Commit b133b55

Browse files
authored
Merge pull request #2790 from StoDevX/search-results-push-view
Push course search results onto the stack
2 parents bc60552 + d802051 commit b133b55

File tree

9 files changed

+326
-128
lines changed

9 files changed

+326
-128
lines changed

source/navigation.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ import {
2424
CarletonSaylesMenuScreen,
2525
} from './views/menus'
2626
import NewsView from './views/news'
27-
import SISView from './views/sis'
28-
import {JobDetailView} from './views/sis/student-work/detail'
29-
import {CourseDetailView} from './views/sis/course-search/detail'
27+
import SISView, {
28+
JobDetailView,
29+
CourseDetailView,
30+
CourseSearchResultsView,
31+
} from './views/sis'
3032
import {
3133
BuildingHoursView,
3234
BuildingHoursDetailView,
@@ -84,6 +86,7 @@ export const AppNavigator = createStackNavigator(
8486
SettingsView: {screen: SettingsView},
8587
IconSettingsView: {screen: IconSettingsView},
8688
SISView: {screen: SISView},
89+
CourseSearchResultsView: {screen: CourseSearchResultsView},
8790
CourseDetailView: {screen: CourseDetailView},
8891
StreamingView: {screen: StreamingView},
8992
KSTOScheduleView: {screen: KSTOScheduleView},

source/views/components/searchbar/index.android.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const styles = StyleSheet.create({
2727
export class SearchBar extends React.Component<Props> {
2828
static defaultProps = {
2929
active: false,
30+
backButtonAndroid: true,
31+
androidIcon: null,
3032
onCancel: () => {},
3133
onChange: () => {},
3234
onFocus: () => {},
@@ -40,16 +42,18 @@ export class SearchBar extends React.Component<Props> {
4042
}
4143

4244
render() {
45+
let {backButtonAndroid} = this.props
4346
let backButton = this.props.active ? backIcon : searchIcon
4447

4548
return (
4649
<NativeSearchBar
4750
ref={this.handleRef}
4851
autoCorrect={false}
49-
backButton={backButton}
52+
backButton={backButtonAndroid === 'search' ? searchIcon : backButton}
5053
closeButton={this.props.active ? closeIcon : null}
5154
focusOnLayout={false}
5255
handleChangeText={this.props.onChange}
56+
hideBack={!backButtonAndroid}
5357
hideClose={!this.props.active}
5458
input={this.props.value}
5559
onBack={this.props.onCancel}

source/views/components/searchbar/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export type Props = {
44
getRef?: any,
55
active?: boolean,
6+
backButtonAndroid?: 'search' | boolean,
67
backgroundColor?: string,
78
onCancel: () => any,
89
onChange: string => any,

source/views/sis/components/animated-searchbox.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,36 @@ export class AnimatedSearchbox extends React.Component<Props> {
8080
render={viewport => {
8181
let searchBarWidth = viewport.width - 20
8282

83+
let showTitle = Boolean(this.props.title)
84+
8385
let containerStyle = [
8486
styles.searchContainer,
8587
styles.common,
86-
{height: this.containerHeight},
88+
{
89+
height: showTitle
90+
? this.containerHeight
91+
: this.containerHeightSpec.end,
92+
},
8793
]
8894

8995
let searchStyle = [
9096
styles.searchBarWrapper,
9197
{width: searchBarWidth},
92-
{top: this.searchBarTop},
98+
{top: showTitle ? this.searchBarTop : this.searchBarTopSpec.end},
9399
]
94100

95-
let headerStyle = [styles.header, {opacity: this.headerOpacity}]
101+
let headerStyle = [
102+
styles.header,
103+
{
104+
opacity: showTitle
105+
? this.headerOpacity
106+
: this.headerOpacitySpec.end,
107+
},
108+
]
96109

97110
return (
98111
<Animated.View style={containerStyle}>
99-
{this.props.title ? (
112+
{showTitle ? (
100113
<Animated.Text style={headerStyle}>
101114
{this.props.title}
102115
</Animated.Text>
@@ -105,6 +118,7 @@ export class AnimatedSearchbox extends React.Component<Props> {
105118
<Animated.View style={searchStyle}>
106119
<SearchBar
107120
active={this.props.active}
121+
backButtonAndroid="search"
108122
onCancel={this.handleCancel}
109123
onChange={this.props.onChange}
110124
onFocus={this.handleFocus}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
// @flow
22

3-
export {default} from './search'
3+
export {default as CourseSearchView} from './search'
4+
export {default as CourseSearchResultsView} from './results'
5+
export {CourseDetailView} from './detail'

source/views/sis/course-search/list.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

33
import * as React from 'react'
4-
import {StyleSheet, SectionList} from 'react-native'
4+
import {StyleSheet, SectionList, ActivityIndicator} from 'react-native'
55
import type {TopLevelViewPropsType} from '../../types'
66
import type {CourseType} from '../../../lib/course-search/types'
77
import {ListSeparator, ListSectionHeader} from '../../components/list'
@@ -21,15 +21,23 @@ const styles = StyleSheet.create({
2121
message: {
2222
paddingVertical: 16,
2323
},
24+
spinner: {
25+
alignItems: 'center',
26+
justifyContent: 'center',
27+
padding: 8,
28+
},
2429
})
2530

2631
type Props = TopLevelViewPropsType & {
2732
applyFilters: (filters: FilterType[], item: CourseType) => boolean,
28-
browsing: boolean,
2933
courses: Array<CourseType>,
3034
filters: Array<FilterType>,
3135
onPopoverDismiss: (filter: FilterType) => any,
36+
onListItemPress?: CourseType => any,
3237
query: string,
38+
style?: any,
39+
contentContainerStyle?: any,
40+
filtersLoaded: boolean,
3341
}
3442

3543
function doSearch(args: {
@@ -63,29 +71,38 @@ export class CourseResultsList extends React.PureComponent<Props> {
6371
)
6472

6573
onPressRow = (data: CourseType) => {
74+
if (this.props.onListItemPress) {
75+
this.props.onListItemPress(data)
76+
}
6677
this.props.navigation.navigate('CourseDetailView', {course: data})
6778
}
6879

6980
render() {
7081
let {
7182
filters,
72-
browsing,
7383
query,
7484
courses,
7585
applyFilters,
7686
onPopoverDismiss,
87+
contentContainerStyle,
88+
style,
89+
filtersLoaded,
7790
} = this.props
7891

7992
// be sure to lowercase the query before calling doSearch, so that the memoization
8093
// doesn't break when nothing's changed except case.
8194
query = query.toLowerCase()
8295
let results = memoizedDoSearch({query, filters, courses, applyFilters})
8396

84-
const header = (
97+
const header = filtersLoaded ? (
8598
<FilterToolbar filters={filters} onPopoverDismiss={onPopoverDismiss} />
99+
) : (
100+
<ActivityIndicator style={styles.spinner} />
86101
)
87102

88-
const message = browsing
103+
const hasActiveFilter = filters.some(f => f.enabled)
104+
105+
const message = hasActiveFilter
89106
? 'There were no courses that matched your selected filters. Try a different filter combination.'
90107
: query.length
91108
? 'There were no courses that matched your query. Please try again.'
@@ -98,14 +115,14 @@ export class CourseResultsList extends React.PureComponent<Props> {
98115
ItemSeparatorComponent={ListSeparator}
99116
ListEmptyComponent={messageView}
100117
ListHeaderComponent={header}
101-
contentContainerStyle={styles.container}
118+
contentContainerStyle={[styles.container, contentContainerStyle]}
102119
extraData={this.props}
103120
keyExtractor={this.keyExtractor}
104-
keyboardDismissMode="on-drag"
105-
keyboardShouldPersistTaps="never"
121+
keyboardDismissMode="interactive"
106122
renderItem={this.renderItem}
107123
renderSectionHeader={this.renderSectionHeader}
108124
sections={(results: any)}
125+
style={style}
109126
windowSize={10}
110127
/>
111128
)

0 commit comments

Comments
 (0)