mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-17 04:07:51 +01:00
71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
|
|
import { groupArray } from 'notes-core/utils/grouping';
|
||
|
|
import React from 'react';
|
||
|
|
import NotesPage, { PLACEHOLDER_DATA } from '.';
|
||
|
|
import { MoveNotes } from '../../components/sheets/move-notes/movenote';
|
||
|
|
import { eSendEvent } from '../../services/event-manager';
|
||
|
|
import Navigation, { NavigationProps, NotesScreenParams } from '../../services/navigation';
|
||
|
|
import { db } from '../../utils/database';
|
||
|
|
import { eOpenAddTopicDialog } from '../../utils/events';
|
||
|
|
import { TopicType } from '../../utils/types';
|
||
|
|
import { openEditor } from './common';
|
||
|
|
|
||
|
|
const headerRightButtons = (params: NotesScreenParams) => [
|
||
|
|
{
|
||
|
|
title: 'Edit topic',
|
||
|
|
onPress: () => {
|
||
|
|
const { item } = params;
|
||
|
|
if (item.type !== 'topic') return;
|
||
|
|
eSendEvent(eOpenAddTopicDialog, {
|
||
|
|
notebookId: item.notebookId,
|
||
|
|
toEdit: item
|
||
|
|
});
|
||
|
|
}
|
||
|
|
},
|
||
|
|
{
|
||
|
|
title: 'Move notes',
|
||
|
|
onPress: () => {
|
||
|
|
const { item } = params;
|
||
|
|
if (item?.type !== 'topic') return;
|
||
|
|
MoveNotes.present(db.notebooks?.notebook(item.notebookId).data, item);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
];
|
||
|
|
|
||
|
|
export const TopicNotes = ({ navigation, route }: NavigationProps<'TopicNotes'>) => {
|
||
|
|
return (
|
||
|
|
<NotesPage
|
||
|
|
navigation={navigation}
|
||
|
|
route={route}
|
||
|
|
get={TopicNotes.get}
|
||
|
|
placeholderData={PLACEHOLDER_DATA}
|
||
|
|
onPressFloatingButton={openEditor}
|
||
|
|
rightButtons={headerRightButtons}
|
||
|
|
canGoBack={route.params.canGoBack}
|
||
|
|
focusControl={true}
|
||
|
|
/>
|
||
|
|
);
|
||
|
|
};
|
||
|
|
|
||
|
|
TopicNotes.get = (id: string, grouped = true) => {
|
||
|
|
let notes = db.notes?.tagged(id) || [];
|
||
|
|
return grouped ? groupArray(notes, db.settings?.getGroupOptions('notes')) : notes;
|
||
|
|
};
|
||
|
|
|
||
|
|
TopicNotes.navigate = (item: TopicType, canGoBack: boolean) => {
|
||
|
|
if (!item) return;
|
||
|
|
Navigation.navigate<'TopicNotes'>(
|
||
|
|
{
|
||
|
|
name: 'TopicNotes',
|
||
|
|
title: item.title,
|
||
|
|
id: item.id,
|
||
|
|
type: 'topic',
|
||
|
|
notebookId: item.notebookId
|
||
|
|
},
|
||
|
|
{
|
||
|
|
item: item,
|
||
|
|
canGoBack,
|
||
|
|
title: item.title
|
||
|
|
}
|
||
|
|
);
|
||
|
|
};
|