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
mobile: refactor
ammarahm-ed8548940cb9ec
diff --git a/apps/mobile/app/components/attachments/attachment-item.js b/apps/mobile/app/components/attachments/attachment-item.jsindex 8a5a12de5..c32286f9f 100644--- a/apps/mobile/app/components/attachments/attachment-item.js+++ b/apps/mobile/app/components/attachments/attachment-item.js@@ -36,7 +36,11 @@ function getFileExtension(filename) {var ext = /^.+\.([^.]+)$/.exec(filename);return ext == null ? "" : ext[1];}-+/**+ *+ * @param {any} param0+ * @returns+ */export const AttachmentItem = ({ attachment, encryption, setAttachments }) => {const colors = useThemeStore((state) => state.colors);const [currentProgress, setCurrentProgress] = useAttachmentProgress(diff --git a/apps/mobile/app/hooks/use-attachment-progress.js b/apps/mobile/app/hooks/use-attachment-progress.tssimilarity index 54%rename from apps/mobile/app/hooks/use-attachment-progress.jsrename to apps/mobile/app/hooks/use-attachment-progress.tsindex 39d807925..a47bbfad5 100644--- a/apps/mobile/app/hooks/use-attachment-progress.js+++ b/apps/mobile/app/hooks/use-attachment-progress.ts@@ -17,35 +17,46 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { useEffect, useState } from "react";+import { useState } from "react";import { useAttachmentStore } from "../stores/use-attachment-store";-export const useAttachmentProgress = (attachment, encryption) => {+type AttachmentProgress = {+ type: string;+ value?: number;+ percent?: string;+};++export const useAttachmentProgress = (+ attachment: any,+ encryption?: boolean+) => {const progress = useAttachmentStore((state) => state.progress);- const [currentProgress, setCurrentProgress] = useState(+ const [currentProgress, setCurrentProgress] = useState<+ AttachmentProgress | undefined+ >(encryption? {type: "encrypt"}- : null+ : undefined);- useEffect(() => {- let prog = progress[attachment.metadata.hash];- if (prog) {- let type = prog.type;- let loaded = prog.type === "download" ? prog.recieved : prog.sent;- prog = loaded / prog.total;- prog = (prog * 100).toFixed(0);- setCurrentProgress({- value: prog,- percent: prog + "%",- type: type- });- } else {- setCurrentProgress(null);- }- }, [attachment.metadata.hash, progress]);+ const attachmentProgress = progress?.[attachment.metadata.hash];+ if (attachmentProgress) {+ const type = attachmentProgress.type;+ const loaded =+ attachmentProgress.type === "download"+ ? attachmentProgress.recieved+ : attachmentProgress.sent;+ const value = loaded / attachmentProgress.total;+ setCurrentProgress({+ value: value * 100,+ percent: (value * 100).toFixed(0) + "%",+ type: type+ });+ } else {+ setCurrentProgress(undefined);+ }return [currentProgress, setCurrentProgress];};diff --git a/apps/mobile/app/hooks/use-vault-status.js b/apps/mobile/app/hooks/use-vault-status.jsdeleted file mode 100644index 1a867c8e5..000000000--- a/apps/mobile/app/hooks/use-vault-status.js+++ /dev/null@@ -1,61 +0,0 @@-/*-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, useEffect } from "react";-import BiometicService from "../services/biometrics";-import { eSubscribeEvent, eUnSubscribeEvent } from "../services/event-manager";-import { db } from "../common/database";--const VaultStatusCache = {- exists: false,- biometryEnrolled: false,- isBiometryAvailable: false-};--export const useVaultStatus = () => {- const [vaultStatus, setVaultStatus] = React.useState(VaultStatusCache);-- const checkVaultStatus = useCallback(() => {- db.vault.exists().then(async (exists) => {- let available = await BiometicService.isBiometryAvailable();- let fingerprint = await BiometicService.hasInternetCredentials();- if (- VaultStatusCache.exists === exists &&- VaultStatusCache.biometryEnrolled === fingerprint &&- VaultStatusCache.isBiometryAvailable === available- )- return;- setVaultStatus({- exists: exists,- biometryEnrolled: fingerprint,- isBiometryAvailable: available ? true : false- });- });- }, []);-- useEffect(() => {- checkVaultStatus();- eSubscribeEvent("vaultUpdated", () => checkVaultStatus());- return () => {- eUnSubscribeEvent("vaultUpdated", () => checkVaultStatus());- };- }, [checkVaultStatus]);-- return vaultStatus;-};diff --git a/apps/mobile/app/services/sync.js b/apps/mobile/app/services/sync.jsindex a6baf0e4c..6ef5642f4 100644--- a/apps/mobile/app/services/sync.js+++ b/apps/mobile/app/services/sync.js@@ -27,14 +27,6 @@ import { DatabaseLogger } from "../common/database/index";import { ToastEvent } from "./event-manager";import SettingsService from "./settings";-NetInfo.configure({- reachabilityUrl: "https://notesnook.com",- reachabilityTest: (response) => {- if (!response) return false;- return response?.status >= 200 && response?.status < 300;- }-});-export const ignoredMessages = ["Sync already running","Not allowed to start service intent",diff --git a/apps/mobile/app/stores/use-message-store.ts b/apps/mobile/app/stores/use-message-store.tsindex 26043701c..3d3fa727f 100644--- a/apps/mobile/app/stores/use-message-store.ts+++ b/apps/mobile/app/stores/use-message-store.ts@@ -24,7 +24,6 @@ import { db } from "../common/database";import { MMKV } from "../common/database/mmkv";import PremiumService from "../services/premium";import { SUBSCRIPTION_STATUS } from "../utils/constants";-import layoutmanager from "../utils/layout-manager";export interface MessageStore extends State {message: Message;setMessage: (message: Message) => void;@@ -96,13 +95,7 @@ export const useMessageStore = create<MessageStore>((set, get) => ({icon: "account-outline"},setMessage: (message) => {- setTimeout(() => {- if (get().message.visible || message.visible) {- layoutmanager.withAnimation();- }-- set({ message: { ...message } });- }, 1);+ set({ message: { ...message } });},announcements: [],remove: async (id) => {diff --git a/apps/mobile/app/utils/layout-manager.js b/apps/mobile/app/utils/layout-manager.jsdeleted file mode 100644index adb142615..000000000--- a/apps/mobile/app/utils/layout-manager.js+++ /dev/null@@ -1,31 +0,0 @@-/*-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/>.-*/--function withAnimation(_duration = 300) {- return;-}--function withSpringAnimation(_duration = 300) {- return;-}--export default {- withAnimation,- withSpringAnimation-};diff --git a/apps/mobile/app/utils/sanitizer/index.js b/apps/mobile/app/utils/sanitizer/index.tssimilarity index 83%rename from apps/mobile/app/utils/sanitizer/index.jsrename to apps/mobile/app/utils/sanitizer/index.tsindex 02836238f..311540a1c 100644--- a/apps/mobile/app/utils/sanitizer/index.js+++ b/apps/mobile/app/utils/sanitizer/index.ts@@ -46,18 +46,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.* @return {String} Sanitized filename*/-var illegalRe = /[/?<>\\:*|"]/g;+const illegalRe = /[/?<>\\:*|"]/g;//var controlRe = /[x00-x1f\x80-\x9f]/g;-var reservedRe = /^\.+$/;-var windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;-var windowsTrailingRe = /[. ]+$/;-var whitespace = /\s+/g;+const reservedRe = /^\.+$/;+const windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;+const windowsTrailingRe = /[. ]+$/;+const whitespace = /\s+/g;-function sanitize(input, replacement) {+function sanitize(input: string, replacement: string) {if (typeof input !== "string") {throw new Error("Input must be string");}- var sanitized = input+ const sanitized = input.replace(whitespace, replacement).replace(illegalRe, replacement).replace(reservedRe, replacement)@@ -67,7 +67,10 @@ function sanitize(input, replacement) {return sanitized.slice(0, 254).toLowerCase();}-export function sanitizeFilename(input, options) {- var replacement = (options && options.replacement) || "";+export function sanitizeFilename(+ input: string,+ options: { replacement: string }+) {+ const replacement = (options && options.replacement) || "";return sanitize(input, replacement);}