Skip to content

Commit 4dd7979

Browse files
Merge remote-tracking branch 'origin/main' into feat/upgrade-expo-to-51
2 parents 95fa513 + b9408eb commit 4dd7979

44 files changed

Lines changed: 1942 additions & 446 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
// This is added to support web for reaniamted: https://github.com/software-mansion/react-native-reanimated/issues/4140#issuecomment-1455209588
55
import 'setimmediate'
66
import 'react-native-reanimated'
7+
// This is added to work jwt-decode for react-native: https://github.com/auth0/jwt-decode?tab=readme-ov-file#polyfilling-atob
8+
import 'core-js/stable/atob'
79

810
// Rest imports
911
import '@baca/i18n'
1012
import { enableAndroidBackgroundNotificationListener, startMockedServer } from '@baca/services'
1113
import * as Device from 'expo-device'
1214
import 'expo-router/entry'
1315

14-
// FIXME: moking not working on mobile app - follow this discussion https://github.com/mswjs/msw/issues/2026
1516
const ENABLE_MOCKED_SERVER = false
1617

1718
if (ENABLE_MOCKED_SERVER) {

App.web.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import '@baca/i18n'
1010
import { startMockedServer } from '@baca/services'
1111
import 'expo-router/entry'
1212

13-
// FIXME: moking not working on mobile app - follow this discussion https://github.com/mswjs/msw/issues/2026
1413
const ENABLE_MOCKED_SERVER = false
1514

1615
if (ENABLE_MOCKED_SERVER) {
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
id: jotai
3+
slug: /jotai
4+
title: State management - jotai
5+
sidebar_position: 4
6+
tags:
7+
- Jotai
8+
- State management
9+
- React
10+
- React Native
11+
description: State management - jotai -
12+
---
13+
14+
# State management - Jotai
15+
16+
## Description
17+
18+
This starter comes with jotai state management tool. Please check documentation on how it work in details:
19+
20+
- https://jotai.org/docs/introduction
21+
22+
## Examples
23+
24+
### Create atom
25+
26+
```tsx
27+
import { atom } from 'jotai'
28+
29+
export const isSignedInAtom = atom<boolean | null>(null)
30+
31+
export const userAtom = atom<User | null>(null)
32+
export const userNameAtom = atom<string | null>((get) => {
33+
const user = get(userAtom)
34+
const userName = user.userName
35+
36+
return userName
37+
})
38+
```
39+
40+
### Get atom value
41+
42+
Get with hook
43+
44+
```tsx
45+
import { useAtomValue } from 'jotai'
46+
import { isSignedInAtom, userNameAtom } from '@baca/store/auth'
47+
48+
export const UserName = () => {
49+
// success-line
50+
const isSignedIn = useAtomValue(isSignedInAtom)
51+
// success-line
52+
const userName = useAtomValue(userNameAtom)
53+
54+
if (isSignedIn) {
55+
return <Text>{userName}</Text>
56+
}
57+
58+
return <Text>No user</Text>
59+
}
60+
```
61+
62+
Get outside of component
63+
64+
```tsx
65+
import { store } from '@baca/store'
66+
import { isSignedInAtom, userNameAtom } from '@baca/store/auth'
67+
68+
const getUserName = () => {
69+
// success-line
70+
const isSignedIn = store.get(isSignedInAtom)
71+
// success-line
72+
const userName = store.get(userNameAtom)
73+
74+
if (isSignedIn) {
75+
return userName
76+
}
77+
78+
return null
79+
}
80+
```
81+
82+
### Update atom value
83+
84+
Update with hook
85+
86+
```tsx
87+
import { isSignedInAtom } from '@baca/store/auth'
88+
89+
const SignInButton = () => {
90+
// Optionbally you can use `useSetAtom()`
91+
// success-line
92+
const [isSignedIn, setIsSignedIn] = useAtom(isSignedInAtom)
93+
94+
const handleSignIn = () => {
95+
// Handle logic on backend
96+
97+
// success-line
98+
setIsSignedIn(true)
99+
}
100+
101+
if (isSignedIn) {
102+
return null
103+
}
104+
105+
return <Button onPress={handleSignIn}>Sign in</Button>
106+
}
107+
```
108+
109+
Update outside of component
110+
111+
```tsx
112+
import { store } from '@baca/store'
113+
import { isSignedInAtom } from '@baca/store/auth'
114+
115+
const handleSignIn = () => {
116+
// Handle logic on backend
117+
118+
// success-line
119+
store.set(isSignedInAtom, true)
120+
}
121+
122+
const SignInButton = () => {
123+
const isSignedIn = useAtomValue(isSignedInAtom)
124+
125+
if (isSignedIn) {
126+
return null
127+
}
128+
129+
return <Button onPress={handleSignIn}>Sign in</Button>
130+
}
131+
```

docs/docs/tutorials/BACKEND-CONNECTION.md renamed to docs/docs/data-management/API-CONNECTION.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
---
2-
id: backend-connection
3-
slug: /backend-connection
4-
title: Backend connection
5-
sidebar_position: 4
2+
id: api-connection
3+
slug: /api-connection
4+
title: API connection
5+
sidebar_position: 1
66
tags:
77
- Backend
8+
- API
89
- react-query
910
- axios
1011
- react native
1112
- orval
12-
description: Backend connection - check how to fetch data from backend and display it for users
13+
description: API connection - check how to fetch data from backend and display it for users
1314
---
1415

15-
# Backend connection
16+
# API connection
1617

17-
This template uses this packages to keep connection with backend:
18+
This template uses this packages to keep connection with API:
1819

19-
- [axios](https://axios-http.com/docs/intro) - direct calls to backend
20+
- [axios](https://axios-http.com/docs/intro) - direct calls to API
2021
- [react-query](https://tanstack.com/query/latest/docs/framework/react/overview) - use hooks that helps displaying data on UI
21-
- [orval](https://orval.dev/overview) - generating query hooks based on swagger (provided by backend)
22+
- [orval](https://orval.dev/overview) - generating query hooks based on swagger (provided by backend developers)
23+
24+
:::note
25+
If you are not using swagger (or open API v3) on your backend side it could be hard for you to make this working, because we are using [orval](https://orval.dev/overview) to auto generate everything.
26+
27+
If you will have any issues please contact **[Mateusz Rostkowski](https://www.github.com/MateuszRostkowski)**
28+
:::
2229

2330
## Generate new query
2431

25-
1. Get `swagger-spec.json` - example: https://gist.github.com/lenage/08964335de9064540c8c335fb849c5da
32+
All api connection code is automatically generated based on swagger schema, you will just need to do this few steps to update your code base.
33+
34+
1. Get `swagger-spec.json` from backend - example: https://gist.github.com/lenage/08964335de9064540c8c335fb849c5da
35+
- This also could be automaticaly done, probably we will work on it soon :)
2636
2. Replace it in `./scripts/data` folder
2737
3. Run script `yarn generate:query`
2838
4. See the magic happens ✨
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
id: api-example
3+
slug: /api-example
4+
title: API connection - example
5+
sidebar_position: 3
6+
tags:
7+
- Backend
8+
- MSW
9+
- Mocking
10+
- react-query
11+
- react-query example
12+
- axios
13+
- react native
14+
- orval
15+
description: Api example - check how to get data from backend and display it for users
16+
---
17+
18+
# Api example
19+
20+
We have prepared example with react query in this file: [src/screens/DataFromBeScreen_EXAMPLE.tsx](https://github.com/binarapps/baca-react-native-template/blob/main/src/screens/DataFromBeScreen_EXAMPLE.tsx)
21+
22+
```tsx
23+
// This is auto generated by orval scripts
24+
// success-line
25+
import { useArticlesControllerFindAll } from '@baca/api/query/articles/articles'
26+
import { ArticleEntity } from '@baca/api/types'
27+
import { Loader, Center, Text, Box, Spacer } from '@baca/design-system'
28+
import { useScreenOptions, useTranslation } from '@baca/hooks'
29+
import { useCallback } from 'react'
30+
import { ListRenderItem, FlatList } from 'react-native'
31+
32+
export const DataFromBeScreen_EXAMPLE = () => {
33+
const { t } = useTranslation()
34+
35+
useScreenOptions({
36+
title: t('navigation.screen_titles.data_from_be_screen_example'),
37+
})
38+
39+
// success-line
40+
const { data: articles, isInitialLoading: isInitialLoadingArticles } =
41+
// success-line
42+
useArticlesControllerFindAll({ page: 1, pageSize: 10 })
43+
44+
const renderItem: ListRenderItem<ArticleEntity> = useCallback(({ item: { id, title } }) => {
45+
return (
46+
<Box mb="1" bg="fg.brand.primary" borderRadius={2} m={2}>
47+
<Text>{'id: ' + id}</Text>
48+
<Text.MdRegular mb={2}>{'title: ' + title}</Text.MdRegular>
49+
</Box>
50+
)
51+
}, [])
52+
53+
return (
54+
<Box flex={1}>
55+
<Center flex={1}>
56+
<Text.XlRegular>THIS IS EXAMPLE SCREEN</Text.XlRegular>
57+
<Text.XlRegular>which contains data from backend</Text.XlRegular>
58+
<Spacer y="1" />
59+
<FlatList
60+
ListEmptyComponent={
61+
!isInitialLoadingArticles ? (
62+
<Center height={400} flex={1}>
63+
<Loader type="circle" />
64+
</Center>
65+
) : (
66+
<Text>No data found</Text>
67+
)
68+
}
69+
data={articles}
70+
renderItem={renderItem}
71+
/>
72+
</Center>
73+
</Box>
74+
)
75+
}
76+
```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
id: mocking-data
3+
slug: /mocking-data
4+
title: Mocking data
5+
sidebar_position: 5
6+
tags:
7+
- Backend
8+
- MSW
9+
- Mocking
10+
- react-query
11+
- axios
12+
- react native
13+
- orval
14+
description: Mocking - check how to mock data from backend and display it for users
15+
---
16+
17+
# Mocking data
18+
19+
This template uses [MSW](https://mswjs.io/docs) to mock data.
20+
21+
Mocks are automatically generated with orval script - you can check [docs here](/api-connection)
22+
23+
## Enabling mocks
24+
25+
Go to `App.tsx` and change `ENABLE_MOCKED_SERVER` variable from false to true
26+
27+
```tsx title="/App.tsx"
28+
// FIXME: moking not working on mobile app - follow this discussion https://github.com/mswjs/msw/issues/2026
29+
// error-line
30+
const ENABLE_MOCKED_SERVER = false
31+
// success-line
32+
const ENABLE_MOCKED_SERVER = true
33+
34+
if (ENABLE_MOCKED_SERVER) {
35+
startMockedServer()
36+
}
37+
```
38+
39+
This will start msw server and api calls will be mocked!
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"label": "Data management",
3+
"position": 5,
4+
"collapsible": true,
5+
"collapsed": false,
6+
"link": {
7+
"type": "generated-index",
8+
"description": "Documentation for data management in BACA projects"
9+
}
10+
}

docs/docs/deploy/_category_.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"label": "Deployment",
3-
"position": 4,
3+
"position": 6,
44
"collapsible": true,
55
"collapsed": false,
66
"link": {

docs/docs/tutorials/JOTAI.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

docs/docs/tutorials/_category_.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"label": "Tutorials",
3-
"position": 5,
3+
"position": 7,
44
"collapsible": true,
55
"collapsed": false,
66
"link": {

0 commit comments

Comments
 (0)