This commit is contained in:
Maarten 2024-08-08 14:22:35 +02:00
parent cec664c8d0
commit ff2320f08c
13 changed files with 297 additions and 297 deletions

View file

@ -1,6 +1,6 @@
import React from 'react';
import {ViewStyle} from 'react-native';
import {ThemedView} from '@/components/ThemedView';
import { ViewStyle } from 'react-native';
import { ThemedView } from '@/components/ThemedView';
interface ListProps {
data: any;
@ -13,9 +13,9 @@ const CustomList: React.FC<ListProps> = ({ data, renderItem, viewStyle }) => {
let list: any[] = [];
for (let i = 0; i < data.length; i++) {
const item = data[i];
const item = data[ i ];
list[i] = renderItem(item, i);
list[ i ] = renderItem( item, i );
}
return list;

View file

@ -15,7 +15,7 @@ export function ThemedText({
type = 'default',
...rest
}: ThemedTextProps) {
const color = useThemeColor({ light: lightColor, dark: darkColor }, 'text');
const color = useThemeColor( { light: lightColor, dark: darkColor }, 'text' );
return (
<Text
@ -33,7 +33,7 @@ export function ThemedText({
);
}
const styles = StyleSheet.create({
const styles = StyleSheet.create( {
default: {
fontSize: 16,
lineHeight: 24,
@ -57,4 +57,4 @@ const styles = StyleSheet.create({
fontSize: 16,
color: '#0a7ea4',
},
});
} );

View file

@ -8,7 +8,7 @@ export type ThemedViewProps = ViewProps & {
};
export function ThemedView({ style, lightColor, darkColor, ...otherProps }: ThemedViewProps) {
const backgroundColor = useThemeColor({ light: lightColor, dark: darkColor }, 'background');
const backgroundColor = useThemeColor( { light: lightColor, dark: darkColor }, 'background' );
return <View style={[{ backgroundColor }, style]} {...otherProps} />;
return <View style={[ { backgroundColor }, style ]} {...otherProps} />;
}

View file

@ -3,8 +3,8 @@ import renderer from 'react-test-renderer';
import { ThemedText } from '../ThemedText';
it(`renders correctly`, () => {
const tree = renderer.create(<ThemedText>Snapshot test!</ThemedText>).toJSON();
it( `renders correctly`, () => {
const tree = renderer.create( <ThemedText>Snapshot test!</ThemedText> ).toJSON();
expect(tree).toMatchSnapshot();
});
expect( tree ).toMatchSnapshot();
} );

View file

@ -5,5 +5,5 @@ import { type IconProps } from '@expo/vector-icons/build/createIconSet';
import { type ComponentProps } from 'react';
export function TabBarIcon({ style, ...rest }: IconProps<ComponentProps<typeof Ionicons>['name']>) {
return <Ionicons size={28} style={[style]} {...rest} />;
return <Ionicons size={28} style={[ style ]} {...rest} />;
}

View file

@ -1,5 +1,5 @@
import {createContext, PropsWithChildren, useContext} from "react";
import {useStorageState} from '@/context/UseStorageState';
import { createContext, PropsWithChildren, useContext } from "react";
import { useStorageState } from '@/context/UseStorageState';
type TokenType = {
token: string | null;
@ -7,22 +7,22 @@ type TokenType = {
isLoading: boolean;
}
const TokenContext = createContext<TokenType>({
const TokenContext = createContext<TokenType>( {
setToken: () => {
},
token: null,
isLoading: true,
});
} );
export const useToken = () => useContext(TokenContext);
export const useToken = () => useContext( TokenContext );
export function AppProvider({ children }: PropsWithChildren) {
const [[isLoading, token], setSession] = useStorageState('appToken');
const [ [ isLoading, token ], setSession ] = useStorageState( 'appToken' );
const tokenContext: TokenType = {
token,
setToken: (token) => {
setSession(token);
setSession( token );
},
isLoading,
};

View file

@ -2,13 +2,13 @@ import * as SecureStore from 'expo-secure-store';
import * as React from 'react';
import { Platform } from 'react-native';
type UseStateHook<T> = [[boolean, T | null], (value: T | null) => void];
type UseStateHook<T> = [ [ boolean, T | null ], (value: T | null) => void ];
function useAsyncState<T>(
initialValue: [boolean, T | null] = [true, null],
initialValue: [ boolean, T | null ] = [ true, null ],
): UseStateHook<T> {
return React.useReducer(
(state: [boolean, T | null], action: T | null = null): [boolean, T | null] => [false, action],
(state: [ boolean, T | null ], action: T | null = null): [ boolean, T | null ] => [ false, action ],
initialValue
) as UseStateHook<T>;
}
@ -17,51 +17,51 @@ export async function setStorageItemAsync(key: string, value: string | null) {
if (Platform.OS === 'web') {
try {
if (value === null) {
localStorage.removeItem(key);
localStorage.removeItem( key );
} else {
localStorage.setItem(key, value);
localStorage.setItem( key, value );
}
} catch (e) {
console.error('Local storage is unavailable:', e);
console.error( 'Local storage is unavailable:', e );
}
} else {
if (value == null) {
await SecureStore.deleteItemAsync(key);
await SecureStore.deleteItemAsync( key );
} else {
await SecureStore.setItemAsync(key, value);
await SecureStore.setItemAsync( key, value );
}
}
}
export function useStorageState(key: string): UseStateHook<string> {
// Public
const [state, setState] = useAsyncState<string>();
const [ state, setState ] = useAsyncState<string>();
// Get
React.useEffect(() => {
React.useEffect( () => {
if (Platform.OS === 'web') {
try {
if (typeof localStorage !== 'undefined') {
setState(localStorage.getItem(key));
setState( localStorage.getItem( key ) );
}
} catch (e) {
console.error('Local storage is unavailable:', e);
console.error( 'Local storage is unavailable:', e );
}
} else {
SecureStore.getItemAsync(key).then((value: string | null) => {
setState(value);
});
SecureStore.getItemAsync( key ).then( (value: string | null) => {
setState( value );
} );
}
}, [key]);
}, [ key ] );
// Set
const setValue = React.useCallback(
(value: string | null) => {
setState(value);
setStorageItemAsync(key, value);
setState( value );
setStorageItemAsync( key, value );
},
[key]
[ key ]
);
return [state, setValue];
return [ state, setValue ];
}

View file

@ -12,11 +12,11 @@ export function useThemeColor(
colorName: keyof typeof Colors.light & keyof typeof Colors.dark
) {
const theme = useColorScheme() ?? 'light';
const colorFromProps = props[theme];
const colorFromProps = props[ theme ];
if (colorFromProps) {
return colorFromProps;
} else {
return Colors[theme][colorName];
return Colors[ theme ][ colorName ];
}
}

View file

@ -7,7 +7,7 @@ export class Message {
* @param message
*/
static success(message: string) {
Message.send('success', message);
Message.send( 'success', message );
}
/**
@ -16,7 +16,7 @@ export class Message {
* @param message
*/
static error(message: string) {
Message.send('error', message);
Message.send( 'error', message );
}
/**
@ -25,7 +25,7 @@ export class Message {
* @param message
*/
static info(message: string) {
Message.send('info', message);
Message.send( 'info', message );
}
/**
@ -35,13 +35,13 @@ export class Message {
* @param message
*/
static send(type: string, message: string) {
Toast.show({
Toast.show( {
type: type,
text1: message,
position: 'bottom',
visibilityTime: 2000,
autoHide: true,
})
} )
}
}

View file

@ -15,15 +15,15 @@ export class Request {
*/
static get(url: string, headers = {}) {
return axios
.get(API_URL + url, {
.get( API_URL + url, {
...CONFIG,
...headers,
})
.then(response => response.data)
.catch(error => {
} )
.then( response => response.data )
.catch( error => {
// Handle error
throw error;
});
} );
}
/**
@ -36,15 +36,15 @@ export class Request {
*/
static post(url: string, body = {}, headers = {}) {
return axios
.post(API_URL + url, body, {
.post( API_URL + url, body, {
...CONFIG,
...headers,
})
.then(response => response.data)
.catch(error => {
} )
.then( response => response.data )
.catch( error => {
// Handle error
throw error;
});
} );
}
/**
@ -57,15 +57,15 @@ export class Request {
*/
static put(url: string, body = {}, headers = {}) {
return axios
.put(API_URL + url, body, {
.put( API_URL + url, body, {
...CONFIG,
...headers,
})
.then(response => response.data)
.catch(error => {
} )
.then( response => response.data )
.catch( error => {
// Handle error
throw error;
});
} );
}
}

View file

@ -1,8 +1,8 @@
import { configureStore } from '@reduxjs/toolkit';
import dataReducer from './dataStore';
export const store = configureStore({
export const store = configureStore( {
reducer: {
data: dataReducer,
},
});
} );