Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: load everything in provider

ammarahm-edcfc13762dfb1
diff --git a/apps/mobile/src/provider/index.js b/apps/mobile/src/provider/index.js
index 2549bf0ce..13d42dec8 100644
--- a/apps/mobile/src/provider/index.js
+++ b/apps/mobile/src/provider/index.js
@@ -1,11 +1,21 @@
-import React, {createContext, useEffect} from 'react';
+import React, {createContext, useEffect, useState} from 'react';
+import {View, Text} from 'react-native';
import {useImmer} from 'use-immer';
-import {DDS} from '../../App';
+import {DDS, db} from '../../App';
+import {getColorScheme} from '../common/common';
const defaultState = {
isMenuOpen: {
current: false,
},
+ selectionMode: false,
+ selectedItemsList: [],
+ notes: [],
+ notebooks: [],
+ trash: [],
+ favorites: [],
+ pinned: [],
+ tags: [],
colors: {
night: false,
bg: 'white',
@@ -25,18 +35,53 @@ const defaultState = {
warningBg: '#FEEFB3',
warningText: '#9F6000',
},
- selectionMode: false,
- selectedItemsList: [],
};
const AppContext = createContext([defaultState, function() {}]);
const AppProvider = ({children}) => {
const [state, dispatch] = useImmer({...defaultState});
+ const [loading, setLoading] = useState(true);
+
+ async function init() {
+ let newColors = await getColorScheme();
+
+ dispatch(draft => {
+ draft.colors = {...newColors};
+ draft.notes = db.groupNotes();
+ });
+ setLoading(false);
+ }
+
+ useEffect(() => {
+ init();
+ }, []);
+
+ useEffect(() => {
+ dispatch(draft => {
+ draft.notebooks = db.getNotebooks();
+ draft.trash = db.getTrash();
+ draft.favorites = db.getFavorites();
+ draft.pinned = db.getPinned();
+ });
+ }, []);
return (
<AppContext.Provider value={[state, dispatch]}>
- {children}
+ {loading ? (
+ <View
+ style={{
+ width: '100%',
+ height: '100%',
+ backgroundColor: 'white',
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}>
+ <Text>Loading...</Text>
+ </View>
+ ) : (
+ children
+ )}
</AppContext.Provider>
);
};