feat: add listed actions

This commit is contained in:
Antonella Sgarlatta
2021-04-16 18:07:38 -03:00
parent f7c32f8c81
commit 545eb46b15
3 changed files with 51 additions and 5 deletions

View File

@@ -503,3 +503,22 @@ export const useProtectOrUnprotectNote = (
return [protectOrUnprotectNote];
};
export const useListedExtensions = (note: SNNote) => {
const LISTED_IDENTIFIER = 'org.standardnotes.listed';
// Context
const application = React.useContext(ApplicationContext);
const getListedExtensions = useCallback(() => {
return application?.actionsManager
.getExtensions()
.filter(
extension => extension.package_info?.identifier === LISTED_IDENTIFIER
)
.map(extension => ({
name: extension.name,
actions: extension.actionsWithContextForItem(note),
}));
}, [application, note]);
return [getListedExtensions];
};

View File

@@ -37,7 +37,7 @@ export const NoteCell = ({
}: Props) => {
// State
const [selected, setSelected] = useState(false);
const actionSections = useNoteActionSections(note);
const getActionSections = useNoteActionSections(note);
// Ref
const selectionTimeout = useRef<number>();
@@ -89,8 +89,9 @@ export const NoteCell = ({
bottomSheetSections = [noteProtectedSection];
} else {
bottomSheetSections = [
actionSections[ActionSection.History],
actionSections[ActionSection.CommonActions],
...getActionSections(ActionSection.History),
...getActionSections(ActionSection.CommonActions),
...getActionSections(ActionSection.Listed),
];
}
onLongPressItem(bottomSheetTitle, bottomSheetSections);

View File

@@ -4,13 +4,14 @@ import { Editor } from '@Lib/editor';
import {
useChangeNote,
useDeleteNoteWithPrivileges,
useListedExtensions,
useProtectOrUnprotectNote,
} from '@Lib/snjs_helper_hooks';
import { useNavigation } from '@react-navigation/native';
import { ApplicationContext } from '@Root/ApplicationContext';
import { SCREEN_NOTE_HISTORY } from '@Screens/screens';
import { SNNote } from '@standardnotes/snjs/dist/@types';
import { useContext } from 'react';
import { useCallback, useContext } from 'react';
import { Share } from 'react-native';
// eslint-disable-next-line no-shadow
@@ -50,8 +51,24 @@ export const useNoteActionSections = (note: SNNote, editor?: Editor) => {
},
editor
);
const [getListedExtensions] = useListedExtensions(note);
const navigation = useNavigation();
const getlistedSections = useCallback(
() =>
(getListedExtensions() || []).map((extension, index) => ({
key: `${extension.name}-${index}-section`,
actions: [
{
text: `${extension.name} actions`,
key: `${extension.name}-${index}-section`,
iconType: IconType.Listed,
},
],
})),
[getListedExtensions]
);
const sections: Record<string, BottomSheetSectionType> = {
[ActionSection.History]: {
key: ActionSection.History,
@@ -163,5 +180,14 @@ export const useNoteActionSections = (note: SNNote, editor?: Editor) => {
});
}
return sections;
const getActionSections = (sectionType: ActionSection) => {
switch (sectionType) {
case ActionSection.Listed:
return getlistedSections();
default:
return [sections[sectionType]];
}
};
return getActionSections;
};