From 60eedfe7baf69445e0a17aba7387731384265122 Mon Sep 17 00:00:00 2001 From: Ana Bujan Date: Wed, 11 Dec 2024 08:19:18 +0100 Subject: [PATCH] add redux integration --- README.md | 8 +- app/_layout.tsx | 22 +-- app/detail/[id].tsx | 19 +-- app/index.tsx | 19 +-- package-lock.json | 206 ++++++++++++++++++++++- package.json | 4 + src/data/providers/AppDataProvider.tsx | 23 ++- src/data/types.ts | 1 + src/store/index.ts | 45 +++++ src/store/taskSlice.ts | 51 ++++++ src/taskClient/IndexedDBClient.ts | 12 +- src/taskClient/LocalStorageTaskClient.ts | 15 +- src/taskClient/SQLiteTaskClient.spec.ts | 2 +- src/taskClient/SQLiteTaskClient.ts | 6 +- src/taskClient/types.ts | 2 +- 15 files changed, 375 insertions(+), 60 deletions(-) create mode 100644 src/store/index.ts create mode 100644 src/store/taskSlice.ts diff --git a/README.md b/README.md index 74dd975..efe7a7b 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Includes integration tests and a multi-platform demo (Android & web). I made first version of the app to showcase how you can to database migrations and configure integration tests to be run in a Node.js environment. Read more about it in my blog post on [expo sqlite migrations and integration testing](https://www.amarjanica.com/bridging-the-gap-between-expo-sqlite-and-node-js/) -or [watch my YT tutorial](https://youtu.be/5OBi4JtlGfY). +or [watch my YT tutorial](https://youtu.be/5OBi4JtlGfY). [Codebase](https://github.com/amarjanica/react-native-sqlite-expo-demo/tree/98c355d5b1fa065a5ec6585273232908edfe50ec) ## 2. Web support with SQLite, AsyncStorage and IndexedDB @@ -16,7 +16,11 @@ I've added web support to the app, so it can run on the web. You can dynamically different storage types: SQLite, AsyncStorage and IndexedDB. SQLite is supported on the web via [sql.js](https://github.com/sql-js/sql.js/). Read more about it in my blog post on [expo sqlite, indexeddb and asyncstorage on the web](https://www.amarjanica.com/expo-sqlite-on-the-web-localstorage-indexeddb-and-sql-js/) -or [watch my YT tutorial](https://youtu.be/JZYXtOgqEbc). +or [watch my YT tutorial](https://youtu.be/JZYXtOgqEbc). +[Codebase](https://github.com/amarjanica/react-native-sqlite-expo-demo/tree/5dd4a2d046073127a1d9f82e7ebd54c1c1b98f7b) + +## 3. Redux +I've integrated Redux into the app to manage global state more efficiently. # App Screenshot

diff --git a/app/_layout.tsx b/app/_layout.tsx index e212e24..1240fca 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -5,6 +5,10 @@ import React from 'react'; import AppDataProvider from '@/data/providers/AppDataProvider'; import { PersistenceType } from '@/data/types'; +const enabledPersistenceTypes = Platform.select({ + web: [PersistenceType.localstorage, PersistenceType.indexedDB, PersistenceType.sqlite], + default: [PersistenceType.localstorage, PersistenceType.sqlite], +}); const Root = () => { const [persistenceType, setPersistenceType] = React.useState( Platform.select({ web: PersistenceType.indexedDB, default: PersistenceType.sqlite }) @@ -20,15 +24,13 @@ const Root = () => { Persistence type: {persistenceType}, OS: {Platform.OS} - - - + {enabledPersistenceTypes.map((persistenceType) => ( +