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

View file

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

View file

@ -8,7 +8,7 @@ export type ThemedViewProps = ViewProps & {
}; };
export function ThemedView({ style, lightColor, darkColor, ...otherProps }: ThemedViewProps) { 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'; import { ThemedText } from '../ThemedText';
it(`renders correctly`, () => { it( `renders correctly`, () => {
const tree = renderer.create(<ThemedText>Snapshot test!</ThemedText>).toJSON(); 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'; import { type ComponentProps } from 'react';
export function TabBarIcon({ style, ...rest }: IconProps<ComponentProps<typeof Ionicons>['name']>) { 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 { createContext, PropsWithChildren, useContext } from "react";
import {useStorageState} from '@/context/UseStorageState'; import { useStorageState } from '@/context/UseStorageState';
type TokenType = { type TokenType = {
token: string | null; token: string | null;
@ -7,22 +7,22 @@ type TokenType = {
isLoading: boolean; isLoading: boolean;
} }
const TokenContext = createContext<TokenType>({ const TokenContext = createContext<TokenType>( {
setToken: () => { setToken: () => {
}, },
token: null, token: null,
isLoading: true, isLoading: true,
}); } );
export const useToken = () => useContext(TokenContext); export const useToken = () => useContext( TokenContext );
export function AppProvider({ children }: PropsWithChildren) { export function AppProvider({ children }: PropsWithChildren) {
const [[isLoading, token], setSession] = useStorageState('appToken'); const [ [ isLoading, token ], setSession ] = useStorageState( 'appToken' );
const tokenContext: TokenType = { const tokenContext: TokenType = {
token, token,
setToken: (token) => { setToken: (token) => {
setSession(token); setSession( token );
}, },
isLoading, isLoading,
}; };

View file

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

View file

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

View file

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

View file

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