A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
change hightlight according to index
ammarahm-ed7e54229f908f
diff --git a/apps/mobile/src/components/JumpToDialog/index.js b/apps/mobile/src/components/JumpToDialog/index.jsindex f3e846e7c..b9d1589fd 100644--- a/apps/mobile/src/components/JumpToDialog/index.js+++ b/apps/mobile/src/components/JumpToDialog/index.js@@ -1,121 +1,164 @@-import React, { useEffect, useState } from 'react';-import { ScrollView, Text, View } from 'react-native';+import React, {useEffect, useState} from 'react';+import {ScrollView, Text, View} from 'react-native';import BaseDialog from '../../components/Dialog/base-dialog';-import { PressableButton } from '../../components/PressableButton';+import {PressableButton} from '../../components/PressableButton';import Seperator from '../../components/Seperator';-import { useTracked } from '../../provider';-import { DDS } from '../../services/DeviceDetection';-import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/EventManager';-import { getElevation } from '../../utils';+import {useTracked} from '../../provider';+import {DDS} from '../../services/DeviceDetection';+import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';+import {getElevation, scrollRef} from '../../utils';import {- eCloseJumpToDialog,- eOpenJumpToDialog+ eCloseJumpToDialog,+ eOpenJumpToDialog,+ eScrollEvent,} from '../../utils/Events';-import { SIZE, WEIGHT } from '../../utils/SizeUtils';+import {SIZE, WEIGHT} from '../../utils/SizeUtils';import Paragraph from '../Typography/Paragraph';+const offsets = [];+let timeout = null;const JumpToDialog = () => {- const [state] = useTracked();- const {notes, colors, settings} = state;- const [visible,setVisible] = useState(false)-- useEffect(() => {});- console.log(notes.filter((i) => i.type === 'header'));-- const onPress = (item, index) => {- let offset = 30 * index;- let ind = notes.findIndex(- (i) => i.title === item.title && i.type === 'header',- );- ind = ind + 1;- ind = ind - (index + 1);- offset = offset + ind * 100;- scrollRef.current?.scrollToOffset(0, index === 0 ? 0 : offset + 50, true);- close();- };-- useEffect(() => {- eSubscribeEvent(eOpenJumpToDialog, open);- eSubscribeEvent(eCloseJumpToDialog, close);-- return () => {- eUnSubscribeEvent(eOpenJumpToDialog, open);- eUnSubscribeEvent(eCloseJumpToDialog, close);- };- }, []);-- const open = () => {- setVisible(true);- };-- const close = () => {- setVisible(false);-- };-- return (- <BaseDialog onRequestClose={close} visible={visible}>- <View- style={{- ...getElevation(5),- width: DDS.isTab ? 500 : '80%',- backgroundColor: colors.bg,- zIndex: 100,- bottom: 20,- maxHeight: '65%',- borderRadius: 5,- alignSelf: 'center',- padding: 10,- }}>- <Text- style={{- fontSize: SIZE.xl,- fontFamily: WEIGHT.bold,- color: colors.heading,- alignSelf: 'center',- }}>- {settings.sort.slice(0, 1).toUpperCase() +- settings.sort.slice(1, settings.sort.length)}- </Text>- <Seperator />- <ScrollView- style={{- maxHeight: '100%',- }}>- <View- style={{- flexDirection: 'row',- flexWrap: 'wrap',- alignSelf: 'center',- justifyContent: 'center',- }}>- {notes- .filter((i) => i.type === 'header')- .map((item, index) => (- <PressableButton- onPress={() => onPress(item, index)}- selectedColor={colors.nav}- customStyle={{- minWidth: '20%',- maxWidth: '46%',- width: null,- padding: 15,- margin: 5,- }}>- <Paragraph- size={SIZE.xs}- style={{- textAlign: 'center',- }}>- {item.title}- </Paragraph>- </PressableButton>- ))}- </View>- </ScrollView>- </View>- </BaseDialog>- );+ const [state] = useTracked();+ const {notes, colors, settings} = state;+ const [visible, setVisible] = useState(false);+ const [currentIndex, setCurrentIndex] = useState(0);++ const onPress = (item, index) => {+ let offset = 30 * index;+ let ind = notes.findIndex(+ (i) => i.title === item.title && i.type === 'header',+ );+ ind = ind + 1;+ ind = ind - (index + 1);+ offset = offset + ind * 100;+ scrollRef.current?.scrollToOffset(0, index === 0 ? 0 : offset + 50, true);+ close();+ };++ useEffect(() => {+ eSubscribeEvent(eOpenJumpToDialog, open);+ eSubscribeEvent(eCloseJumpToDialog, close);+ eSubscribeEvent(eScrollEvent, onScroll);++ return () => {+ eUnSubscribeEvent(eOpenJumpToDialog, open);+ eUnSubscribeEvent(eCloseJumpToDialog, close);+ eUnSubscribeEvent(eScrollEvent, onScroll);+ };+ }, []);++ const onScroll = (y) => {+ if (timeout) {+ clearTimeout(timeout);+ timeout = null;+ }+ timeout = setTimeout(() => {+ let index = offsets.findIndex((o, i) => o <= y && offsets[i + 1] > y);+ setCurrentIndex(index);+ }, 30);+ };++ const open = () => {+ setVisible(true);};- export default JumpToDialog\ No newline at end of file+ const close = () => {+ setVisible(false);+ };++ useEffect(() => {+ loadOffsets();+ }, [notes]);++ const loadOffsets = () => {+ notes+ .filter((i) => i.type === 'header')+ .map((item, index) => {+ let offset = 30 * index;+ let ind = notes.findIndex(+ (i) => i.title === item.title && i.type === 'header',+ );+ ind = ind + 1;+ ind = ind - (index + 1);+ offset = offset + ind * 100;+ offsets.push(offset);+ });+ };++ return (+ <BaseDialog+ onShow={() => {+ loadOffsets();+ }}+ onRequestClose={close}+ visible={visible}>+ <View+ style={{+ ...getElevation(5),+ width: DDS.isTab ? 500 : '80%',+ backgroundColor: colors.bg,+ zIndex: 100,+ bottom: 20,+ maxHeight: '65%',+ borderRadius: 5,+ alignSelf: 'center',+ padding: 10,+ }}>+ <Text+ style={{+ fontSize: SIZE.xl,+ fontFamily: WEIGHT.bold,+ color: colors.heading,+ alignSelf: 'center',+ }}>+ {settings.sort.slice(0, 1).toUpperCase() ++ settings.sort.slice(1, settings.sort.length)}+ </Text>+ <Seperator />+ <ScrollView+ style={{+ maxHeight: '100%',+ }}>+ <View+ style={{+ flexDirection: 'row',+ flexWrap: 'wrap',+ alignSelf: 'center',+ justifyContent: 'center',+ }}>+ {notes+ .filter((i) => i.type === 'header')+ .map((item, index) => (+ <PressableButton+ onPress={() => onPress(item, index)}+ color={currentIndex === index ? colors.shade : 'transparent'}+ selectedColor={+ currentIndex === index ? colors.accent : colors.nav+ }+ alpha={!colors.night ? -0.02 : 0.02}+ opacity={currentIndex === index ? 0.12 : 1}+ customStyle={{+ minWidth: '20%',+ maxWidth: '46%',+ width: null,+ padding: 15,+ margin: 5,+ }}>+ <Paragraph+ size={SIZE.xs}+ color={currentIndex === index ? colors.accent : null}+ style={{+ textAlign: 'center',+ }}>+ {item.title}+ </Paragraph>+ </PressableButton>+ ))}+ </View>+ </ScrollView>+ </View>+ </BaseDialog>+ );+};++export default JumpToDialog;diff --git a/apps/mobile/src/utils/index.js b/apps/mobile/src/utils/index.jsindex 290a5cbcb..d24d112d1 100755--- a/apps/mobile/src/utils/index.js+++ b/apps/mobile/src/utils/index.js@@ -5,6 +5,7 @@ import {Actions} from '../provider/Actions';import {MMKV} from "./MMKV";import RNFetchBlob from 'rn-fetch-blob';import {defaultState} from "../provider/DefaultState";+import { createRef } from 'react';export async function setSetting(settings, name, value) {let s = {...settings};@@ -13,6 +14,9 @@ export async function setSetting(settings, name, value) {updateEvent({type: Actions.SETTINGS, settings: s});}++export const scrollRef = createRef();+export const dirs = RNFetchBlob.fs.dirs;export const ANDROID_PATH = dirs.SDCardDir + '/Notesnook/';export const IOS_PATH = dirs.DocumentDir;diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.jsindex 5e7df1790..dd2ec3eec 100755--- a/apps/mobile/src/views/Home/index.js+++ b/apps/mobile/src/views/Home/index.js@@ -7,7 +7,7 @@ import { useTracked } from '../../provider';import { Actions } from '../../provider/Actions';import { DDS } from '../../services/DeviceDetection';import { eSendEvent } from '../../services/EventManager';-import { sortSettings } from '../../utils';+import { scrollRef, sortSettings } from '../../utils';import { openEditorAnimation } from '../../utils/Animations';import {eOnLoadNote,@@ -16,8 +16,6 @@ import {eUpdateSearchState} from '../../utils/Events';-const scrollRef = createRef();-export const Home = ({navigation}) => {const [state, dispatch] = useTracked();const {notes} = state;