From bb79a4f61ca76a179a49b3ac2ea9eac218eceb5d Mon Sep 17 00:00:00 2001 From: Chasen Le Hara Date: Fri, 24 May 2024 11:33:04 -0700 Subject: [PATCH] =?UTF-8?q?Fix=20the=20solution=20code=20for=20=E2=80=9CUs?= =?UTF-8?q?ing=20Async=20Storage=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also, other minor improvements. --- .../01-problem/src/services/storage/storage.ts | 2 +- .../01-solution/src/services/pmo/api/api.ts | 2 +- .../using-asyncstorage.md | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/exercise-src/react-native/15-async-storage/01-problem/src/services/storage/storage.ts b/exercise-src/react-native/15-async-storage/01-problem/src/services/storage/storage.ts index fe6dfc004..f0def6994 100644 --- a/exercise-src/react-native/15-async-storage/01-problem/src/services/storage/storage.ts +++ b/exercise-src/react-native/15-async-storage/01-problem/src/services/storage/storage.ts @@ -1,6 +1,6 @@ import AsyncStorage from "@react-native-async-storage/async-storage" -// Exercise: Implement the four `AsyncStorage` helpers in `storage.ts`. +// Exercise: Implement the four `AsyncStorage` helpers. export const getData = async (key: string): Promise => {} export const getAllKeys = (): Promise => {} diff --git a/exercise-src/react-native/15-async-storage/01-solution/src/services/pmo/api/api.ts b/exercise-src/react-native/15-async-storage/01-solution/src/services/pmo/api/api.ts index 67c9ef8ee..af443dec9 100644 --- a/exercise-src/react-native/15-async-storage/01-solution/src/services/pmo/api/api.ts +++ b/exercise-src/react-native/15-async-storage/01-solution/src/services/pmo/api/api.ts @@ -63,7 +63,7 @@ export async function apiRequest< if (method === "GET" && response.ok) { await storeData>(keyPrefix + requestUrl, { data: data, - dateTime: new Date().toDateString(), + dateTime: new Date().toJSON(), }) } diff --git a/src/react-native/15-using-asyncstorage/using-asyncstorage.md b/src/react-native/15-using-asyncstorage/using-asyncstorage.md index 72647a71e..e10e96139 100644 --- a/src/react-native/15-using-asyncstorage/using-asyncstorage.md +++ b/src/react-native/15-using-asyncstorage/using-asyncstorage.md @@ -126,17 +126,24 @@ Here are some pointers on implementing this strategy: npm install @react-native-async-storage/async-storage@1 ``` -✏️ Update **jest-setup.ts** to be: +✏️ Terminate the existing dev server and start it again: -@diff ../../../exercises/react-native/14-user-input/01-solution/jest-setup.ts ../../../exercises/react-native/15-async-storage/01-problem/jest-setup.ts only +```bash +npm run start +``` -✏️ Create **src/services/storage/index.ts** and update it to be: +✏️ Update **jest-setup.ts** to be: -@sourceref ../../../exercises/react-native/15-async-storage/01-problem/src/services/storage/index.ts +@diff ../../../exercises/react-native/14-user-input/01-solution/jest-setup.ts ../../../exercises/react-native/15-async-storage/01-problem/jest-setup.ts only ✏️ Create **src/services/storage/storage.ts** and update it to be: @sourceref ../../../exercises/react-native/15-async-storage/01-problem/src/services/storage/storage.ts +@highlight 3 + +✏️ Create **src/services/storage/index.ts** and update it to be: + +@sourceref ../../../exercises/react-native/15-async-storage/01-problem/src/services/storage/index.ts ✏️ Update **src/services/pmo/api/api.ts** to be: @@ -166,6 +173,8 @@ You can verify that this is working correctly by using DevTools to: - View the requests (or lack thereof) being made. - Inspect the stored data. +**Hint:** Use [`new Date().toJSON()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON) to get the current datetime as a string. + ### Solution 1 If you’ve implemented the solution correctly, the tests will pass when you run `npm run test`! @@ -249,6 +258,7 @@ We’ll assume that the data is version `1` if we haven’t stored the version n ✏️ Create **src/services/DataMigration/DataMigration.tsx** and update it to be: @sourceref ../../../exercises/react-native/15-async-storage/02-problem/src/services/DataMigration/DataMigration.tsx +@highlight 13, 21-23, only ✏️ Create **src/services/DataMigration/index.ts** and update it to be: