Files
notesnook/apps/mobile/app/components/side-menu/index.js
Ammar Ahmed 89c2d45a4b mobile: reduce app size (#3068)
* mobile: reduce app size

* editor: substitute all @mdi/js icons at build time

* mobile: add script to tree shake icon font file

* mobile: fix icon loading

* mobile: remove html-entities dep

* mobile: add missing icon fonts

* mobile: include plain editor

* mobile: add missing fonts

* mobile: use webpack-bundle

* mobile: keep generated fonts in repo

* mobile: update fonts

* mobile: fix duplicate key warning

* mobile: update fonts

* mobile: disable gesure on reminder sheet

* mobile: update fonts

* mobile: reset session correctly on logout

* mobile: update icon fonts

* mobile: set button action on reminder sheet

* mobile: add missing icons

* mobile: fix crash

* mobile: fix right menus

* mobile: remove console.log

* mobile: disable bounce effect

* mobile: update deps

---------

Co-authored-by: Abdullah Atta <abdullahatta@streetwriters.co>
2023-08-02 15:35:15 +05:00

188 lines
5.5 KiB
JavaScript

/*
This file is part of the Notesnook project (https://notesnook.com/)
Copyright (C) 2023 Streetwriters (Private) Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React, { useCallback } from "react";
import { FlatList, View } from "react-native";
import { notesnook } from "../../../e2e/test.ids";
import useGlobalSafeAreaInsets from "../../hooks/use-global-safe-area-insets";
import { DDS } from "../../services/device-detection";
import { eSendEvent } from "../../services/event-manager";
import Navigation from "../../services/navigation";
import { useNoteStore } from "../../stores/use-notes-store";
import { useSettingStore } from "../../stores/use-setting-store";
import { useThemeColors } from "@notesnook/theme";
import { useUserStore } from "../../stores/use-user-store";
import { MenuItemsList } from "../../utils/menu-items";
import { SUBSCRIPTION_STATUS } from "../../utils/constants";
import { eOpenPremiumDialog } from "../../utils/events";
import { ColorSection } from "./color-section";
import { MenuItem } from "./menu-item";
import { TagsSection } from "./pinned-section";
import { UserStatus } from "./user-status";
import { useThemeStore } from "../../stores/use-theme-store";
export const SideMenu = React.memo(
function SideMenu() {
const { colors, isDark } = useThemeColors();
const insets = useGlobalSafeAreaInsets();
const subscriptionType = useUserStore(
(state) => state.user?.subscription?.type
);
const loading = useNoteStore((state) => state.loading);
const introCompleted = useSettingStore(
(state) => state.settings.introCompleted
);
const noTextMode = false;
const BottomItemsList = [
{
name: isDark ? "Day" : "Night",
icon: "theme-light-dark",
func: () => {
useThemeStore.getState().setColorScheme();
},
switch: true,
on: !!isDark,
close: false
},
{
name: "Settings",
icon: "cog-outline",
close: true,
func: () => {
Navigation.navigate({
name: "Settings",
title: "Settings"
});
}
}
];
const pro = {
name: "Notesnook Pro",
icon: "crown",
func: () => {
eSendEvent(eOpenPremiumDialog);
}
};
const renderItem = useCallback(
() => (
<>
{MenuItemsList.map((item, index) => (
<MenuItem
key={item.name}
item={item}
testID={item.name}
index={index}
/>
))}
<ColorSection noTextMode={noTextMode} />
<TagsSection />
</>
),
[noTextMode]
);
return !loading && introCompleted ? (
<View
style={{
height: "100%",
width: "100%",
backgroundColor: colors.primary.background
}}
>
<View
style={{
height: "100%",
width: "100%",
backgroundColor: colors.primary.background,
paddingTop: insets.top,
borderRadius: 10,
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0
}}
>
<FlatList
alwaysBounceVertical={false}
contentContainerStyle={{
flexGrow: 1
}}
style={{
height: "100%",
width: "100%",
paddingHorizontal: 12
}}
showsVerticalScrollIndicator={false}
data={[0]}
keyExtractor={() => "mainMenuView"}
renderItem={renderItem}
/>
<View
style={{
paddingHorizontal: 12
}}
>
{subscriptionType === SUBSCRIPTION_STATUS.TRIAL ||
subscriptionType === SUBSCRIPTION_STATUS.BASIC ? (
<MenuItem
testID={pro.name}
key={pro.name}
item={pro}
index={0}
ignore={true}
/>
) : null}
{BottomItemsList.slice(DDS.isLargeTablet() ? 0 : 1, 3).map(
(item, index) => (
<MenuItem
testID={
item.name == "Night mode"
? notesnook.ids.menu.nightmode
: item.name
}
key={item.name}
item={item}
index={index}
ignore={true}
rightBtn={
DDS.isLargeTablet() || item.name === "Notesnook Pro"
? null
: BottomItemsList[0]
}
/>
)
)}
</View>
<View
style={{
width: "100%",
paddingHorizontal: 0
}}
>
<UserStatus noTextMode={noTextMode} />
</View>
</View>
</View>
) : null;
},
() => true
);