mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
mobile: auto update pinned note in notif
This commit is contained in:
@@ -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 { getFormattedDate } from "@notesnook/common";
|
||||
import { EVENTS } from "@notesnook/core/dist/common";
|
||||
import { useThemeEngineStore } from "@notesnook/theme";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
@@ -31,6 +32,7 @@ import {
|
||||
openVault
|
||||
} from "../../../services/event-manager";
|
||||
import Navigation from "../../../services/navigation";
|
||||
import Notifications from "../../../services/notifications";
|
||||
import SettingsService from "../../../services/settings";
|
||||
import { TipManager } from "../../../services/tip-manager";
|
||||
import { useEditorStore } from "../../../stores/use-editor-store";
|
||||
@@ -52,7 +54,6 @@ import {
|
||||
makeSessionId,
|
||||
post
|
||||
} from "./utils";
|
||||
import { getFormattedDate } from "@notesnook/common";
|
||||
|
||||
export const useEditor = (
|
||||
editorId = "",
|
||||
@@ -234,6 +235,10 @@ export const useEditor = (
|
||||
id && useEditorStore.getState().setCurrentlyEditingNote(id);
|
||||
});
|
||||
}
|
||||
|
||||
if (Notifications.isNotePinned(id as string)) {
|
||||
Notifications.pinNote(id as string);
|
||||
}
|
||||
} else {
|
||||
noteData.contentId = note?.contentId;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
||||
@@ -46,6 +46,7 @@ import { useRelationStore } from "../stores/use-relation-store";
|
||||
import { useReminderStore } from "../stores/use-reminder-store";
|
||||
import { presentDialog } from "../components/dialog/functions";
|
||||
import NetInfo from "@react-native-community/netinfo";
|
||||
import { convertNoteToText } from "../utils/note-to-text";
|
||||
|
||||
export type Reminder = {
|
||||
id: string;
|
||||
@@ -757,6 +758,11 @@ function getPinnedNotes(): DisplayedNotification[] {
|
||||
return pinned;
|
||||
}
|
||||
|
||||
function isNotePinned(id: string) {
|
||||
if (Platform.OS !== "android") return false;
|
||||
return pinned.findIndex((notification) => notification.id === id) > -1;
|
||||
}
|
||||
|
||||
function get(): Promise<DisplayedNotification[]> {
|
||||
return new Promise((resolve) => {
|
||||
if (Platform.OS === "ios") resolve([]);
|
||||
@@ -844,6 +850,26 @@ async function setupReminders(checkNeedsScheduling = false) {
|
||||
);
|
||||
}
|
||||
|
||||
async function pinNote(id: string) {
|
||||
try {
|
||||
const note = db.notes?.note(id as string) as any;
|
||||
let text = await convertNoteToText(note as any, false);
|
||||
if (!text) text = "";
|
||||
let html = text.replace(/\n/g, "<br />");
|
||||
Notifications.displayNotification({
|
||||
title: note.title,
|
||||
message: note.headline || text,
|
||||
subtitle: note.headline || text,
|
||||
bigText: html,
|
||||
ongoing: true,
|
||||
actions: ["UNPIN"],
|
||||
id: note.id
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
const Notifications = {
|
||||
init,
|
||||
displayNotification,
|
||||
@@ -859,7 +885,9 @@ const Notifications = {
|
||||
checkAndRequestPermissions,
|
||||
clearAllTriggers,
|
||||
setupReminders,
|
||||
getChannelId
|
||||
getChannelId,
|
||||
isNotePinned,
|
||||
pinNote
|
||||
};
|
||||
|
||||
export default Notifications;
|
||||
|
||||
Reference in New Issue
Block a user