Skip to content

Commit

Permalink
Merge pull request #7113 from StoDevX/drew/api-tester-refactor
Browse files Browse the repository at this point in the history
refactor api tester for better separation of concerns
  • Loading branch information
drewvolz authored May 20, 2024
2 parents a690685 + e198276 commit 5d8315b
Show file tree
Hide file tree
Showing 13 changed files with 319 additions and 273 deletions.
1 change: 1 addition & 0 deletions modules/navigation-buttons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export {OpenSettingsButton} from './open-settings'
export {FavoriteButton} from './favorite'
export {DebugNoticeButton} from './debug'
export {SearchButton} from './search'
export {NetworkLoggerButton} from './network-logger'
37 changes: 37 additions & 0 deletions modules/navigation-buttons/network-logger.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as React from 'react'
import {Platform, StyleSheet, Text} from 'react-native'
import {Touchable} from '@frogpond/touchable'
import {useNavigation, useTheme} from '@react-navigation/native'
import {commonStyles, rightButtonStyles as styles} from './styles'

export const buttonStyles = StyleSheet.create({
text: {
...Platform.select({
ios: {
fontWeight: '600',
},
android: {
fontWeight: '400',
},
}),
},
})

export const NetworkLoggerButton: React.FC = () => {
const navigation = useNavigation()
let {colors} = useTheme()

return (
<Touchable
highlight={false}
onPress={() => navigation.navigate('NetworkLogger')}
style={styles.button}
>
<Text
style={[commonStyles.text, buttonStyles.text, {color: colors.primary}]}
>
Log
</Text>
</Touchable>
)
}
10 changes: 10 additions & 0 deletions modules/use-debounce/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {debounce} from 'lodash'
import {useState, useEffect} from 'react'

export function useDebounce<T>(value: T, delay: number): T {
Expand All @@ -15,3 +16,12 @@ export function useDebounce<T>(value: T, delay: number): T {

return debouncedValue
}

export const debounceSearch = debounce(
(query: string, callback: () => void) => {
if (query.length >= 2) {
callback()
}
},
1500,
)
3 changes: 3 additions & 0 deletions modules/use-debounce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"scripts": {
"test": "jest"
},
"dependencies": {
"lodash": "4.17.21"
},
"peerDependencies": {
"react": "^18.0.0"
}
Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions source/navigation/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ const SettingsStackScreens = () => {
name="APITest"
options={settings.APITestNavigationOptions}
/>
<SettingsStack.Screen
component={settings.APITestDetailView}
name="APITestDetail"
options={settings.APITestDetailNavigationOptions}
/>
<SettingsStack.Screen
component={DevBonAppPickerView}
name="BonAppPicker"
Expand Down
2 changes: 2 additions & 0 deletions source/navigation/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {Printer, PrintJob} from '../lib/stoprint/types'
import {JobType} from '../views/sis/student-work/types'
import {CourseType} from '../lib/course-search/types'
import {DirectoryItem, DirectorySearchTypeEnum} from '../views/directory/types'
import {ServerRoute} from '../views/settings/screens/api-test/query'

export type RootViewsParamList = {
Home: undefined
Expand Down Expand Up @@ -94,6 +95,7 @@ export type RootStackParamList = RootViewsParamList &

export type SettingsStackParamList = {
APITest: undefined
APITestDetail: {query: ServerRoute}
BonAppPicker: undefined
Credits: undefined
[debug.NavigationKey]: {keyPath: string[]}
Expand Down
7 changes: 6 additions & 1 deletion source/views/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export {

// Developer settings
export {DebugRootView} from './screens/debug'
export {APITestView, APITestNavigationOptions} from './screens/api-test'
export {
APITestView,
APITestNavigationOptions,
APITestDetailView,
APITestDetailNavigationOptions,
} from './screens/api-test'
export {
NetworkLoggerView,
NavigationOptions as NetworkLoggerNavigationOptions,
Expand Down
190 changes: 0 additions & 190 deletions source/views/settings/screens/api-test/api-test.tsx

This file was deleted.

Loading

0 comments on commit 5d8315b

Please sign in to comment.