Skip to content

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

mobile: minor fixes

Ammar Ahmed9801d117a16f
diff --git a/apps/mobile/app/components/premium/paywall.tsx b/apps/mobile/app/components/premium/paywall.tsx
index 5d0b60bc4..84f0ff436 100644
--- a/apps/mobile/app/components/premium/paywall.tsx
+++ b/apps/mobile/app/components/premium/paywall.tsx
@@ -64,6 +64,7 @@ import {
TECHLORE_SVG,
XDA_SVG
} from "../../assets/images/assets";
+import { EV, EVENTS, SubscriptionPlan, User } from "@notesnook/core";
const Steps = {
select: 1,
@@ -134,6 +135,23 @@ const PayWall = (props: NavigationProps<"PayWall">) => {
};
}, [isFocused, step]);
+ useEffect(() => {
+ const sub = EV.subscribe(
+ EVENTS.userSubscriptionUpdated,
+ (sub: User["subscription"]) => {
+ if (sub.plan === SubscriptionPlan.FREE) return;
+ if (routeParams.context === "signup") {
+ Navigation.replace("FluidPanelsView", {});
+ } else {
+ Navigation.goBack();
+ }
+ }
+ );
+ return () => {
+ sub?.unsubscribe();
+ };
+ }, []);
+
return (
<SafeAreaView
style={{
diff --git a/apps/mobile/app/components/sheets/export-notes/index.tsx b/apps/mobile/app/components/sheets/export-notes/index.tsx
index ab3206d08..8f151363e 100644
--- a/apps/mobile/app/components/sheets/export-notes/index.tsx
+++ b/apps/mobile/app/components/sheets/export-notes/index.tsx
@@ -78,7 +78,6 @@ const ExportNotesSheet = ({
| undefined
>();
const [status, setStatus] = useState<string>();
- const premium = useUserStore((state) => state.premium);
const exportNoteAs = async (
type: "pdf" | "txt" | "md" | "html" | "md-frontmatter"
@@ -122,8 +121,7 @@ const ExportNotesSheet = ({
await exportNoteAs("pdf");
},
icon: "file-pdf-box",
- id: notesnook.ids.dialogs.export.pdf,
- pro: premium
+ id: notesnook.ids.dialogs.export.pdf
},
{
title: "Markdown",
@@ -131,8 +129,7 @@ const ExportNotesSheet = ({
await exportNoteAs("md");
},
icon: "language-markdown",
- id: notesnook.ids.dialogs.export.md,
- pro: premium
+ id: notesnook.ids.dialogs.export.md
},
{
title: "Markdown + Frontmatter",
@@ -140,8 +137,7 @@ const ExportNotesSheet = ({
await exportNoteAs("md-frontmatter");
},
icon: "language-markdown",
- id: notesnook.ids.dialogs.export.md,
- pro: premium
+ id: notesnook.ids.dialogs.export.md
},
{
title: "Plain Text",
@@ -158,8 +154,7 @@ const ExportNotesSheet = ({
await exportNoteAs("html");
},
icon: "language-html5",
- id: notesnook.ids.dialogs.export.html,
- pro: premium
+ id: notesnook.ids.dialogs.export.html
}
];
@@ -215,9 +210,7 @@ const ExportNotesSheet = ({
>
<Icon
name={item.icon}
- color={
- item.pro ? colors.primary.accent : colors.primary.icon
- }
+ color={colors.primary.icon}
size={AppFontSize.xxxl + 10}
/>
</View>
diff --git a/apps/mobile/app/components/ui/button/index.tsx b/apps/mobile/app/components/ui/button/index.tsx
index e4c0fc29e..cae91d2e8 100644
--- a/apps/mobile/app/components/ui/button/index.tsx
+++ b/apps/mobile/app/components/ui/button/index.tsx
@@ -84,7 +84,6 @@ export const Button = ({
...restProps
}: ButtonProps) => {
const { colors } = useThemeColors();
- const premium = useUserStore((state) => state.premium);
const { text } = useButton({
type,
accent: accentColor,
diff --git a/apps/mobile/app/screens/editor/tiptap/picker.ts b/apps/mobile/app/screens/editor/tiptap/picker.ts
index 654f018e9..93ceb28c2 100644
--- a/apps/mobile/app/screens/editor/tiptap/picker.ts
+++ b/apps/mobile/app/screens/editor/tiptap/picker.ts
@@ -234,25 +234,22 @@ const gallery = async (options: PickerOptions) => {
};
const pick = async (options: PickerOptions) => {
- if (!PremiumService.get()) {
- const user = await db.user.getUser();
- if (!user) {
- ToastManager.show({
- heading: strings.loginRequired(),
- type: "error"
- });
- return;
- }
- if (editorState().isFocused) {
- editorState().isFocused = true;
- }
- if (user && !PremiumService.get() && !user?.isEmailConfirmed) {
- PremiumService.showVerifyEmailDialog();
- } else {
- PremiumService.sheet();
- }
+ const user = await db.user.getUser();
+ if (!user) {
+ ToastManager.show({
+ heading: strings.loginRequired(),
+ type: "error"
+ });
return;
}
+ if (editorState().isFocused) {
+ editorState().isFocused = true;
+ }
+ if (user && !user?.isEmailConfirmed) {
+ PremiumService.showVerifyEmailDialog();
+ return;
+ }
+
useUserStore.getState().setDisableAppLockRequests(true);
if (options?.type.startsWith("image") || options?.type === "camera") {
if (options.type.startsWith("image")) {
diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx b/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx
index 62febf823..fad08947f 100644
--- a/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx
+++ b/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx
@@ -164,7 +164,6 @@ export const useEditorEvents = (
state.timeFormat
]);
const handleBack = useRef<NativeEventSubscription>();
- const isPremium = useUserStore((state) => state.premium);
const { fontScale } = useWindowDimensions();
const doubleSpacedLines = useSettingStore(
@@ -208,7 +207,7 @@ export const useEditorEvents = (
editor.commands.setSettings({
deviceMode: deviceMode || "mobile",
fullscreen: fullscreen || false,
- premium: isPremium,
+ premium: false,
readonly: false,
tools: tools || getDefaultPresets().default,
noHeader: noHeader,
@@ -228,7 +227,6 @@ export const useEditorEvents = (
});
}, [
fullscreen,
- isPremium,
editor.loading,
deviceMode,
tools,
diff --git a/apps/mobile/app/screens/settings/editor/group.tsx b/apps/mobile/app/screens/settings/editor/group.tsx
index baa1d5429..5cd1fcc41 100644
--- a/apps/mobile/app/screens/settings/editor/group.tsx
+++ b/apps/mobile/app/screens/settings/editor/group.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 { useThemeColors } from "@notesnook/theme";
import * as React from "react";
import { View } from "react-native";
import { DraxDragWithReceiverEventData, DraxView } from "react-native-drax";
@@ -24,17 +25,17 @@ import Animated, { Layout } from "react-native-reanimated";
import { presentDialog } from "../../../components/dialog/functions";
import { IconButton } from "../../../components/ui/icon-button";
import Paragraph from "../../../components/ui/typography/paragraph";
-import { useThemeColors } from "@notesnook/theme";
import { getElevationStyle } from "../../../utils/elevation";
import { AppFontSize } from "../../../utils/size";
import { renderTool } from "./common";
import { DraggableItem, useDragState } from "./state";
import ToolSheet from "./tool-sheet";
-import Icon from "react-native-vector-icons/MaterialCommunityIcons";
+import { useIsFeatureAvailable } from "@notesnook/common";
import type { ToolId } from "@notesnook/editor";
-import PremiumService from "../../../services/premium";
import { strings } from "@notesnook/intl";
+import Icon from "react-native-vector-icons/MaterialCommunityIcons";
+import { ToastManager } from "../../../services/event-manager";
import { DefaultAppStyles } from "../../../utils/styles";
export const Group = ({
@@ -61,10 +62,14 @@ export const Group = ({
width: 0
});
const { colors } = useThemeColors();
+ const featureAvailable = useIsFeatureAvailable("customToolbarPreset");
const onDrop = (data: DraxDragWithReceiverEventData) => {
- if (!PremiumService.get()) {
- PremiumService.sheet("global");
+ if (!featureAvailable?.isAllowed) {
+ ToastManager.show({
+ type: "info",
+ message: featureAvailable?.error
+ });
return;
}
const isDroppedAbove = data.receiver.receiveOffsetRatio.y < 0.5;
@@ -127,8 +132,11 @@ export const Group = ({
{
name: "minus",
onPress: () => {
- if (!PremiumService.get()) {
- PremiumService.sheet("global");
+ if (!featureAvailable?.isAllowed) {
+ ToastManager.show({
+ type: "info",
+ message: featureAvailable?.error
+ });
return;
}
presentDialog({
@@ -136,7 +144,7 @@ export const Group = ({
title: strings.deleteGroup(),
positiveText: strings.delete(),
paragraph: strings.deleteGroupDesc(),
- positivePress: () => {
+ positivePress: async () => {
if (groupIndex === undefined) return;
const _data = useDragState.getState().data.slice();
@@ -150,8 +158,11 @@ export const Group = ({
{
name: "plus",
onPress: () => {
- if (!PremiumService.get()) {
- PremiumService.sheet("global");
+ if (!featureAvailable?.isAllowed) {
+ ToastManager.show({
+ type: "info",
+ message: featureAvailable?.error
+ });
return;
}
ToolSheet.present({
diff --git a/apps/mobile/app/screens/settings/editor/tool.tsx b/apps/mobile/app/screens/settings/editor/tool.tsx
index 8b107c91c..7d9e834da 100644
--- a/apps/mobile/app/screens/settings/editor/tool.tsx
+++ b/apps/mobile/app/screens/settings/editor/tool.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 { useThemeColors } from "@notesnook/theme";
import * as React from "react";
import { View } from "react-native";
import { DraxDragWithReceiverEventData, DraxView } from "react-native-drax";
@@ -25,18 +26,18 @@ import { presentDialog } from "../../../components/dialog/functions";
import { IconButton } from "../../../components/ui/icon-button";
import { SvgView } from "../../../components/ui/svg";
import Paragraph from "../../../components/ui/typography/paragraph";
-import { useThemeColors } from "@notesnook/theme";
import { getElevationStyle } from "../../../utils/elevation";
-import { defaultBorderRadius, AppFontSize } from "../../../utils/size";
+import { AppFontSize, defaultBorderRadius } from "../../../utils/size";
import { renderGroup } from "./common";
import { DraggableItem, useDragState } from "./state";
-import { findToolById, getToolIcon } from "./toolbar-definition";
import ToolSheet from "./tool-sheet";
+import { findToolById, getToolIcon } from "./toolbar-definition";
-import Icon from "react-native-vector-icons/MaterialCommunityIcons";
+import { useIsFeatureAvailable } from "@notesnook/common";
import type { ToolId } from "@notesnook/editor";
-import PremiumService from "../../../services/premium";
import { strings } from "@notesnook/intl";
+import Icon from "react-native-vector-icons/MaterialCommunityIcons";
+import { ToastManager } from "../../../services/event-manager";
import { DefaultAppStyles } from "../../../utils/styles";
export const Tool = ({
@@ -70,6 +71,7 @@ export const Tool = ({
isSubgroup || !tool
? null
: getToolIcon(tool.icon as ToolId, colors.secondary.icon);
+ const featureAvailable = useIsFeatureAvailable("customToolbarPreset");
const buttons = React.useCallback(() => {
const btns = isSubgroup
@@ -77,8 +79,11 @@ export const Tool = ({
{
name: "minus",
onPress: () => {
- if (!PremiumService.get()) {
- PremiumService.sheet("global");
+ if (!featureAvailable?.isAllowed) {
+ ToastManager.show({
+ type: "info",
+ message: featureAvailable?.error
+ });
return;
}
presentDialog({
@@ -86,7 +91,7 @@ export const Tool = ({
title: strings.deleteCollapsed(),
positiveText: strings.delete(),
paragraph: strings.deleteCollapsedDesc(),
- positivePress: () => {
+ positivePress: async () => {
if (typeof groupIndex !== "number") return;
const _data = useDragState.getState().data.slice();
_data[groupIndex].splice(index, 1);
@@ -98,8 +103,11 @@ export const Tool = ({
{
name: "plus",
onPress: () => {
- if (!PremiumService.get()) {
- PremiumService.sheet("global");
+ if (!featureAvailable?.isAllowed) {
+ ToastManager.show({
+ type: "info",
+ message: featureAvailable?.error
+ });
return;
}
ToolSheet.present({
@@ -115,8 +123,11 @@ export const Tool = ({
{
name: "minus",
onPress: () => {
- if (!PremiumService.get()) {
- PremiumService.sheet("global");
+ if (!featureAvailable?.isAllowed) {
+ ToastManager.show({
+ type: "info",
+ message: featureAvailable?.error
+ });
return;
}
if (typeof groupIndex !== "number") return;
@@ -280,8 +291,11 @@ export const Tool = ({
);
const onDrop = (data: DraxDragWithReceiverEventData) => {
- if (!PremiumService.get()) {
- PremiumService.sheet("global");
+ if (!featureAvailable?.isAllowed) {
+ ToastManager.show({
+ type: "info",
+ message: featureAvailable?.error
+ });
return;
}
const isDroppedAbove = data.receiver.receiveOffsetRatio.y < 0.5;
diff --git a/apps/mobile/app/services/premium.js b/apps/mobile/app/services/premium.js
index b4a568bd6..8c3fcc1b5 100644
--- a/apps/mobile/app/services/premium.js
+++ b/apps/mobile/app/services/premium.js
@@ -30,7 +30,6 @@ import { eSendEvent, presentSheet, ToastManager } from "./event-manager";
import { strings } from "@notesnook/intl";
import SettingsService from "./settings";
-let premiumStatus = 0;
/**
* @type {RNIap.Subscription[]}
@@ -51,16 +50,12 @@ async function setPremiumStatus() {
try {
user = await db.user.getUser();
if (!user) {
- premiumStatus = 0;
userstore.setPremium(get());
} else {
- premiumStatus = user.subscription?.type || 0;
userstore.setPremium(get());
userstore.setUser(user);
}
- } catch (e) {
- premiumStatus = 0;
- }
+ } catch (e) {}
if (Config.GITHUB_RELEASE === "true") return;
if (get()) {
@@ -72,9 +67,6 @@ async function setPremiumStatus() {
skus: itemSkus
});
} catch (e) {}
- if (premiumStatus === 0 && !__DEV__) {
- SettingsService.reset();
- }
}
function getMontlySub() {
@@ -144,62 +136,6 @@ async function verify(callback, error) {
}
}
-const onUserStatusCheck = async (type) => {
- let user = await db.user.getUser();
- let userstore = useUserStore.getState();
- premiumStatus = user?.subscription?.type || 0;
- if (userstore?.premium !== get()) {
- userstore.setPremium(get());
- }
-
- let status = get();
- let message = null;
- if (!status) {
- switch (type) {
- case CHECK_IDS.noteColor:
- message = {
- context: "sheet",
- title: strings.getNotesnookPro(),
- desc: strings.colorsProMessage()
- };
- break;
- case CHECK_IDS.noteExport:
- message = {
- context: "export",
- title: strings.getNotesnookPro(),
- desc: strings.exportProMessage()
- };
- break;
- case CHECK_IDS.noteTag:
- message = {
- context: "sheet",
- title: strings.getNotesnookPro(),
- desc: strings.tagsProMessage()
- };
- break;
- case CHECK_IDS.notebookAdd:
- message = {
- context: "sheet",
- title: strings.getNotesnookPro(),
- desc: strings.notebookProMessage()
- };
- break;
- case CHECK_IDS.vaultAdd:
- message = {
- context: "sheet",
- title: strings.getNotesnookPro(),
- desc: strings.vaultProMessage()
- };
- break;
- }
-
- if (message) {
- eSendEvent(eShowGetPremium, message);
- }
- }
- return { type, result: status };
-};
-
const showVerifyEmailDialog = () => {
presentSheet({
title: strings.confirmEmail(),
@@ -358,19 +294,15 @@ const subscriptions = {
}
};
-const sheet = (context, promo, trial) => {};
-
const PremiumService = {
verify,
setPremiumStatus,
get,
- onUserStatusCheck,
showVerifyEmailDialog,
loadProductsAndSubs: loadProductsAndSubs,
getUser,
subscriptions,
- getMontlySub,
- sheet
+ getMontlySub
};
export default PremiumService;