2022-08-30 09:59:53 +05:00
|
|
|
import { groupArray } from "@notesnook/core/utils/grouping";
|
2022-08-29 16:19:17 +05:00
|
|
|
import React from "react";
|
2022-08-26 16:19:39 +05:00
|
|
|
import NotesPage, { PLACEHOLDER_DATA } from ".";
|
2022-08-29 16:19:17 +05:00
|
|
|
import { db } from "../../common/database";
|
2022-08-26 16:19:39 +05:00
|
|
|
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";
|
2022-08-26 16:19:39 +05:00
|
|
|
import { openEditor } from "./common";
|
2022-04-24 05:59:14 +05:00
|
|
|
const headerRightButtons = (params: NotesScreenParams) => [
|
|
|
|
|
{
|
2022-08-26 16:19:39 +05:00
|
|
|
title: "Edit topic",
|
2022-04-24 05:59:14 +05:00
|
|
|
onPress: () => {
|
|
|
|
|
const { item } = params;
|
2022-08-26 16:19:39 +05:00
|
|
|
if (item.type !== "topic") return;
|
2022-04-24 05:59:14 +05:00
|
|
|
eSendEvent(eOpenAddTopicDialog, {
|
|
|
|
|
notebookId: item.notebookId,
|
|
|
|
|
toEdit: item
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-08-26 16:19:39 +05:00
|
|
|
title: "Move notes",
|
2022-04-24 05:59:14 +05:00
|
|
|
onPress: () => {
|
|
|
|
|
const { item } = params;
|
2022-08-26 16:19:39 +05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
2022-08-26 16:19:39 +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;
|
2022-08-27 15:23:11 +05:00
|
|
|
const notes = db.notebooks?.notebook(notebookId)?.topics.topic(id)?.all || [];
|
2022-08-26 16:19:39 +05:00
|
|
|
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;
|
2022-08-26 16:19:39 +05:00
|
|
|
Navigation.navigate<"TopicNotes">(
|
2022-04-24 05:59:14 +05:00
|
|
|
{
|
2022-08-26 16:19:39 +05:00
|
|
|
name: "TopicNotes",
|
2022-04-24 05:59:14 +05:00
|
|
|
title: item.title,
|
|
|
|
|
id: item.id,
|
2022-08-26 16:19:39 +05:00
|
|
|
type: "topic",
|
2022-04-24 05:59:14 +05:00
|
|
|
notebookId: item.notebookId
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
item: item,
|
|
|
|
|
canGoBack,
|
|
|
|
|
title: item.title
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|