-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added zodios with examples + use-custom-fonts hook
- Loading branch information
Showing
9 changed files
with
239 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ZodiosPlugin } from '@zodios/core'; | ||
import { AxiosError } from 'axios'; | ||
|
||
const SKIP_ERROR_HANDLING_URLS = ['/example/skip-error-handling']; | ||
|
||
const errorErrorPlugin: ZodiosPlugin = { | ||
name: 'errorErrorPlugin', | ||
error: async (api, config, err) => { | ||
if (SKIP_ERROR_HANDLING_URLS.includes(config.url)) { | ||
console.log('Skipping error handling for', config.url); | ||
throw err; | ||
} | ||
|
||
if (err instanceof AxiosError) { | ||
console.error('AxiosError', err); | ||
} | ||
|
||
throw err; | ||
}, | ||
}; | ||
|
||
export default errorErrorPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Zodios } from '@zodios/core'; | ||
import { ZodiosHooks } from '@zodios/react'; | ||
import apiErrorPlugin from './api-error-plugin'; | ||
import exampleApi from './example'; | ||
|
||
const API_URL = process.env.EXPO_PUBLIC_API_URL || ''; | ||
|
||
// Zodios API client | ||
const apiClient = new Zodios(API_URL, [...exampleApi]); | ||
|
||
apiClient.use(apiErrorPlugin); | ||
const api = new ZodiosHooks('exampleApi', apiClient); | ||
|
||
export { api, apiClient }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { apiBuilder } from '@zodios/core'; | ||
import { z } from 'zod'; | ||
|
||
// Endpoints for Example API - Example Endpoints. | ||
const exampleApi = apiBuilder({ | ||
method: 'get', | ||
path: '/example', | ||
alias: 'getExample', | ||
description: 'Get example', | ||
response: z.object({ | ||
text: z.string(), | ||
}), | ||
parameters: [ | ||
{ | ||
type: 'Query', | ||
name: 'name', | ||
description: 'User name', | ||
schema: z.string().optional(), | ||
}, | ||
], | ||
errors: [{ status: 'default', schema: z.object({ message: z.string() }) }], | ||
}) | ||
.addEndpoint({ | ||
method: 'post', | ||
path: '/example/:exampleId', | ||
description: 'Add example', | ||
alias: 'addExample', | ||
response: z.object({}), | ||
parameters: [ | ||
{ | ||
name: 'exampleId', | ||
type: 'Path', | ||
schema: z.string(), | ||
}, | ||
{ | ||
name: 'body', | ||
type: 'Body', | ||
schema: z.object({ | ||
name: z.string(), | ||
}), | ||
}, | ||
], | ||
errors: [{ status: 'default', schema: z.object({ message: z.string() }) }], | ||
}) | ||
.build(); | ||
|
||
export default exampleApi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { FontSource, loadAsync } from 'expo-font'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
const fontsToLoad = { | ||
thin: require('@assets/fonts/Inter-Thin.ttf'), | ||
light: require('@assets/fonts/Inter-Light.ttf'), | ||
regular: require('@assets/fonts/Inter-Regular.ttf'), | ||
medium: require('@assets/fonts/Inter-Medium.ttf'), | ||
bold: require('@assets/fonts/Inter-Bold.ttf'), | ||
black: require('@assets/fonts/Inter-Black.ttf'), | ||
semibold: require('@assets/fonts/Inter-SemiBold.ttf'), | ||
extrabold: require('@assets/fonts/Inter-ExtraBold.ttf'), | ||
extralight: require('@assets/fonts/Inter-ExtraLight.ttf'), | ||
} as Record<string, FontSource>; | ||
|
||
export default function useSfFonts({ | ||
callback, | ||
}: { | ||
callback?: () => void; | ||
}): [boolean, Error | undefined] { | ||
const [loaded, setLoaded] = useState(false); | ||
const [error, setError] = useState<Error | undefined>(); | ||
|
||
useEffect(() => { | ||
loadAsync(fontsToLoad) | ||
.then(() => { | ||
// Change the state. | ||
setLoaded(true); | ||
|
||
// Call the parent's callback. | ||
callback?.(); | ||
}) | ||
.catch((e) => { | ||
setError(e); | ||
console.error('Fonts not loaded.', e); | ||
}); | ||
}, [callback]); | ||
|
||
return [loaded, error]; | ||
} |
Oops, something went wrong.