Skip to content

Commit

Permalink
Linting and type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
robertherber committed Oct 12, 2023
1 parent a86dc0a commit 174cb3c
Show file tree
Hide file tree
Showing 25 changed files with 115 additions and 89 deletions.
120 changes: 70 additions & 50 deletions apps/cms-ui/app/(auth)/login.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { AuthContext } from '@kingstinct/react'
import { useCallback, useContext, useRef, useState } from 'react'
import {
useCallback, useContext, useRef, useState,
} from 'react'
import { KeyboardAvoidingView, View } from 'react-native'
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
import {
Button, TextInput, Title,
} from 'react-native-paper'
import { SafeAreaView } from 'react-native-safe-area-context'
import { useMutation } from 'urql'

import { graphql } from '../../gql'
import { SafeAreaView } from 'react-native-safe-area-context'
import { Button, Text, TextInput, Title } from 'react-native-paper'
import { KeyboardAvoidingView, View, TextInput as TextInputNative } from 'react-native'

import type { TextInput as TextInputNative } from 'react-native'

type TextInputHandles = Pick<TextInputNative, 'focus' | 'clear' | 'blur' | 'isFocused' | 'setNativeProps'>;

export const LoginConfirmMutation = graphql(`
mutation LoginConfirm($email: String!, $code: String!) {
Expand Down Expand Up @@ -38,12 +46,11 @@ const Login = () => {

const [email, setEmail] = useState('')
const [code, setCode] = useState('')
const [{data: requestData, fetching: fetchingRequest}, loginRequest] = useMutation(LoginRequestMutation)
const [{ data: confirmData, fetching: fetchingConfirm }, loginConfirm] = useMutation(LoginConfirmMutation)
const [{ data: requestData, fetching: fetchingRequest }, loginRequest] = useMutation(LoginRequestMutation)
const [{ fetching: fetchingConfirm }, loginConfirm] = useMutation(LoginConfirmMutation)
const doRequest = useCallback(async () => {
await loginRequest({ email })
txtPasswordRef.current?.focus()

}, [email, loginRequest])
const doConfirm = useCallback(async () => {
const { data } = await loginConfirm({ email, code })
Expand All @@ -55,52 +62,65 @@ const Login = () => {
email, code, loginConfirm, setToken,
])

const txtPasswordRef = useRef<TextInputNative>(null)
const txtPasswordRef = useRef<TextInputHandles>(null)

return (
<SafeAreaView style={{ padding: 16, flex: 1 }}>
<KeyboardAwareScrollView keyboardDismissMode='interactive' keyboardShouldPersistTaps={'handled'} style={{ }} contentContainerStyle={{flex: 1}}>
<KeyboardAvoidingView behavior='padding' style={{flex:1}}>
<Title>Login to CMS Admin</Title>
<TextInput
accessibilityLabel='Email input field'
accessibilityHint='email'
value={email}
label={'Email'}
placeholder='Email'
onChangeText={setEmail}
onSubmitEditing={doRequest}
autoComplete='email'
keyboardType='email-address'
returnKeyType='next'
autoFocus={true}
/>
{ requestData ? <TextInput
ref={txtPasswordRef}
accessibilityLabel='Text input field'
value={code}
accessibilityHint='code'
onChangeText={setCode}
maxLength={6}
label={'One Time Code'}
placeholder='One Time Code'
keyboardType='number-pad'
autoComplete='one-time-code'
importantForAutofill='yes'

onSubmitEditing={doConfirm}
returnKeyType='send'
/> : null }
<View style={{flex:1}}/>
<Button
onPress={doRequest} loading={fetchingRequest} disabled={fetchingConfirm || fetchingRequest} mode={ requestData ? 'text' : 'contained' }>{ requestData ? 'Request code again' : 'Continue' }</Button>
{ requestData ? <Button
onPress={doConfirm}
loading={fetchingConfirm}
disabled={fetchingConfirm || fetchingRequest}
mode='contained'>Continue</Button> : null }
<View style={{ height: 80 }}></View>
</KeyboardAvoidingView>
<KeyboardAwareScrollView keyboardDismissMode='interactive' keyboardShouldPersistTaps='handled' style={{ }} contentContainerStyle={{ flex: 1 }}>
<KeyboardAvoidingView behavior='padding' style={{ flex: 1 }}>
<Title>Login to CMS Admin</Title>
<TextInput
accessibilityLabel='Email input field'
accessibilityHint='email'
value={email}
label='Email'
placeholder='Email'
onChangeText={setEmail}
onSubmitEditing={doRequest}
autoComplete='email'
keyboardType='email-address'
returnKeyType='next'
autoFocus
/>
{ requestData ? (
<TextInput
// @ts-expect-error sadface
ref={txtPasswordRef}
accessibilityLabel='Text input field'
value={code}
accessibilityHint='code'
onChangeText={setCode}
maxLength={6}
label='One Time Code'
placeholder='One Time Code'
keyboardType='number-pad'
autoComplete='one-time-code'
importantForAutofill='yes'
onSubmitEditing={doConfirm}
returnKeyType='send'
/>
) : null }
<View style={{ flex: 1 }} />
<Button
onPress={doRequest}
loading={fetchingRequest}
disabled={fetchingConfirm || fetchingRequest}
mode={requestData ? 'text' : 'contained'}
>
{ requestData ? 'Request code again' : 'Continue' }
</Button>
{ requestData ? (
<Button
onPress={doConfirm}
loading={fetchingConfirm}
disabled={fetchingConfirm || fetchingRequest}
mode='contained'
>
Continue
</Button>
) : null }
<View style={{ height: 80 }} />
</KeyboardAvoidingView>
</KeyboardAwareScrollView>
</SafeAreaView>
)
Expand Down
9 changes: 6 additions & 3 deletions apps/cms-ui/app/(tabs)/(content)/[entity]/schema/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Styles } from '@kingstinct/react'
import { router, useLocalSearchParams } from 'expo-router'
import {
View, Text, ScrollView,
Expand All @@ -7,7 +8,6 @@ import { Button, DataTable } from 'react-native-paper'
import { useQuery } from 'urql'

import { GetEntityByPluralizedNameQuery } from '..'
import { Styles } from '@kingstinct/react'

const EntityDetails = () => {
const { entity } = useLocalSearchParams()
Expand Down Expand Up @@ -42,10 +42,13 @@ const EntityDetails = () => {
</DataTable.Row>
))
}
<Button
<Button
icon='plus'
style={Styles.margin8}
onPress={() => router.push(`/(tabs)/(content)/${entity}/schema/fields/create`)}>Add Field</Button>
onPress={() => router.push(`/(tabs)/(content)/${entity}/schema/fields/create`)}
>
Add Field
</Button>
</DataTable>
<Text>{ JSON.stringify(data?.getEntityByPluralizedName, null, 2) }</Text>
<View style={{ height: 200 }} />
Expand Down
14 changes: 5 additions & 9 deletions apps/cms-ui/app/(tabs)/(content)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,34 @@ import {
} from 'expo-router'
import { useCallback } from 'react'
import { Pressable } from 'react-native'

import { useTheme } from 'react-native-paper'

import { capitalize, singularize } from '../../../utils/text'

import type { HeaderButtonProps } from '@react-navigation/native-stack/src/types'
import { useTheme } from 'react-native-paper'



// eslint-disable-next-line camelcase
export const unstable_settings = {
// Ensure any route can link back to `/`
initialRouteName: 'index',
}

const HeaderRightButton = ({ onPress, tintColor, icon = 'plus' }: HeaderButtonProps & { readonly onPress: () => void, icon?: string }) => {
const HeaderRightButton = ({ onPress, tintColor, icon = 'plus' }: HeaderButtonProps & { readonly onPress: () => void, readonly icon?: keyof typeof MaterialCommunityIcons.glyphMap }) => {
const theme = useTheme()
return (
<Pressable accessibilityRole='button' onPress={onPress}>
<MaterialCommunityIcons
// @ts-ignore
name={icon}
size={24}
style={{ marginRight: 16 }}
color={tintColor ?? theme.colors.onSurface}
/>
</Pressable>
)
}
}

const EntitiesLayout = () => {
const { entity } = useGlobalSearchParams()
const { entity } = useGlobalSearchParams()

const headerRightForListView = useCallback((props: HeaderButtonProps) => (
<HeaderRightButton {...props} icon='cog' onPress={() => router.push(`/(tabs)/(content)/${entity as string}/schema`)} />
Expand Down Expand Up @@ -122,7 +118,7 @@ const EntitiesLayout = () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
options={({ route }) => ({
title: 'Update field ' + route.params?.fieldName,
title: `Update field ${route.params?.fieldName}`,
presentation: 'modal',
})}
/>
Expand Down
4 changes: 3 additions & 1 deletion apps/cms-ui/app/(tabs)/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const ProfileScreen = () => {
</Text>
<Button
onPress={logout}
>Logout</Button>
>
Logout
</Button>
</View>
)
}
Expand Down
14 changes: 7 additions & 7 deletions apps/cms-ui/app/(tabs)/users.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { View, Text } from 'react-native'
import { ScrollView } from 'react-native-gesture-handler'
import { DataTable } from 'react-native-paper'
import { useQuery } from 'urql'

import { graphql } from '../../gql'
import { DataTable } from 'react-native-paper'
import { ScrollView } from 'react-native-gesture-handler'

export const GetUsersQuery = graphql(`
query GetUsers {
Expand All @@ -26,11 +26,11 @@ const UserList = () => {
<DataTable.Title>Email</DataTable.Title>
</DataTable.Header>
{
data?.users.map((entity) =>
<DataTable.Row key={entity.email}>
<DataTable.Cell><Text key={entity.email}>{entity.email}</Text></DataTable.Cell>
</DataTable.Row>
)
data?.users.map((entity) => (
<DataTable.Row key={entity.email}>
<DataTable.Cell><Text key={entity.email}>{entity.email}</Text></DataTable.Cell>
</DataTable.Row>
))
}
</DataTable>
</ScrollView>
Expand Down
2 changes: 1 addition & 1 deletion apps/cms-ui/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Stack, router, useSegments } from 'expo-router'
import { useContext, useEffect, useMemo } from 'react'
import { useColorScheme } from 'react-native'
import {
PaperProvider, MD3DarkTheme, MD2LightTheme, MD2DarkTheme, MD3LightTheme,
PaperProvider, MD3DarkTheme, MD3LightTheme,
} from 'react-native-paper'
import { SafeAreaProvider } from 'react-native-safe-area-context'

Expand Down
2 changes: 1 addition & 1 deletion apps/cms-ui/clients/urql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
createClient, errorExchange, fetchExchange, subscriptionExchange,
} from '@urql/core'
import { createClient as createWSClient } from 'graphql-ws'
import { Platform } from 'react-native'

import type { CombinedErrorWithExtensions, CreateUrqlClient } from '@kingstinct/react/contexts/Urql'
import { Platform } from 'react-native'

const BACKEND_ROOT_URL = Platform.OS === 'web' ? 'http://localhost:3000' : 'http://robmax.local:3000'

Expand Down
1 change: 1 addition & 0 deletions apps/cms-ui/components/ListOfEntries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const formatFieldValue = (value: unknown) => {
return `${value.length.toString()} items`
}

// eslint-disable-next-line @typescript-eslint/no-base-to-string
return value.toString()
}

