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
fix unnecessary rerendering
ammarahm-edef17442ec857
diff --git a/apps/mobile/src/components/listitems/headers/sectionheader.js b/apps/mobile/src/components/listitems/headers/sectionheader.jsindex 932f1839e..224fd5c78 100644--- a/apps/mobile/src/components/listitems/headers/sectionheader.js+++ b/apps/mobile/src/components/listitems/headers/sectionheader.js@@ -19,132 +19,135 @@ import { Button } from '../../ui/button';import Sort from '../../sheets/sort';import Heading from '../../ui/typography/heading';-export const SectionHeader = ({ item, index, type, color, screen }) => {- const colors = useThemeStore(state => state.colors);- const { fontScale } = useWindowDimensions();- const [groupOptions, setGroupOptions] = useState(db.settings?.getGroupOptions(type));- let groupBy = Object.keys(GROUP).find(key => GROUP[key] === groupOptions.groupBy);- const jumpToRef = useRef();- const sortRef = useRef();- const compactModeRef = useRef();+export const SectionHeader = React.memo(+ ({ item, index, type, color, screen }) => {+ const colors = useThemeStore(state => state.colors);+ const { fontScale } = useWindowDimensions();+ const [groupOptions, setGroupOptions] = useState(db.settings?.getGroupOptions(type));+ let groupBy = Object.keys(GROUP).find(key => GROUP[key] === groupOptions.groupBy);+ const jumpToRef = useRef();+ const sortRef = useRef();+ const compactModeRef = useRef();- const notebooksListMode = useSettingStore(state => state.settings.notebooksListMode);- const notesListMode = useSettingStore(state => state.settings.notesListMode);- const listMode = type === 'notebooks' ? notebooksListMode : notesListMode;+ const notebooksListMode = useSettingStore(state => state.settings.notebooksListMode);+ const notesListMode = useSettingStore(state => state.settings.notesListMode);+ const listMode = type === 'notebooks' ? notebooksListMode : notesListMode;- useEffect(() => {- console.log('rerender section header');- });+ groupBy = !groupBy+ ? 'Default'+ : groupBy.slice(0, 1).toUpperCase() + groupBy.slice(1, groupBy.length);- groupBy = !groupBy- ? 'Default'- : groupBy.slice(0, 1).toUpperCase() + groupBy.slice(1, groupBy.length);-- const onUpdate = () => {- setGroupOptions({ ...db.settings?.getGroupOptions(type) });- };-- useEffect(() => {- eSubscribeEvent('groupOptionsUpdate', onUpdate);- return () => {- eUnSubscribeEvent('groupOptionsUpdate', onUpdate);+ const onUpdate = () => {+ setGroupOptions({ ...db.settings?.getGroupOptions(type) });};- }, []);- return (- <View- style={{- flexDirection: 'row',- alignItems: 'center',- width: '95%',- justifyContent: 'space-between',- paddingHorizontal: 12,- height: 35 * fontScale,- backgroundColor: colors.nav,- alignSelf: 'center',- borderRadius: 5,- marginVertical: 5- }}- >- <TouchableOpacity- onPress={() => {- eSendEvent(eOpenJumpToDialog, type);- }}- ref={jumpToRef}- activeOpacity={0.9}- hitSlop={{ top: 10, left: 10, right: 30, bottom: 15 }}- style={{- height: '100%',- justifyContent: 'center'- }}- >- <Heading- color={COLORS_NOTE[color?.toLowerCase()] || colors.accent}- size={SIZE.sm}- style={{- minWidth: 60,- alignSelf: 'center',- textAlignVertical: 'center'- }}- >- {!item.title || item.title === '' ? 'Pinned' : item.title}- </Heading>- </TouchableOpacity>+ useEffect(() => {+ eSubscribeEvent('groupOptionsUpdate', onUpdate);+ return () => {+ eUnSubscribeEvent('groupOptionsUpdate', onUpdate);+ };+ }, []);+ return (<Viewstyle={{flexDirection: 'row',- alignItems: 'center'+ alignItems: 'center',+ width: '95%',+ justifyContent: 'space-between',+ paddingHorizontal: 12,+ height: 35 * fontScale,+ backgroundColor: colors.nav,+ alignSelf: 'center',+ borderRadius: 5,+ marginVertical: 5}}>- {index === 0 ? (- <>- <Button- onPress={() => {- presentSheet({- component: <Sort screen={screen} type={type} />- });- }}- tooltipText="Change sorting of items in list"- fwdRef={sortRef}- title={groupBy}- icon={groupOptions.sortDirection === 'asc' ? 'sort-ascending' : 'sort-descending'}- height={25}- style={{- borderRadius: 100,- paddingHorizontal: 0,- backgroundColor: 'transparent',- marginRight: type === 'notes' || type === 'home' || type === 'notebooks' ? 10 : 0- }}- type="gray"- iconPosition="right"- />+ <TouchableOpacity+ onPress={() => {+ eSendEvent(eOpenJumpToDialog, type);+ }}+ ref={jumpToRef}+ activeOpacity={0.9}+ hitSlop={{ top: 10, left: 10, right: 30, bottom: 15 }}+ style={{+ height: '100%',+ justifyContent: 'center'+ }}+ >+ <Heading+ color={COLORS_NOTE[color?.toLowerCase()] || colors.accent}+ size={SIZE.sm}+ style={{+ minWidth: 60,+ alignSelf: 'center',+ textAlignVertical: 'center'+ }}+ >+ {!item.title || item.title === '' ? 'Pinned' : item.title}+ </Heading>+ </TouchableOpacity>- {type === 'notes' || type === 'notebooks' || type === 'home' ? (- <IconButton- customStyle={{- width: 25,- height: 25- }}- tooltipText={- listMode == 'compact' ? 'Switch to normal mode' : 'Switch to compact mode'- }- fwdRef={compactModeRef}- color={colors.icon}- name={listMode == 'compact' ? 'view-list' : 'view-list-outline'}+ <View+ style={{+ flexDirection: 'row',+ alignItems: 'center'+ }}+ >+ {index === 0 ? (+ <>+ <ButtononPress={() => {- let settings = {};- settings[type !== 'notebooks' ? 'notesListMode' : 'notebooksListMode'] =- listMode === 'normal' ? 'compact' : 'normal';-- SettingsService.set(settings);+ presentSheet({+ component: <Sort screen={screen} type={type} />+ });+ }}+ tooltipText="Change sorting of items in list"+ fwdRef={sortRef}+ title={groupBy}+ icon={groupOptions.sortDirection === 'asc' ? 'sort-ascending' : 'sort-descending'}+ height={25}+ style={{+ borderRadius: 100,+ paddingHorizontal: 0,+ backgroundColor: 'transparent',+ marginRight: type === 'notes' || type === 'home' || type === 'notebooks' ? 10 : 0}}- size={SIZE.lg - 2}+ type="gray"+ iconPosition="right"/>- ) : null}- </>- ) : null}++ {type === 'notes' || type === 'notebooks' || type === 'home' ? (+ <IconButton+ customStyle={{+ width: 25,+ height: 25+ }}+ tooltipText={+ listMode == 'compact' ? 'Switch to normal mode' : 'Switch to compact mode'+ }+ fwdRef={compactModeRef}+ color={colors.icon}+ name={listMode == 'compact' ? 'view-list' : 'view-list-outline'}+ onPress={() => {+ let settings = {};+ settings[type !== 'notebooks' ? 'notesListMode' : 'notebooksListMode'] =+ listMode === 'normal' ? 'compact' : 'normal';++ SettingsService.set(settings);+ }}+ size={SIZE.lg - 2}+ />+ ) : null}+ </>+ ) : null}+ </View></View>- </View>- );-};+ );+ },+ (prev, next) => {+ if (prev.item.title !== next.item.title) return false;++ return true;+ }+);