mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
add support for pinning items to menu
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
import React, {useEffect, useState} from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
ActivityIndicator,
|
||||
Clipboard,
|
||||
Dimensions,
|
||||
StatusBar,
|
||||
Text,
|
||||
|
||||
|
||||
TouchableOpacity,
|
||||
View,
|
||||
View
|
||||
} from 'react-native';
|
||||
import Share from 'react-native-share';
|
||||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||
import {useTracked} from '../../provider';
|
||||
import {Actions} from '../../provider/Actions';
|
||||
import {DDS} from '../../services/DeviceDetection';
|
||||
import { useTracked } from '../../provider';
|
||||
import { Actions } from '../../provider/Actions';
|
||||
import { DDS } from '../../services/DeviceDetection';
|
||||
import {
|
||||
eSendEvent,
|
||||
openVault,
|
||||
sendNoteEditedEvent,
|
||||
ToastEvent,
|
||||
ToastEvent
|
||||
} from '../../services/EventManager';
|
||||
import PremiumService from '../../services/PremiumService';
|
||||
import {
|
||||
@@ -25,27 +25,25 @@ import {
|
||||
COLOR_SCHEME,
|
||||
COLOR_SCHEME_DARK,
|
||||
COLOR_SCHEME_LIGHT,
|
||||
setColorScheme,
|
||||
setColorScheme
|
||||
} from '../../utils/Colors';
|
||||
import {db} from '../../utils/DB';
|
||||
import { db } from '../../utils/DB';
|
||||
import {
|
||||
eOpenLoginDialog,
|
||||
eOpenMoveNoteDialog,
|
||||
eShowGetPremium,
|
||||
eShowGetPremium
|
||||
} from '../../utils/Events';
|
||||
import {deleteItems} from '../../utils/functions';
|
||||
import {MMKV} from '../../utils/mmkv';
|
||||
import {opacity, ph, pv, SIZE, WEIGHT} from '../../utils/SizeUtils';
|
||||
import {sleep, timeConverter} from '../../utils/TimeUtils';
|
||||
import {Button} from '../Button';
|
||||
import {PremiumTag} from '../Premium/PremiumTag';
|
||||
import {PressableButton} from '../PressableButton';
|
||||
import {Toast} from '../Toast';
|
||||
import { deleteItems } from '../../utils/functions';
|
||||
import { MMKV } from '../../utils/mmkv';
|
||||
import { opacity, ph, pv, SIZE } from '../../utils/SizeUtils';
|
||||
import { timeConverter } from '../../utils/TimeUtils';
|
||||
import { PremiumTag } from '../Premium/PremiumTag';
|
||||
import { PressableButton } from '../PressableButton';
|
||||
import { Toast } from '../Toast';
|
||||
import Heading from '../Typography/Heading';
|
||||
import Paragraph from '../Typography/Paragraph';
|
||||
import {ActionSheetColorsSection} from './ActionSheetColorsSection';
|
||||
import {ActionSheetTagsSection} from './ActionSheetTagsSection';
|
||||
import {GetPremium} from './GetPremium';
|
||||
import { ActionSheetColorsSection } from './ActionSheetColorsSection';
|
||||
import { ActionSheetTagsSection } from './ActionSheetTagsSection';
|
||||
const w = Dimensions.get('window').width;
|
||||
|
||||
export const ActionSheetComponent = ({
|
||||
@@ -59,6 +57,8 @@ export const ActionSheetComponent = ({
|
||||
const [state, dispatch] = useTracked();
|
||||
const {colors, premiumUser, user} = state;
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [isPinnedToMenu, setIsPinnedToMenu] = useState(false);
|
||||
|
||||
const [note, setNote] = useState(
|
||||
item
|
||||
? item
|
||||
@@ -84,6 +84,11 @@ export const ActionSheetComponent = ({
|
||||
useEffect(() => {
|
||||
if (item.dateCreated !== null) {
|
||||
setNote({...item});
|
||||
if (item.type !== note) {
|
||||
setIsPinnedToMenu(
|
||||
db.settings.pins.findIndex((i) => i.id === item.id) > -1,
|
||||
);
|
||||
}
|
||||
}
|
||||
}, [item]);
|
||||
|
||||
@@ -313,6 +318,34 @@ export const ActionSheetComponent = ({
|
||||
check: true,
|
||||
on: note.favorite,
|
||||
},
|
||||
{
|
||||
name: isPinnedToMenu ? 'Unpin from Menu' : 'Pin to Menu',
|
||||
icon: 'tag-outline',
|
||||
func: async () => {
|
||||
try {
|
||||
if (isPinnedToMenu) {
|
||||
await db.settings.unpin(note.id);
|
||||
} else {
|
||||
if (item.type === 'notebook') {
|
||||
await db.settings.pin(note.type, {id: note.id});
|
||||
} else if (item.type === 'topic') {
|
||||
await db.settings.pin(note.type, {
|
||||
id: note.notebookId,
|
||||
topic: note.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setIsPinnedToMenu(
|
||||
db.settings.pins.findIndex((i) => i.id === item.id) > -1,
|
||||
);
|
||||
dispatch({type:Actions.MENU_PINS})
|
||||
} catch (e) {}
|
||||
},
|
||||
close: false,
|
||||
check: true,
|
||||
on: isPinnedToMenu,
|
||||
},
|
||||
];
|
||||
|
||||
const _renderRowItem = (rowItem) =>
|
||||
|
||||
Reference in New Issue
Block a user