Expand Down
1 change: 1 addition & 0 deletions apps/cms-ui/components/TextControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Props<T extends FieldValues> = { readonly control: Control<T>, readonly nam
export function TextControl<T extends FieldValues>({
control, name, rules, ...textInputProps
}: Props<T>) {
// eslint-disable-next-line @typescript-eslint/no-base-to-string
const labelOrPlaceholder = (textInputProps.label ? textInputProps.label.toString() : textInputProps.placeholder) ?? ''
const render = useCallback(
({
Expand Down
6 changes: 3 additions & 3 deletions apps/cms-ui/components/UpsertEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const ArrayFieldComponent: React.FC<ArrayFieldComponentProps> = ({ field, items,
label={label}
keyboardType='numeric'
onSubmitEditing={onSubmit}
// todo [>=1]: should probably introduce an id here
// todo [>1]: should probably introduce an id here
// eslint-disable-next-line react/no-array-index-key
key={name}
/>
Expand All @@ -153,7 +153,7 @@ const ArrayFieldComponent: React.FC<ArrayFieldComponentProps> = ({ field, items,
name={name}
label={label}
switchProps={{ onValueChange: async () => onSubmit() }}
// todo [>=1]: should probably introduce an id here
// todo [>1]: should probably introduce an id here
// eslint-disable-next-line react/no-array-index-key
key={name}
/>
Expand All @@ -165,7 +165,7 @@ const ArrayFieldComponent: React.FC<ArrayFieldComponentProps> = ({ field, items,
name={name}
label={label}
onSubmitEditing={onSubmit}
// todo [>=1]: should probably introduce an id here
// todo [>1]: should probably introduce an id here
// eslint-disable-next-line react/no-array-index-key
key={name}
/>
Expand Down
2 changes: 1 addition & 1 deletion apps/cms-ui/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ config.resolver.sourceExts = [...config.resolver.sourceExts, 'mjs', 'cjs']
config.resolver.resolverMainFields = ['sbmodern', ...config.resolver.resolverMainFields]
config.resolver.assetExts = [...config.resolver.assetExts, 'ttf', 'otf']
config.resolver.unstable_enableSymlinks = true
config.resolver.disableHierarchicalLookup = true;
config.resolver.disableHierarchicalLookup = true

// eslint-disable-next-line no-underscore-dangle
// if (process.env.NODE_ENV === 'development') {
Expand Down
1 change: 1 addition & 0 deletions apps/cms-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@kingstinct/react": "^1.0.7",
"@react-native-async-storage/async-storage": "^1.19.3",
"@react-native-community/netinfo": "^9.4.1",
"@react-navigation/native": "^6.1.8",
"@types/react": "~18.2.14",
"@urql/core": "^4.1.2",
"expo": "^49.0.11",
Expand Down
2 changes: 1 addition & 1 deletion apps/todo-app-with-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@types/react": "~18.0.14",
"@types/react": "~18.2.14",
"typescript": "^5.1.3"
},
"private": true
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/anonymous-auth-expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@babel/core": "^7.20.0",
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/client-preset": "^4.1.0",
"@types/react": "~18.0.14",
"@types/react": "~18.2.14",
"typescript": "^5.1.3"
},
"private": true
Expand Down
6 changes: 5 additions & 1 deletion packages/auth-expo/contexts/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import {
import { TOKEN_KEY } from '../config'
import getToken from '../utils/getToken'

import type { PropsWithChildren } from 'react'

export const AuthContext = createContext({
token: null as string | null,
logout: () => {},
})

export const ReadToken = async (): Promise<string | null> => AsyncStorage.getItem(TOKEN_KEY)

export const AuthProvider: React.FC<React.PropsWithChildren<{ readonly token: string | null, readonly setToken: (token: string | null) => void }>> = ({ children, token, setToken }) => {
type Props = { readonly token: string | null, readonly setToken: (token: string | null) => void }

export const AuthProvider: React.FC<PropsWithChildren<Props>> = ({ children, token, setToken }) => {
useEffect(() => {
void getToken().then(setToken)
}, [setToken])
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@types/react": "~18.0.14",
"@types/react": "~18.2.14",
"typescript": "^5.1.3"
},
"private": true
Expand Down
Loading

0 comments on commit 174cb3c

Please sign in to comment.