Files
notesnook/apps/mobile/app/screens/notes/topic-notes.tsx

82 lines
2.1 KiB
TypeScript
Raw Normal View History

import { groupArray } from "@notesnook/core/utils/grouping";
2022-08-29 16:19:17 +05:00
import React from "react";
import NotesPage, { PLACEHOLDER_DATA } from ".";
2022-08-29 16:19:17 +05:00
import { db } from "../../common/database";
import { MoveNotes } from "../../components/sheets/move-notes/movenote";
import { eSendEvent } from "../../services/event-manager";
import Navigation, {
NavigationProps,
NotesScreenParams
} from "../../services/navigation";
import { eOpenAddTopicDialog } from "../../utils/events";
2022-08-30 13:30:11 +05:00
import { NotebookType, TopicType } from "../../utils/types";
import { openEditor } from "./common";
2022-04-24 05:59:14 +05:00
const headerRightButtons = (params: NotesScreenParams) => [
{
title: "Edit topic",
2022-04-24 05:59:14 +05:00
onPress: () => {
const { item } = params;
if (item.type !== "topic") return;
2022-04-24 05:59:14 +05:00
eSendEvent(eOpenAddTopicDialog, {
notebookId: item.notebookId,
toEdit: item
});
}
},
{
title: "Move notes",
2022-04-24 05:59:14 +05:00
onPress: () => {
const { item } = params;
if (item?.type !== "topic") return;
2022-08-30 13:30:11 +05:00
MoveNotes.present(
db.notebooks?.notebook(item.notebookId).data as NotebookType,
item
);
2022-04-24 05:59:14 +05:00
}
}
];
export const TopicNotes = ({
navigation,
route
}: NavigationProps<"TopicNotes">) => {
2022-04-24 05:59:14 +05:00
return (
<NotesPage
navigation={navigation}
route={route}
get={TopicNotes.get}
placeholderData={PLACEHOLDER_DATA}
onPressFloatingButton={openEditor}
rightButtons={headerRightButtons}
canGoBack={route.params.canGoBack}
focusControl={true}
/>
);
};
2022-04-25 00:37:09 +05:00
TopicNotes.get = (params: NotesScreenParams, grouped = true) => {
2022-08-30 13:30:11 +05:00
const { id, notebookId } = params.item as TopicType;
const notes = db.notebooks?.notebook(notebookId)?.topics.topic(id)?.all || [];
return grouped
? groupArray(notes, db.settings?.getGroupOptions("notes"))
: notes;
2022-04-24 05:59:14 +05:00
};
TopicNotes.navigate = (item: TopicType, canGoBack: boolean) => {
if (!item) return;
Navigation.navigate<"TopicNotes">(
2022-04-24 05:59:14 +05:00
{
name: "TopicNotes",
2022-04-24 05:59:14 +05:00
title: item.title,
id: item.id,
type: "topic",
2022-04-24 05:59:14 +05:00
notebookId: item.notebookId
},
{
item: item,
canGoBack,
title: item.title
}
);
};