Skip to content

Commit bde5de5

Browse files
authored
Sycing RN fetching and rendering (#908)
* Sycing RN fetching and rendering * updating react-vite to use undefined for fetching
1 parent 163de15 commit bde5de5

File tree

218 files changed

+1090
-1094
lines changed

Some content is hidden

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

218 files changed

+1090
-1094
lines changed

exercise-src/react-native/13-http-requests/03-problem/src/services/pmo/api/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export async function apiRequest<
1414
params?: Params
1515
path: string
1616
body?: Body
17-
}): Promise<{ data: Data | undefined; error: Error | undefined }> {}
17+
}): Promise<{ data?: Data; error?: Error }> {}
1818

1919
export function stringifyQuery(
2020
input: Record<string, string | undefined | undefined>,

exercise-src/react-native/13-http-requests/03-solution/src/services/pmo/api/api.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export async function apiRequest<
1414
params?: Params
1515
path: string
1616
body?: Body
17-
}): Promise<{ data: Data | undefined; error: Error | undefined }> {
17+
}): Promise<{ data?: Data; error?: Error }> {
1818
try {
1919
const query = params ? stringifyQuery(params) : ""
2020
const requestUrl = `${baseUrl}${path}?${query}`
@@ -28,15 +28,13 @@ export async function apiRequest<
2828
})
2929

3030
const data = await response.json()
31-
32-
if (!response.ok) {
33-
const error = new Error(`${response.status} (${response.statusText})`)
34-
return { data: data, error: error }
35-
}
31+
const error = response.ok
32+
? undefined
33+
: new Error(`${response.status} (${response.statusText})`)
3634

3735
return {
3836
data: "data" in data ? data.data : data,
39-
error: undefined,
37+
error: error,
4038
}
4139
} catch (error) {
4240
return {

exercise-src/react-native/15-async-storage/01-problem/src/services/pmo/api/api.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ export async function apiRequest<
3737
})
3838

3939
const data = await response.json()
40-
41-
if (!response.ok) {
42-
const error = new Error(`${response.status} (${response.statusText})`)
43-
return { data: data, error: error }
44-
}
40+
const error = response.ok
41+
? undefined
42+
: new Error(`${response.status} (${response.statusText})`)
4543

4644
return {
4745
data: "data" in data ? data.data : data,
48-
error: undefined,
46+
error: error,
4947
}
5048
} catch (error) {
5149
return {

exercise-src/react-native/15-async-storage/01-solution/src/services/pmo/api/api.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ export async function apiRequest<
5959
})
6060

6161
const data = await response.json()
62+
const error = response.ok
63+
? undefined
64+
: new Error(`${response.status} (${response.statusText})`)
6265

6366
if (method === "GET" && response.ok) {
6467
await storeData<CachedResponse<Data>>(keyPrefix + requestUrl, {
@@ -67,14 +70,9 @@ export async function apiRequest<
6770
})
6871
}
6972

70-
if (!response.ok) {
71-
const error = new Error(`${response.status} (${response.statusText})`)
72-
return { data: data, error: error }
73-
}
74-
7573
return {
7674
data: "data" in data ? data.data : data,
77-
error: undefined,
75+
error: error,
7876
}
7977
} catch (error) {
8078
return {

exercise-src/react-native/15-async-storage/02-problem/src/services/pmo/api/api.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function apiRequest<
2323
params?: Params
2424
path: string
2525
body?: Body
26-
}): Promise<{ data: Data | undefined; error: Error | undefined }> {
26+
}): Promise<{ data?: Data; error?: Error }> {
2727
try {
2828
const query = params ? stringifyQuery(params) : ""
2929
const requestUrl = `${baseUrl}${path}?${query}`
@@ -58,6 +58,9 @@ export async function apiRequest<
5858
})
5959

6060
const data = await response.json()
61+
const error = response.ok
62+
? undefined
63+
: new Error(`${response.status} (${response.statusText})`)
6164

6265
if (method === "GET" && response.ok) {
6366
await storeData<CachedResponse<Data>>(keyPrefix + requestUrl, {
@@ -66,14 +69,9 @@ export async function apiRequest<
6669
})
6770
}
6871

69-
if (!response.ok) {
70-
const error = new Error(`${response.status} (${response.statusText})`)
71-
return { data: data, error: error }
72-
}
73-
7472
return {
7573
data: "data" in data ? data.data : data,
76-
error: undefined,
74+
error: error,
7775
}
7876
} catch (error) {
7977
return {

exercises/react-vite/05-props/01-solution/src/pages/RestaurantList/ListItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const ListItem: React.FC<ListItemProps> = ({
1919
return (
2020
<>
2121
<div className="restaurant">
22-
<img src={thumbnail} alt={`A thumbnail for ${name}`} width="100" height="100" />
22+
<img src={`/${thumbnail}`} alt={`A thumbnail for ${name}`} width="100" height="100" />
2323
<h3>{name}</h3>
2424

2525
{address && (

exercises/react-vite/06-routing/01-problem/src/pages/RestaurantList/ListItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const ListItem: React.FC<ListItemProps> = ({
1919
return (
2020
<>
2121
<div className="restaurant">
22-
<img src={thumbnail} alt={`A thumbnail for ${name}`} width="100" height="100" />
22+
<img src={`/${thumbnail}`} alt={`A thumbnail for ${name}`} width="100" height="100" />
2323
<h3>{name}</h3>
2424

2525
{address && (

exercises/react-vite/06-routing/01-solution/src/pages/RestaurantList/ListItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const ListItem: React.FC<ListItemProps> = ({
1919
return (
2020
<>
2121
<div className="restaurant">
22-
<img src={thumbnail} alt={`A thumbnail for ${name}`} width="100" height="100" />
22+
<img src={`/${thumbnail}`} alt={`A thumbnail for ${name}`} width="100" height="100" />
2323
<h3>{name}</h3>
2424

2525
{address && (

exercises/react-vite/06-routing/02-problem/src/pages/RestaurantList/ListItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const ListItem: React.FC<ListItemProps> = ({
1919
return (
2020
<>
2121
<div className="restaurant">
22-
<img src={thumbnail} alt={`A thumbnail for ${name}`} width="100" height="100" />
22+
<img src={`/${thumbnail}`} alt={`A thumbnail for ${name}`} width="100" height="100" />
2323
<h3>{name}</h3>
2424

2525
{address && (

exercises/react-vite/06-routing/02-solution/src/pages/RestaurantList/ListItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const ListItem: React.FC<ListItemProps> = ({
1919
return (
2020
<>
2121
<div className="restaurant">
22-
<img src={thumbnail} alt={`A thumbnail for ${name}`} width="100" height="100" />
22+
<img src={`/${thumbnail}`} alt={`A thumbnail for ${name}`} width="100" height="100" />
2323
<h3>{name}</h3>
2424

2525
{address && (

0 commit comments

Comments
 (0)