Skip to content

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

mobile: add limits to UI

Ammar Ahmed32a7f866c323
diff --git a/apps/mobile/app/common/database/index.ts b/apps/mobile/app/common/database/index.ts
index 6bfca7efc..a968bb88d 100644
--- a/apps/mobile/app/common/database/index.ts
+++ b/apps/mobile/app/common/database/index.ts
@@ -16,7 +16,7 @@ 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 { database, getFeatureLimit } from "@notesnook/common";
+import { database, getFeature, getFeatureLimit } from "@notesnook/common";
import { logger as dbLogger, ICompressor } from "@notesnook/core";
import { strings } from "@notesnook/intl";
import {
@@ -75,7 +75,7 @@ export async function setupDatabase(password?: string) {
password: key
},
maxNoteVersions: async () => {
- const limit = await getFeatureLimit("maxNoteVersions");
+ const limit = await getFeatureLimit(getFeature("maxNoteVersions"));
return typeof limit.caption === "number" ? limit.caption : undefined;
}
});
diff --git a/apps/mobile/app/components/auth/login.js b/apps/mobile/app/components/auth/login.js
index 93e1b09ea..47f88086f 100644
--- a/apps/mobile/app/components/auth/login.js
+++ b/apps/mobile/app/components/auth/login.js
@@ -42,6 +42,7 @@ import { hideAuth } from "./common";
import { ForgotPassword } from "./forgot-password";
import { AuthHeader } from "./header";
import { useLogin } from "./use-login";
+import { useRoute } from "@react-navigation/native";
const LoginSteps = {
emailAuth: 1,
@@ -52,6 +53,7 @@ const LoginSteps = {
export const Login = ({ changeMode }) => {
const { colors } = useThemeColors();
const [focused, setFocused] = useState(false);
+ const route = useRoute();
const {
step,
setStep,
@@ -74,7 +76,8 @@ export const Login = ({ changeMode }) => {
}, 5000);
if (!PremiumService.get()) {
Navigation.navigate("PayWall", {
- context: "logged-in"
+ context: "logged-in",
+ state: route.params.state
});
} else {
Progress.present();
diff --git a/apps/mobile/app/components/auth/signup.js b/apps/mobile/app/components/auth/signup.js
index 6588b1830..05e52a145 100644
--- a/apps/mobile/app/components/auth/signup.js
+++ b/apps/mobile/app/components/auth/signup.js
@@ -26,20 +26,19 @@ import { db } from "../../common/database";
import { DDS } from "../../services/device-detection";
import { ToastManager } from "../../services/event-manager";
import { clearMessage, setEmailVerifyMessage } from "../../services/message";
+import Navigation from "../../services/navigation";
import { useUserStore } from "../../stores/use-user-store";
import { openLinkInBrowser } from "../../utils/functions";
import { AppFontSize } from "../../utils/size";
import { DefaultAppStyles } from "../../utils/styles";
import { Loading } from "../loading";
-import { PaywallComponent } from "../premium/paywall";
import { Button } from "../ui/button";
import Input from "../ui/input";
import Heading from "../ui/typography/heading";
import Paragraph from "../ui/typography/paragraph";
-import { hideAuth } from "./common";
import { AuthHeader } from "./header";
import { SignupContext } from "./signup-context";
-import Navigation from "../../services/navigation";
+import { useRoute } from "@react-navigation/native";
const SignupSteps = {
signup: 0,
@@ -62,6 +61,8 @@ export const Signup = ({ changeMode, welcome }) => {
const setLastSynced = useUserStore((state) => state.setLastSynced);
const { width, height } = useWindowDimensions();
const isTablet = width > 600;
+ const route = useRoute();
+
const validateInfo = () => {
if (!password.current || !email.current || !confirmPassword.current) {
ToastManager.show({
@@ -91,7 +92,8 @@ export const Signup = ({ changeMode, welcome }) => {
clearMessage();
setEmailVerifyMessage();
Navigation.navigate("PayWall", {
- canGoBack: false
+ canGoBack: false,
+ state: route.params.state
});
return true;
} catch (e) {
diff --git a/apps/mobile/app/components/premium/paywall.tsx b/apps/mobile/app/components/premium/paywall.tsx
index 071f02a21..47b9d9c76 100644
--- a/apps/mobile/app/components/premium/paywall.tsx
+++ b/apps/mobile/app/components/premium/paywall.tsx
@@ -29,6 +29,8 @@ import {
TouchableOpacity,
View
} from "react-native";
+import { WebView } from "react-native-webview";
+import Config from "react-native-config";
import * as RNIap from "react-native-iap";
import { SafeAreaView } from "react-native-safe-area-context";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
@@ -40,6 +42,7 @@ import { getElevationStyle } from "../../utils/elevation";
import { openLinkInBrowser } from "../../utils/functions";
import { AppFontSize } from "../../utils/size";
import { DefaultAppStyles } from "../../utils/styles";
+import { AuthMode } from "../auth/common";
import { Header } from "../header";
import { BuyPlan } from "../sheets/buy-plan";
import { Toast } from "../toast";
@@ -47,19 +50,34 @@ import { Button } from "../ui/button";
import Heading from "../ui/typography/heading";
import Paragraph from "../ui/typography/paragraph";
import { FeaturesList } from "./features-list";
+import { db } from "../../common/database";
const Steps = {
select: 1,
buy: 2,
- finish: 3
+ finish: 3,
+ buyWeb: 4
};
const PayWall = (props: NavigationProps<"PayWall">) => {
+ const isGithubRelease = Config.GITHUB_RELEASE === "true";
const routeParams = props.route.params;
+ const [webUrl, setWebUrl] = useState("https://notesnook.com");
const { colors } = useThemeColors();
- const pricingPlans = usePricingPlans();
- const [annualBilling, setAnnualBilling] = useState(true);
- const [step, setStep] = useState(Steps.select);
+ const pricingPlans = usePricingPlans({
+ planId: routeParams.state?.planId,
+ productId: routeParams.state?.productId
+ });
+ const [annualBilling, setAnnualBilling] = useState(
+ routeParams.state ? routeParams.state.billingType === "annual" : true
+ );
+ const [step, setStep] = useState(
+ routeParams.state
+ ? isGithubRelease
+ ? Steps.buyWeb
+ : Steps.buy
+ : Steps.select
+ );
const isFocused = useNavigationFocus(props.navigation, {
onBlur: () => true,
onFocus: () => true
@@ -79,7 +97,7 @@ const PayWall = (props: NavigationProps<"PayWall">) => {
});
}
return () => {
- listener.remove();
+ listener?.remove();
};
}, [isFocused, step]);
@@ -101,7 +119,7 @@ const PayWall = (props: NavigationProps<"PayWall">) => {
props.navigation.goBack();
}}
title={
- step === Steps.buy
+ step === Steps.buy || step === Steps.buyWeb
? pricingPlans.userCanRequestTrial
? `Try ${pricingPlans.currentPlan?.name} plan for free`
: `${pricingPlans.currentPlan?.name} plan`
@@ -467,7 +485,9 @@ After trying all the privacy security oriented note taking apps, for the price a
? "I'll stay on the Free plan"
: pricingPlans.userCanRequestTrial
? `Start ${annualBilling ? "14" : "7"} days free trial`
- : "Subscribe"
+ : pricingPlans.user
+ ? "Subscribe"
+ : "Login to subscribe"
}
onPress={() => {
if (pricingPlans.currentPlan?.id === "free") {
@@ -477,6 +497,23 @@ After trying all the privacy security oriented note taking apps, for the price a
Navigation.goBack();
}
}
+
+ if (!pricingPlans.user) {
+ Navigation.navigate("Auth", {
+ mode: AuthMode.login,
+ state: {
+ planId: pricingPlans.currentPlan?.id,
+ productId: pricingPlans.selectedProduct?.productId,
+ billingType: annualBilling ? "annual" : "monthly"
+ }
+ });
+ return;
+ }
+
+ if (isGithubRelease) {
+ setStep(Steps.buyWeb);
+ }
+
if (
!pricingPlans.currentPlan?.id ||
!pricingPlans.selectedProduct
@@ -503,6 +540,18 @@ After trying all the privacy security oriented note taking apps, for the price a
setStep(Steps.finish);
}}
/>
+ ) : step === Steps.buyWeb ? (
+ <View
+ style={{
+ flex: 1
+ }}
+ >
+ <WebView
+ source={{
+ uri: webUrl
+ }}
+ />
+ </View>
) : (
<View />
)}
@@ -719,6 +768,14 @@ const PricingPlanCard = ({
annualBilling
);
+ console.log("PRODUCT", product?.productId, plan.id);
+
+ const DefaultPricing = {
+ essential: "$2.99",
+ pro: "$5.99",
+ believer: "$6.99"
+ };
+
return (
<TouchableOpacity
activeOpacity={0.9}
@@ -778,10 +835,14 @@ const PricingPlanCard = ({
) : (
<View>
<Paragraph size={AppFontSize.lg}>
- {isFreePlan ? "0.00" : price} <Paragraph>/month</Paragraph>
+ {isFreePlan
+ ? "0.00"
+ : price ||
+ DefaultPricing[plan.id as keyof typeof DefaultPricing]}{" "}
+ <Paragraph>/month</Paragraph>
</Paragraph>
- {isFreePlan ? null : (
+ {isFreePlan || !product ? null : (
<Paragraph color={colors.secondary.paragraph} size={AppFontSize.xs}>
billed {annualBilling ? "annually" : "monthly"} at{" "}
{pricingPlans?.getStandardPrice(product as RNIap.Subscription)}{" "}
diff --git a/apps/mobile/app/components/properties/color-tags.tsx b/apps/mobile/app/components/properties/color-tags.tsx
index 693748097..fe5e8bef6 100644
--- a/apps/mobile/app/components/properties/color-tags.tsx
+++ b/apps/mobile/app/components/properties/color-tags.tsx
@@ -38,7 +38,7 @@ import NativeTooltip from "../../utils/tooltip";
import { Pressable } from "../ui/pressable";
import { strings } from "@notesnook/intl";
import { DefaultAppStyles } from "../../utils/styles";
-import { isFeatureAvailable } from "@notesnook/common";
+import { isFeatureAvailable, useIsFeatureAvailable } from "@notesnook/common";
import PaywallSheet from "../sheets/paywall";
const ColorItem = ({ item, note }: { item: Color; note: Note }) => {
@@ -97,6 +97,7 @@ const ColorItem = ({ item, note }: { item: Color; note: Note }) => {
};
export const ColorTags = ({ item }: { item: Note }) => {
+ const colorFeature = useIsFeatureAvailable("colors");
const { colors } = useThemeColors();
const colorNotes = useMenuStore((state) => state.colorNotes);
const isTablet = useSettingStore((state) => state.deviceMode) !== "mobile";
@@ -112,15 +113,14 @@ export const ColorTags = ({ item }: { item: Note }) => {
);
const onPress = React.useCallback(async () => {
- const colorTagsAvailable = await isFeatureAvailable("colors");
- if (!colorTagsAvailable.isAllowed) {
+ if (colorFeature && !colorFeature.isAllowed) {
ToastManager.show({
- message: colorTagsAvailable.error,
+ message: colorFeature.error,
type: "info",
context: "local",
actionText: strings.upgrade(),
func: () => {
- PaywallSheet.present(colorTagsAvailable);
+ PaywallSheet.present(colorFeature);
ToastManager.hide();
}
});
@@ -187,7 +187,8 @@ export const ColorTags = ({ item }: { item: Note }) => {
borderRadius: 100,
justifyContent: "center",
alignItems: "center",
- marginRight: 5
+ marginRight: 5,
+ opacity: !colorFeature?.isAllowed ? 0.5 : 1
}}
type="secondary"
onPress={onPress}
diff --git a/apps/mobile/app/components/properties/items.tsx b/apps/mobile/app/components/properties/items.tsx
index 36b7c35c5..b28871d59 100644
--- a/apps/mobile/app/components/properties/items.tsx
+++ b/apps/mobile/app/components/properties/items.tsx
@@ -145,7 +145,8 @@ export const Items = ({
key={item.id}
style={{
alignItems: "center",
- width: columnItemWidth - 8
+ width: columnItemWidth - 8,
+ opacity: item.locked ? 0.5 : 1
}}
>
<Pressable
@@ -220,7 +221,8 @@ export const Items = ({
borderRadius: 0,
justifyContent: "flex-start",
alignSelf: "flex-start",
- width: "100%"
+ width: "100%",
+ opacity: item.locked ? 0.5 : 1
}}
/>
),
@@ -244,7 +246,8 @@ export const Items = ({
key={item.id}
testID={"icon-" + item.id}
style={{
- width: columnItemWidth - 8
+ width: columnItemWidth - 8,
+ opacity: item.locked ? 0.5 : 1
}}
>
<View
diff --git a/apps/mobile/app/components/properties/tags.js b/apps/mobile/app/components/properties/tags.js
index 830b2d10a..561e228b6 100644
--- a/apps/mobile/app/components/properties/tags.js
+++ b/apps/mobile/app/components/properties/tags.js
@@ -17,22 +17,21 @@ 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 { strings } from "@notesnook/intl";
+import { useThemeColors } from "@notesnook/theme";
import React, { useEffect, useState } from "react";
import { View } from "react-native";
import { db } from "../../common/database";
+import ManageTags from "../../screens/manage-tags";
import { TaggedNotes } from "../../screens/notes/tagged";
-import { useThemeColors } from "@notesnook/theme";
import { AppFontSize } from "../../utils/size";
+import { DefaultAppStyles } from "../../utils/styles";
import { sleep } from "../../utils/time";
import { Button } from "../ui/button";
import { ColorTags } from "./color-tags";
import { strings } from "@notesnook/intl";
import { DefaultAppStyles } from "../../utils/styles";
import ManageTags from "../../screens/manage-tags";
-import {
- paddingTop,
- paddingVertical
-} from "deprecated-react-native-prop-types/DeprecatedLayoutPropTypes";
export const Tags = ({ item, close }) => {
const { colors } = useThemeColors();
diff --git a/apps/mobile/app/components/sheets/menu-item-properties/index.tsx b/apps/mobile/app/components/sheets/menu-item-properties/index.tsx
index baa65b4b7..88c73678a 100644
--- a/apps/mobile/app/components/sheets/menu-item-properties/index.tsx
+++ b/apps/mobile/app/components/sheets/menu-item-properties/index.tsx
@@ -17,6 +17,7 @@ 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 { useAreFeaturesAvailable } from "@notesnook/common";
import { strings } from "@notesnook/intl";
import { useThemeColors } from "@notesnook/theme";
import React from "react";
@@ -35,11 +36,14 @@ import { useSideBarDraggingStore } from "../../side-menu/dragging-store";
import AppIcon from "../../ui/AppIcon";
import { Pressable } from "../../ui/pressable";
import Paragraph from "../../ui/typography/paragraph";
-import { isFeatureAvailable } from "@notesnook/common";
import PaywallSheet from "../paywall";
export const MenuItemProperties = ({ item }: { item: SideMenuItem }) => {
const { colors } = useThemeColors();
- return (
+ const featuresAvailable = useAreFeaturesAvailable([
+ "customHomepage",
+ "customizableSidebar"
+ ]);
+ return !featuresAvailable ? null : (
<View
style={{
width: "100%",
@@ -51,17 +55,14 @@ export const MenuItemProperties = ({ item }: { item: SideMenuItem }) => {
{
title: strings.setAsHomepage(),
onPress: async () => {
- const customHomepageFeature = await isFeatureAvailable(
- "customHomepage"
- );
- if (!customHomepageFeature.isAllowed) {
+ if (!featuresAvailable?.customHomepage.isAllowed) {
ToastManager.show({
- message: customHomepageFeature.error,
+ message: featuresAvailable?.customHomepage.error,
type: "info",
context: "local",
actionText: strings.upgrade(),
func: () => {
- PaywallSheet.present(customHomepageFeature);
+ PaywallSheet.present(featuresAvailable?.customHomepage);
}
});
return;
@@ -74,22 +75,20 @@ export const MenuItemProperties = ({ item }: { item: SideMenuItem }) => {
},
icon: "home-outline",
type: "switch",
- state: SettingsService.getProperty("homepageV2")?.id === item.id
+ state: SettingsService.getProperty("homepageV2")?.id === item.id,
+ locked: !featuresAvailable?.customHomepage.isAllowed
},
{
title: strings.reorder(),
onPress: async () => {
- const sidebarReorderFeature = await isFeatureAvailable(
- "customizableSidebar"
- );
- if (!sidebarReorderFeature.isAllowed) {
+ if (!featuresAvailable?.customizableSidebar.isAllowed) {
ToastManager.show({
- message: sidebarReorderFeature.error,
+ message: featuresAvailable?.customizableSidebar.error,
type: "info",
context: "local",
actionText: strings.upgrade(),
func: () => {
- PaywallSheet.present(sidebarReorderFeature);
+ PaywallSheet.present(featuresAvailable?.customizableSidebar);
}
});
return;
@@ -99,7 +98,8 @@ export const MenuItemProperties = ({ item }: { item: SideMenuItem }) => {
});
eSendEvent(eCloseSheet);
},
- icon: "sort-ascending"
+ icon: "sort-ascending",
+ locked: !featuresAvailable?.customizableSidebar.isAllowed
}
].map((item) => (
<Pressable
@@ -111,7 +111,8 @@ export const MenuItemProperties = ({ item }: { item: SideMenuItem }) => {
justifyContent: "flex-start",
gap: DefaultAppStyles.GAP_SMALL,
borderRadius: 0,
- paddingHorizontal: DefaultAppStyles.GAP
+ paddingHorizontal: DefaultAppStyles.GAP,
+ opacity: item.locked ? 0.6 : 1
}}
onPress={() => {
item.onPress();
@@ -131,7 +132,14 @@ export const MenuItemProperties = ({ item }: { item: SideMenuItem }) => {
/>
<Paragraph>{item.title}</Paragraph>
</View>
- {item.type === "switch" && item.state ? (
+ {item.locked ? (
+ <AppIcon
+ name="lock"
+ size={AppFontSize.lg}
+ color={colors.primary.icon}
+ style={{ marginLeft: "auto" }}
+ />
+ ) : item.type === "switch" && item.state ? (
<AppIcon
name="check"
size={AppFontSize.lg}
diff --git a/apps/mobile/app/components/sheets/paywall/index.tsx b/apps/mobile/app/components/sheets/paywall/index.tsx
index 3c8da753d..2b99044db 100644
--- a/apps/mobile/app/components/sheets/paywall/index.tsx
+++ b/apps/mobile/app/components/sheets/paywall/index.tsx
@@ -1,27 +1,29 @@
-import { View, Text } from "react-native";
+import { FeatureId, FeatureResult } from "@notesnook/common";
+import { useThemeColors } from "@notesnook/theme";
+import { useEffect, useState } from "react";
+import { View } from "react-native";
+import usePricingPlans from "../../../hooks/use-pricing-plans";
import {
eSendEvent,
presentSheet,
ToastManager
} from "../../../services/event-manager";
-import { FeatureId, FeatureResult } from "@notesnook/common";
-import { useEffect, useState } from "react";
-import usePricingPlans from "../../../hooks/use-pricing-plans";
-import { BuyPlan } from "../buy-plan";
-import Heading from "../../ui/typography/heading";
+import Navigation from "../../../services/navigation";
+import { useUserStore } from "../../../stores/use-user-store";
+import { eCloseSheet } from "../../../utils/events";
import { AppFontSize } from "../../../utils/size";
import { DefaultAppStyles } from "../../../utils/styles";
-import Paragraph from "../../ui/typography/paragraph";
-import { Button } from "../../ui/button";
-import { eCloseSheet } from "../../../utils/events";
-import Navigation from "../../../services/navigation";
-import { useThemeColors } from "@notesnook/theme";
+import { AuthMode } from "../../auth/common";
import AppIcon from "../../ui/AppIcon";
+import { Button } from "../../ui/button";
+import Heading from "../../ui/typography/heading";
+import Paragraph from "../../ui/typography/paragraph";
+import { BuyPlan } from "../buy-plan";
const INDEX_TO_PLAN = {
- 0: "essential",
- 1: "pro",
- 2: "believer"
+ 1: "essential",
+ 2: "pro",
+ 3: "believer"
};
const Steps = {
@@ -186,6 +188,13 @@ export default function PaywallSheet<Tid extends FeatureId>(props: {
width: "100%"
}}
onPress={() => {
+ if (!useUserStore.getState().user) {
+ eSendEvent(eCloseSheet);
+ Navigation.navigate("Auth", {
+ mode: AuthMode.login
+ });
+ return;
+ }
setStep(Steps.Buy);
}}
/>
@@ -199,7 +208,9 @@ export default function PaywallSheet<Tid extends FeatureId>(props: {
onPress={() => {
eSendEvent(eCloseSheet);
Navigation.navigate("PayWall", {
- context: "logged-in"
+ context: useUserStore.getState().user
+ ? "logged-in"
+ : "logged-out"
});
}}
/>
diff --git a/apps/mobile/app/components/side-menu/side-menu-home.tsx b/apps/mobile/app/components/side-menu/side-menu-home.tsx
index c0c06f402..b88aa01a3 100644
--- a/apps/mobile/app/components/side-menu/side-menu-home.tsx
+++ b/apps/mobile/app/components/side-menu/side-menu-home.tsx
@@ -61,6 +61,7 @@ export function SideMenuHome() {
const subscriptionType = useUserStore(
(state) => state.user?.subscription?.type
);
+ const user = useUserStore.getState().user;
return (
<View
@@ -139,7 +140,8 @@ export function SideMenuHome() {
}}
>
{subscriptionType === SUBSCRIPTION_STATUS.TRIAL ||
- subscriptionType === SUBSCRIPTION_STATUS.BASIC ? (
+ subscriptionType === SUBSCRIPTION_STATUS.BASIC ||
+ !user ? (
<Button
title={pro.title}
style={{
diff --git a/apps/mobile/app/hooks/use-actions.tsx b/apps/mobile/app/hooks/use-actions.tsx
index e3e29334b..8f6181bb6 100644
--- a/apps/mobile/app/hooks/use-actions.tsx
+++ b/apps/mobile/app/hooks/use-actions.tsx
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* eslint-disable no-inner-declarations */
-import { isFeatureAvailable } from "@notesnook/common";
+import { useAreFeaturesAvailable } from "@notesnook/common";
import {
createInternalLink,
Item,
@@ -126,6 +126,7 @@ export type Action = {
hidden?: boolean;
activeColor?: string;
type?: ButtonProps["type"];
+ locked?: boolean;
};
function isNotePinnedInNotifications(item: Item) {
@@ -149,6 +150,15 @@ export const useActions = ({
close: () => void;
customActionHandlers?: Record<ActionId, () => void>;
}) => {
+ const features = useAreFeaturesAvailable([
+ "defaultNotebookAndTag",
+ "activeReminders",
+ "pinNoteInNotification",
+ "shortcuts",
+ "notebooks",
+ "customizableSidebar",
+ "customHomepage"
+ ]);
const [item, setItem] = useState(propItem);
const { colors } = useThemeColors();
const setMenuPins = useMenuStore((state) => state.setMenuPins);
@@ -248,15 +258,14 @@ export const useActions = ({
if (isPinnedToMenu) {
await db.shortcuts.remove(item.id);
} else {
- const shortcutsFeature = await isFeatureAvailable("shortcuts");
- if (!shortcutsFeature.isAllowed) {
+ if (features && !features?.shortcuts.isAllowed) {
ToastManager.show({
- message: shortcutsFeature.error,
+ message: features?.shortcuts.error,
type: "info",
context: "local",
actionText: strings.upgrade(),
func: () => {
- PaywallSheet.present(shortcutsFeature);
+ PaywallSheet.present(features?.shortcuts);
}
});
return;
@@ -431,17 +440,14 @@ export const useActions = ({
title: strings.reorder(),
icon: "sort-ascending",
onPress: async () => {
- const sidebarReorderFeature = await isFeatureAvailable(
- "customizableSidebar"
- );
- if (!sidebarReorderFeature.isAllowed) {
+ if (features && !features.customizableSidebar.isAllowed) {
ToastManager.show({
- message: sidebarReorderFeature.error,
+ message: features.customizableSidebar.error,
type: "info",
context: "local",
actionText: strings.upgrade(),
func: () => {
- PaywallSheet.present(sidebarReorderFeature);
+ PaywallSheet.present(features.customizableSidebar);
}
});
return;
@@ -450,7 +456,8 @@ export const useActions = ({
dragging: true
});
close();
- }
+ },
+ locked: !features?.customizableSidebar.isAllowed
});
}
@@ -528,17 +535,14 @@ export const useActions = ({
await db.settings.setDefaultTag(undefined);
setDefaultTag(undefined);
} else {
- const defaultNotebookAndTagFeature = await isFeatureAvailable(
- "defaultNotebookAndTag"
- );
- if (!defaultNotebookAndTagFeature.isAllowed) {
+ if (features && !features.defaultNotebookAndTag.isAllowed) {
ToastManager.show({
- message: defaultNotebookAndTagFeature.error,
+ message: features.defaultNotebookAndTag.error,
type: "info",
context: "local",
actionText: strings.upgrade(),
func: () => {
- PaywallSheet.present(defaultNotebookAndTagFeature);
+ PaywallSheet.present(features.defaultNotebookAndTag);
}
});
return;
@@ -549,7 +553,8 @@ export const useActions = ({
}
close();
},
- checked: defaultTag === item.id
+ checked: defaultTag === item.id,
+ locked: !features?.defaultNotebookAndTag.isAllowed
}
);
}
@@ -561,16 +566,15 @@ export const useActions = ({
title: strings.addNotebook(),
icon: "plus",
onPress: async () => {
- const notebooksFeature = await isFeatureAvailable("notebooks");
- if (!notebooksFeature.isAllowed) {
+ if (features && !features.notebooks.isAllowed) {
ToastManager.show({
- message: notebooksFeature.error,
+ message: features.notebooks.error,
type: "info",
context: "local",
actionText: strings.upgrade(),
func: () => {
ToastManager.hide();
- PaywallSheet.present(notebooksFeature);
+ PaywallSheet.present(features.notebooks);
}
});
return;
@@ -578,7 +582,8 @@ export const useActions = ({
close();
await sleep(300);
AddNotebookSheet.present(undefined, item);
- }
+ },
+ locked: !features?.notebooks.isAllowed
},
{
id: "edit-notebook",
@@ -603,17 +608,14 @@ export const useActions = ({
await db.settings.setDefaultNotebook(undefined);
setDefaultNotebook(undefined);
} else {
- const defaultNotebookAndTagFeature = await isFeatureAvailable(
- "defaultNotebookAndTag"
- );
- if (!defaultNotebookAndTagFeature.isAllowed) {
+ if (features && !features.defaultNotebookAndTag.isAllowed) {
ToastManager.show({
- message: defaultNotebookAndTagFeature.error,
+ message: features.defaultNotebookAndTag.error,
type: "info",
context: "local",
actionText: strings.upgrade(),
func: () => {
- PaywallSheet.present(defaultNotebookAndTagFeature);
+ PaywallSheet.present(features.defaultNotebookAndTag);
}
});
return;
@@ -627,7 +629,9 @@ export const useActions = ({
}
close();
},
- checked: defaultNotebook === item.id
+ checked: defaultNotebook === item.id,
+
+ locked: !features?.defaultNotebookAndTag.isAllowed
},
{
id: "move-notes",
@@ -679,18 +683,14 @@ export const useActions = ({
isToggle: true,
checked: isHomepage,
onPress: async () => {
- const customHomepageFeature = await isFeatureAvailable(
- "customHomepage"
- );
-
- if (!customHomepageFeature.isAllowed) {
+ if (features && !features?.customHomepage.isAllowed) {
ToastManager.show({
- message: customHomepageFeature.error,
+ message: features?.customHomepage.error,
type: "info",
context: "local",
actionText: strings.upgrade(),
func: () => {
- PaywallSheet.present(customHomepageFeature);
+ PaywallSheet.present(features?.customHomepage);
}
});
return;
@@ -777,14 +777,14 @@ export const useActions = ({
}
async function pinToNotifications() {
- const result = await isFeatureAvailable("pinNoteInNotification");
- if (!result.isAllowed) {
+ if (features && !features?.pinNoteInNotification.isAllowed) {
ToastManager.show({
- message: result.error,
+ message: features?.pinNoteInNotification.error,
type: "info",
actionText: strings.upgrade(),
+ context: "local",
func: () => {
- PaywallSheet.present(result);
+ PaywallSheet.present(features?.pinNoteInNotification);
}
});
return;
@@ -1020,16 +1020,13 @@ export const useActions = ({
relationType: "from",
title: strings.dataTypesPluralCamelCase.reminder(),
onAdd: async () => {
- const reminderFeature = await isFeatureAvailable(
- "activeReminders"
- );
- if (!reminderFeature.isAllowed) {
+ if (features && !features.activeReminders.isAllowed) {
ToastManager.show({
type: "info",
- message: reminderFeature.error,
+ message: features.activeReminders.error,
actionText: strings.upgrade(),
func: () => {
- PaywallSheet.present(reminderFeature);
+ PaywallSheet.present(features.activeReminders);
}
});
}
@@ -1039,16 +1036,13 @@ export const useActions = ({
button: {
type: "plain",
onPress: async () => {
- const reminderFeature = await isFeatureAvailable(
- "activeReminders"
- );
- if (!reminderFeature.isAllowed) {
+ if (features && !features.activeReminders.isAllowed) {
ToastManager.show({
type: "info",
- message: reminderFeature.error,
+ message: features.activeReminders.error,
actionText: strings.upgrade(),
func: () => {
- PaywallSheet.present(reminderFeature);
+ PaywallSheet.present(features.activeReminders);
}
});
return;
@@ -1060,7 +1054,8 @@ export const useActions = ({
iconSize: 20
}
});
- }
+ },
+ locked: !features?.activeReminders.isAllowed
},
{
@@ -1172,7 +1167,8 @@ export const useActions = ({
: strings.pinToNotifications(),
icon: "message-badge-outline",
checked: !!notifPinned,
- onPress: pinToNotifications
+ onPress: pinToNotifications,
+ locked: !features?.pinNoteInNotification.isAllowed
});
}
}
diff --git a/apps/mobile/app/hooks/use-feature-manager.ts b/apps/mobile/app/hooks/use-feature-manager.ts
index e0375c655..b0859c7dc 100644
--- a/apps/mobile/app/hooks/use-feature-manager.ts
+++ b/apps/mobile/app/hooks/use-feature-manager.ts
@@ -1,27 +1,73 @@
-import { useIsFeatureAvailable } from "@notesnook/common";
+import { useAreFeaturesAvailable } from "@notesnook/common";
import { strings } from "@notesnook/intl";
import { useEffect } from "react";
+import { db } from "../common/database";
import { presentDialog } from "../components/dialog/functions";
+import { useDragState } from "../screens/settings/editor/state";
import { eSendEvent } from "../services/event-manager";
import Navigation from "../services/navigation";
+import Notifications from "../services/notifications";
import SettingsService from "../services/settings";
import { useUserStore } from "../stores/use-user-store";
import { eCloseSimpleDialog } from "../utils/events";
export default function useFeatureManager() {
- const appLockFeature = useIsFeatureAvailable("appLock");
+ const features = useAreFeaturesAvailable([
+ "appLock",
+ "createNoteFromNotificationDrawer",
+ "pinNoteInNotification",
+ "markdownShortcuts",
+ "customHomepage",
+ "defaultNotebookAndTag",
+ "defaultSidebarTab",
+ "customToolbarPreset",
+ "disableTrashCleanup"
+ ]);
const user = useUserStore((state) => state.user);
useEffect(() => {
- if (!user || appLockFeature?.isAllowed) return;
+ if (!user || !features) return;
+
+ if (!features.createNoteFromNotificationDrawer.isAllowed) {
+ SettingsService.setProperty("notifNotes", false);
+ }
+
+ if (!features.pinNoteInNotification.isAllowed) {
+ Notifications.clearPinnedNotes();
+ }
+
+ if (!features.markdownShortcuts.isAllowed) {
+ SettingsService.setProperty("markdownShortcuts", false);
+ }
+
+ if (!features.customHomepage.isAllowed) {
+ SettingsService.setProperty("homepageV2", undefined);
+ }
+
+ if (!features.defaultSidebarTab.isAllowed) {
+ SettingsService.setProperty("defaultSidebarTab", 0);
+ }
+
+ if (
+ !features.customToolbarPreset.isAllowed &&
+ useDragState.getState().preset === "custom"
+ ) {
+ useDragState.getState().setPreset("default");
+ }
+
+ if (!features.defaultNotebookAndTag.isAllowed) {
+ db.settings.setDefaultNotebook(undefined);
+ db.settings.setDefaultTag(undefined);
+ }
+
const unsub = useUserStore.subscribe((state) => {
- if (!state.appLocked && !appLockFeature?.isAllowed) {
+ if (!state.appLocked && !features?.appLock?.isAllowed) {
unsub();
SettingsService.setProperty("appLockEnabled", false);
setTimeout(() => {
presentDialog({
title: "App Lock Disabled",
- paragraph: appLockFeature?.error,
+ paragraph: features?.appLock?.error,
positiveText: strings.upgrade(),
negativeText: strings.cancel(),
positivePress: async () => {
@@ -37,7 +83,7 @@ export default function useFeatureManager() {
return () => {
unsub();
};
- }, [appLockFeature?.isAllowed]);
+ }, [features]);
return true;
}
diff --git a/apps/mobile/app/screens/settings/section-item.tsx b/apps/mobile/app/screens/settings/section-item.tsx
index 8cde468d7..ca51a7f49 100644
--- a/apps/mobile/app/screens/settings/section-item.tsx
+++ b/apps/mobile/app/screens/settings/section-item.tsx
@@ -27,23 +27,32 @@ import React, { useEffect, useRef, useState } from "react";
import { ActivityIndicator, TextInput, View } from "react-native";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
//@ts-ignore
+import { FeatureResult, useIsFeatureAvailable } from "@notesnook/common";
+import { strings } from "@notesnook/intl";
import ToggleSwitch from "toggle-switch-react-native";
+import PaywallSheet from "../../components/sheets/paywall";
import { IconButton } from "../../components/ui/icon-button";
import Input from "../../components/ui/input";
import { Pressable } from "../../components/ui/pressable";
import Seperator from "../../components/ui/seperator";
+import Heading from "../../components/ui/typography/heading";
import Paragraph from "../../components/ui/typography/paragraph";
+import { ToastManager } from "../../services/event-manager";
import SettingsService from "../../services/settings";
import useNavigationStore from "../../stores/use-navigation-store";
import { SettingStore, useSettingStore } from "../../stores/use-setting-store";
import { AppFontSize } from "../../utils/size";
+import { DefaultAppStyles } from "../../utils/styles";
import { components } from "./components";
import { RouteParams, SettingSection } from "./types";
-import Heading from "../../components/ui/typography/heading";
-import { DefaultAppStyles } from "../../utils/styles";
const _SectionItem = ({ item }: { item: SettingSection }) => {
const { colors } = useThemeColors();
+ const isFeatureAvailable = item.featureId
+ ? useIsFeatureAvailable(item.featureId)
+ : ({
+ isAllowed: true
+ } as FeatureResult);
const [settings, itemProperty] = useSettingStore((state) => [
state.settings,
item.property ? state.settings[item.property] : null
@@ -60,6 +69,8 @@ const _SectionItem = ({ item }: { item: SettingSection }) => {
const [loading, setLoading] = useState(false);
const onChangeSettings = async () => {
+ if (isDisabled) return;
+ if (!checkIsFeatureAvailable()) return;
if (loading) return;
if (item.onVerify && !(await item.onVerify())) return;
if (item.modifer) {
@@ -111,12 +122,33 @@ const _SectionItem = ({ item }: { item: SettingSection }) => {
useEffect(() => {
setIsHidden(item.hidden && item.hidden(item.property || current));
- setIsDisabled(item.disabled && item.disabled(item.property || current));
- }, [current, item, itemProperty]);
+ setIsDisabled(
+ !isFeatureAvailable?.isAllowed ||
+ (item.disabled && item.disabled(item.property || current))
+ );
+ }, [current, item, itemProperty, isFeatureAvailable?.isAllowed]);
+
+ const checkIsFeatureAvailable = React.useCallback(() => {
+ if (!isFeatureAvailable) return false;
+ if (isFeatureAvailable && !isFeatureAvailable?.isAllowed) {
+ ToastManager.show({
+ message: isFeatureAvailable?.error,
+ type: "info",
+ context: "global",
+ actionText: strings.upgrade(),
+ func: () => {
+ PaywallSheet.present(isFeatureAvailable);
+ }
+ });
+ return false;
+ }
+
+ return true;
+ }, [isFeatureAvailable]);
return isHidden ? null : (
<Pressable
- disabled={item.type === "component" || isDisabled}
+ disabled={item.type === "component"}
style={{
width: "100%",
alignItems: "center",
@@ -129,6 +161,7 @@ const _SectionItem = ({ item }: { item: SettingSection }) => {
...styles
}}
onPress={async () => {
+ if (!checkIsFeatureAvailable()) return;
if (isDisabled) return;
switch (item.type) {
case "screen":
@@ -266,6 +299,7 @@ const _SectionItem = ({ item }: { item: SettingSection }) => {
name="minus"
color={colors.primary.icon}
onPress={() => {
+ if (!checkIsFeatureAvailable()) return;
if (isDisabled) return;
const rawValue = SettingsService.get()[
item.property as keyof SettingStore["settings"]
@@ -320,6 +354,7 @@ const _SectionItem = ({ item }: { item: SettingSection }) => {
name="plus"
color={colors.primary.icon}
onPress={() => {
+ if (!checkIsFeatureAvailable()) return;
if (isDisabled) return;
const rawValue = SettingsService.get()[
item.property as keyof SettingStore["settings"]
diff --git a/apps/mobile/app/screens/settings/settings-data.tsx b/apps/mobile/app/screens/settings/settings-data.tsx
index 352ee5b43..b8f779683 100644
--- a/apps/mobile/app/screens/settings/settings-data.tsx
+++ b/apps/mobile/app/screens/settings/settings-data.tsx
@@ -17,7 +17,7 @@ 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 { formatBytes, isFeatureAvailable } from "@notesnook/common";
+import { formatBytes } from "@notesnook/common";
import { User } from "@notesnook/core";
import { strings } from "@notesnook/intl";
import notifee from "@notifee/react-native";
@@ -67,7 +67,6 @@ import { verifyUser, verifyUserWithApplock } from "./functions";
import { logoutUser } from "./logout";
import { SettingSection } from "./types";
import { getTimeLeft } from "./user-section";
-import PaywallSheet from "../../components/sheets/paywall";
export const settingsGroups: SettingSection[] = [
{
@@ -751,24 +750,7 @@ export const settingsGroups: SettingSection[] = [
property: "markdownShortcuts",
description: strings.mardownShortcutsDesc(),
type: "switch",
- onVerify: async () => {
- const markdownShortcuts = await isFeatureAvailable(
- "markdownShortcuts"
- );
-
- if (!markdownShortcuts.isAllowed) {
- ToastManager.show({
- message: markdownShortcuts.error,
- type: "info",
- context: "local",
- actionText: strings.upgrade(),
- func: () => {
- PaywallSheet.present(markdownShortcuts);
- }
- });
- }
- return markdownShortcuts.isAllowed;
- }
+ featureId: "markdownShortcuts"
}
]
},
@@ -945,6 +927,7 @@ export const settingsGroups: SettingSection[] = [
type: "screen",
description: strings.appLockDesc(),
icon: "lock",
+ featureId: "appLock",
sections: [
{
id: "app-lock-mode",
@@ -953,6 +936,7 @@ export const settingsGroups: SettingSection[] = [
icon: "lock",
type: "switch",
property: "appLockEnabled",
+ featureId: "appLock",
onChange: () => {
SettingsService.set({
privacyScreen: true
@@ -960,19 +944,6 @@ export const settingsGroups: SettingSection[] = [
SettingsService.setPrivacyScreen(SettingsService.get());
},
onVerify: async () => {
- const appLockFeature = await isFeatureAvailable("appLock");
- if (!appLockFeature.isAllowed) {
- ToastManager.show({
- message: appLockFeature.error,
- type: "info",
- actionText: strings.upgrade(),
- func: () => {
- PaywallSheet.present(appLockFeature);
- }
- });
- return;
- }
-
const verified = await verifyUserWithApplock();
if (!verified) return false;
@@ -1281,18 +1252,6 @@ export const settingsGroups: SettingSection[] = [
if (settings.notifNotes) {
Notifications.unpinQuickNote();
} else {
- const createNoteFromNotificationDrawerFeature =
- await isFeatureAvailable("createNoteFromNotificationDrawer");
- if (!createNoteFromNotificationDrawerFeature.isAllowed) {
- ToastManager.show({
- message: createNoteFromNotificationDrawerFeature.error,
- type: "info",
- actionText: strings.upgrade(),
- func: () => {
- PaywallSheet.present(createNoteFromNotificationDrawerFeature);
- }
- });
- }
Notifications.pinQuickNote(false);
}
SettingsService.set({
diff --git a/apps/mobile/app/screens/settings/types.ts b/apps/mobile/app/screens/settings/types.ts
index c50840588..e638dd937 100644
--- a/apps/mobile/app/screens/settings/types.ts
+++ b/apps/mobile/app/screens/settings/types.ts
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { TextInput } from "react-native";
import { Settings } from "../../stores/use-setting-store";
+import { FeatureId } from "@notesnook/common";
export type SettingSection = {
id: string;
@@ -48,6 +49,7 @@ export type SettingSection = {
onVerify?: () => Promise<boolean>;
hideHeader?: boolean;
disabled?: (current: unknown) => boolean;
+ featureId?: FeatureId;
};
export type SettingsGroup = {
diff --git a/apps/mobile/app/services/notifications.ts b/apps/mobile/app/services/notifications.ts
index 2bda9fb99..99628386d 100644
--- a/apps/mobile/app/services/notifications.ts
+++ b/apps/mobile/app/services/notifications.ts
@@ -1045,6 +1045,13 @@ async function restorePinnedNotes() {
}
}
+async function clearPinnedNotes() {
+ const pinnedNotes = PinnedNotesStorage.get();
+ for (const id of pinnedNotes) {
+ remove(id);
+ }
+}
+
const Events = {
onUpdate: "onUpdate"
};
@@ -1054,6 +1061,7 @@ const Notifications = {
displayNotification,
clearAll,
remove,
+ clearPinnedNotes,
get,
getPinnedNotes,
pinQuickNote,
diff --git a/apps/mobile/app/stores/use-navigation-store.ts b/apps/mobile/app/stores/use-navigation-store.ts
index 6e9fd618f..9585f9b7f 100644
--- a/apps/mobile/app/stores/use-navigation-store.ts
+++ b/apps/mobile/app/stores/use-navigation-store.ts
@@ -55,6 +55,13 @@ export type AppLockRouteParams = {
export type AuthParams = {
mode: number;
context?: "intro";
+ state?: BillingState;
+};
+
+export type BillingState = {
+ productId?: string;
+ planId?: string;
+ billingType?: "annual" | "monthly";
};
export interface RouteParams extends ParamListBase {
@@ -105,6 +112,7 @@ export interface RouteParams extends ParamListBase {
PayWall: {
canGoBack?: boolean;
context: "signup" | "logged-in" | "logged-out";
+ state?: BillingState;
};
}