Skip to content

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

some refactoring

ammarahm-ed132ba3958938
diff --git a/apps/mobile/src/components/Header/HeaderLeftMenu.js b/apps/mobile/src/components/Header/HeaderLeftMenu.js
index 3da17a881..128c6c607 100644
--- a/apps/mobile/src/components/Header/HeaderLeftMenu.js
+++ b/apps/mobile/src/components/Header/HeaderLeftMenu.js
@@ -3,7 +3,6 @@ import {notesnook} from '../../../e2e/test.ids';
import {useTracked} from '../../provider';
import { DDS } from '../../services/DeviceDetection';
import Navigation from '../../services/Navigation';
-import SettingsService from '../../services/SettingsService';
import {SIZE} from '../../utils/SizeUtils';
import {ActionIcon} from '../ActionIcon';
@@ -18,6 +17,9 @@ export const HeaderLeftMenu = () => {
}
Navigation.goBack();
};
+
+
+
return (
<>
{deviceMode === 'mobile' ||
diff --git a/apps/mobile/src/components/Header/HeaderTitle.js b/apps/mobile/src/components/Header/HeaderTitle.js
index e1ae815f5..b2b869b82 100644
--- a/apps/mobile/src/components/Header/HeaderTitle.js
+++ b/apps/mobile/src/components/Header/HeaderTitle.js
@@ -1,8 +1,9 @@
-import React, { useEffect } from 'react';
+import React, { useEffect, useState } from 'react';
import Animated from 'react-native-reanimated';
import { useTracked } from '../../provider';
import { DDS } from '../../services/DeviceDetection';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/EventManager';
+import Navigation from '../../services/Navigation';
import { eScrollEvent } from '../../utils/Events';
import Heading from '../Typography/Heading';
@@ -12,7 +13,19 @@ let scrollPostions = {};
export const HeaderTitle = () => {
const [state] = useTracked();
- const {colors, headerTextState} = state;
+ const {colors} = state;
+ const [headerTextState, setHeaderTextState] = useState(Navigation.getHeaderState());
+
+ const onHeaderStateChange = (event) => {
+ setHeaderTextState(event);
+ };
+ useEffect(() => {
+ eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
+ return () => {
+ eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
+ };
+ }, []);
+
const onScroll = async (y) => {
if (DDS.isLargeTablet()) return;
@@ -42,7 +55,7 @@ export const HeaderTitle = () => {
} else {
opacity.setValue(0);
}
- scrollPostions[headerTextState.heading] = y;
+ scrollPostions[headerTextState?.heading] = y;
};
useEffect(() => {
@@ -50,7 +63,7 @@ export const HeaderTitle = () => {
return () => {
eUnSubscribeEvent(eScrollEvent, onScroll);
};
- }, [headerTextState.heading]);
+ }, [headerTextState?.heading]);
return (
<Animated.View
diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.js
index 6667abce0..a79bf0ce1 100644
--- a/apps/mobile/src/components/SimpleList/index.js
+++ b/apps/mobile/src/components/SimpleList/index.js
@@ -10,7 +10,12 @@ import {useSafeAreaInsets} from 'react-native-safe-area-context';
import {DataProvider, LayoutProvider, RecyclerListView} from 'recyclerlistview';
import {useTracked} from '../../provider';
import {DDS} from '../../services/DeviceDetection';
-import {eSendEvent} from '../../services/EventManager';
+import {
+ eSendEvent,
+ eSubscribeEvent,
+ eUnSubscribeEvent,
+} from '../../services/EventManager';
+import Navigation from '../../services/Navigation';
import Sync from '../../services/Sync';
import {dHeight} from '../../utils';
import {COLORS_NOTE} from '../../utils/Colors';
@@ -59,8 +64,6 @@ const SimpleList = ({
const listData = data;
const dataType = type;
-
-
useEffect(() => {
if (loading) return;
loadData();
@@ -240,7 +243,13 @@ const SimpleList = ({
export default SimpleList;
-const RenderSectionHeader = ({item, index, headerProps, jumpToDialog,sortMenuButton}) => {
+const RenderSectionHeader = ({
+ item,
+ index,
+ headerProps,
+ jumpToDialog,
+ sortMenuButton,
+}) => {
const [state] = useTracked();
const {colors} = state;
@@ -290,9 +299,23 @@ const RenderSectionHeader = ({item, index, headerProps, jumpToDialog,sortMenuBut
const ListEmptyComponent = ({loading = true, placeholderData}) => {
const [state] = useTracked();
- const {colors, headerTextState} = state;
+ const {colors} = state;
+ const [headerTextState, setHeaderTextState] = useState(
+ Navigation.getHeaderState(),
+ );
const insets = useSafeAreaInsets();
const {height} = useWindowDimensions();
+
+ const onHeaderStateChange = (event) => {
+ setHeaderTextState(event);
+ };
+ useEffect(() => {
+ eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
+ return () => {
+ eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);
+ };
+ }, []);
+
return (
<View
style={[
@@ -333,7 +356,13 @@ const ListEmptyComponent = ({loading = true, placeholderData}) => {
}
/>
) : loading ? (
- <ActivityIndicator color={colors.accent} />
+ <ActivityIndicator
+ color={
+ COLORS_NOTE[headerTextState.heading.toLowerCase()]
+ ? COLORS_NOTE[headerTextState.heading.toLowerCase()]
+ : colors.accent
+ }
+ />
) : null}
</View>
</View>
diff --git a/apps/mobile/src/services/Navigation.js b/apps/mobile/src/services/Navigation.js
index bef361d48..b6ba18747 100755
--- a/apps/mobile/src/services/Navigation.js
+++ b/apps/mobile/src/services/Navigation.js
@@ -5,8 +5,11 @@ import { rootNavigatorRef, sideMenuRef } from '../utils/Refs';
import { eSendEvent } from './EventManager';
import SettingsService from './SettingsService';
-let currentScreen = null;
-let headerState = null;
+let currentScreen = "Notes"
+let headerState = {
+ heading: 'Notes',
+ color: null,
+}
function getCurrentScreen() {
return currentScreen;
}
@@ -46,13 +49,8 @@ function setHeaderState(name, params, item) {
headerState = item;
currentScreen = name;
if (item) {
- updateEvent({
- type: Actions.HEADER_TEXT_STATE,
- state: item,
- });
eSendEvent('onHeaderStateChange', item);
}
-
if (name) {
updateEvent({
type: Actions.CURRENT_SCREEN,