mirror of
https://github.com/standardnotes/mobile.git
synced 2026-05-18 19:44:31 -04:00
feat: add listed actions
This commit is contained in:
@@ -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];
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user