2022-01-07 13:05:24 +05:00
|
|
|
import React from 'react';
|
2022-01-22 12:57:05 +05:00
|
|
|
import { Platform, ScrollView, View } from 'react-native';
|
|
|
|
|
import { useTracked } from '../../provider';
|
|
|
|
|
import { DDS } from '../../services/DeviceDetection';
|
|
|
|
|
import { presentSheet } from '../../services/EventManager';
|
|
|
|
|
import { db } from '../../utils/database';
|
|
|
|
|
import { SIZE } from '../../utils/SizeUtils';
|
2020-11-09 20:26:20 +05:00
|
|
|
import Heading from '../Typography/Heading';
|
|
|
|
|
import Paragraph from '../Typography/Paragraph';
|
2022-01-22 12:57:05 +05:00
|
|
|
import { ColorTags } from './color-tags';
|
|
|
|
|
import { DateMeta } from './date-meta';
|
|
|
|
|
import { DevMode } from './dev-mode';
|
|
|
|
|
import { Items } from './items';
|
2021-12-27 18:09:00 +05:00
|
|
|
import Notebooks from './notebooks';
|
2022-01-22 12:57:05 +05:00
|
|
|
import { Synced } from './synced';
|
|
|
|
|
import { Tags } from './tags';
|
|
|
|
|
import { Topics } from './topics';
|
2020-10-31 16:32:21 +05:00
|
|
|
|
2022-01-22 12:57:05 +05:00
|
|
|
export const Properties = ({ close = () => {}, item, buttons = [], getRef }) => {
|
2020-01-17 21:26:01 +05:00
|
|
|
const [state, dispatch] = useTracked();
|
2022-01-22 12:57:05 +05:00
|
|
|
const { colors } = state;
|
2021-07-10 00:22:51 +05:00
|
|
|
|
2022-01-08 12:41:56 +05:00
|
|
|
const alias = item
|
|
|
|
|
? item.type === 'tag'
|
2022-01-07 13:05:24 +05:00
|
|
|
? db.tags.alias(item.id)
|
|
|
|
|
: item.type === 'color'
|
|
|
|
|
? db.colors.alias(item.id)
|
2022-01-08 12:41:56 +05:00
|
|
|
: item.title
|
|
|
|
|
: null;
|
2020-01-16 19:53:16 +05:00
|
|
|
|
2020-12-19 14:26:44 +05:00
|
|
|
const onScrollEnd = () => {
|
2020-12-29 17:19:32 +05:00
|
|
|
getRef().current?.handleChildScrollEnd();
|
2020-12-19 14:26:44 +05:00
|
|
|
};
|
|
|
|
|
|
2020-01-09 20:14:51 +05:00
|
|
|
return (
|
2020-12-19 13:15:34 +05:00
|
|
|
<ScrollView
|
2020-12-19 14:26:44 +05:00
|
|
|
nestedScrollEnabled
|
|
|
|
|
onMomentumScrollEnd={onScrollEnd}
|
2020-12-31 12:16:28 +05:00
|
|
|
keyboardShouldPersistTaps="always"
|
|
|
|
|
keyboardDismissMode="none"
|
2020-01-10 18:44:41 +05:00
|
|
|
style={{
|
|
|
|
|
backgroundColor: colors.bg,
|
2020-01-24 18:48:33 +05:00
|
|
|
paddingHorizontal: 0,
|
2020-12-19 14:26:44 +05:00
|
|
|
borderBottomRightRadius: DDS.isLargeTablet() ? 10 : 1,
|
2021-07-19 13:25:32 +05:00
|
|
|
borderBottomLeftRadius: DDS.isLargeTablet() ? 10 : 1
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2022-01-07 13:05:24 +05:00
|
|
|
{!item || !item.id ? (
|
2022-01-22 12:57:05 +05:00
|
|
|
<Paragraph style={{ marginVertical: 10, alignSelf: 'center' }}>
|
2020-11-09 20:26:20 +05:00
|
|
|
Start writing to save your note.
|
|
|
|
|
</Paragraph>
|
2020-02-03 12:18:45 +05:00
|
|
|
) : (
|
2020-04-18 13:49:24 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2021-04-22 11:49:55 +05:00
|
|
|
marginTop: 5,
|
2021-07-19 13:25:32 +05:00
|
|
|
zIndex: 10
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2021-06-16 11:39:52 +05:00
|
|
|
<View
|
|
|
|
|
style={{
|
2021-12-22 13:59:58 +05:00
|
|
|
paddingHorizontal: 12
|
2022-01-22 12:57:05 +05:00
|
|
|
}}
|
|
|
|
|
>
|
2021-12-22 13:59:58 +05:00
|
|
|
<Heading size={SIZE.lg}>
|
2022-01-07 13:05:24 +05:00
|
|
|
{item.type === 'tag' ? '#' : null}
|
2021-12-22 13:59:58 +05:00
|
|
|
{alias}
|
|
|
|
|
</Heading>
|
|
|
|
|
|
2022-01-07 13:05:24 +05:00
|
|
|
{item.headline || item.description ? (
|
2022-01-31 14:27:32 +05:00
|
|
|
<Paragraph
|
|
|
|
|
style={{
|
|
|
|
|
marginBottom: 5
|
|
|
|
|
}}
|
|
|
|
|
numberOfLines={2}
|
|
|
|
|
color={colors.icon}
|
|
|
|
|
>
|
2022-01-22 12:57:05 +05:00
|
|
|
{(item.type === 'notebook' || item.itemType === 'notebook') && item?.description
|
2022-01-07 13:05:24 +05:00
|
|
|
? item.description
|
2021-12-22 13:59:58 +05:00
|
|
|
: null}
|
2022-01-22 12:57:05 +05:00
|
|
|
{(item.type === 'note' || item.itemType === 'note') && item?.headline
|
2022-01-07 13:05:24 +05:00
|
|
|
? item.headline
|
2021-12-27 18:09:00 +05:00
|
|
|
: null}
|
2021-12-22 13:59:58 +05:00
|
|
|
</Paragraph>
|
2021-09-13 08:53:16 +05:00
|
|
|
) : null}
|
2020-09-08 14:36:25 +05:00
|
|
|
|
2022-01-07 13:05:24 +05:00
|
|
|
{item.type === 'note' ? <Tags close={close} item={item} /> : null}
|
2021-12-22 13:59:58 +05:00
|
|
|
|
2022-01-07 13:05:24 +05:00
|
|
|
<Topics item={item} close={close} />
|
2021-07-07 12:54:48 +05:00
|
|
|
</View>
|
2021-12-22 13:59:58 +05:00
|
|
|
|
2022-01-22 12:57:05 +05:00
|
|
|
{item.type === 'note' ? <Notebooks note={item} close={close} /> : null}
|
2021-12-27 18:09:00 +05:00
|
|
|
|
2022-01-07 13:05:24 +05:00
|
|
|
<DateMeta item={item} />
|
2020-04-18 13:49:24 +05:00
|
|
|
</View>
|
|
|
|
|
)}
|
2021-12-22 13:59:58 +05:00
|
|
|
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
borderTopWidth: 1,
|
|
|
|
|
borderColor: colors.nav
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
2022-01-07 13:05:24 +05:00
|
|
|
{item.type === 'note' ? <ColorTags close={close} item={item} /> : null}
|
2021-12-22 13:59:58 +05:00
|
|
|
|
2022-01-07 23:42:58 +05:00
|
|
|
<Items item={item} buttons={buttons} close={close} />
|
2022-01-07 11:04:38 +05:00
|
|
|
<Synced item={item} close={close} />
|
2022-01-07 13:05:24 +05:00
|
|
|
<DevMode item={item} />
|
2021-12-22 13:59:58 +05:00
|
|
|
|
2020-01-24 18:48:33 +05:00
|
|
|
{DDS.isTab ? (
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
2021-07-19 13:25:32 +05:00
|
|
|
height: 20
|
2020-01-24 18:48:33 +05:00
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
2020-12-19 13:15:34 +05:00
|
|
|
</ScrollView>
|
2020-01-09 20:14:51 +05:00
|
|
|
);
|
|
|
|
|
};
|
2022-01-07 13:05:24 +05:00
|
|
|
|
|
|
|
|
Properties.present = (item, buttons = []) => {
|
2022-01-08 12:41:56 +05:00
|
|
|
if (!item) return;
|
|
|
|
|
let type = item?.type;
|
2022-01-07 13:05:24 +05:00
|
|
|
let props = [item];
|
2022-01-22 12:57:05 +05:00
|
|
|
let android = [];
|
2022-01-07 13:05:24 +05:00
|
|
|
switch (type) {
|
|
|
|
|
case 'trash':
|
|
|
|
|
props.push(['PermDelete', 'Restore']);
|
|
|
|
|
break;
|
|
|
|
|
case 'note':
|
2022-01-22 12:57:05 +05:00
|
|
|
android = Platform.OS === 'android' ? ['PinToNotif'] : [];
|
2022-01-07 13:05:24 +05:00
|
|
|
props.push([
|
|
|
|
|
'Add to notebook',
|
|
|
|
|
'Share',
|
|
|
|
|
'Export',
|
|
|
|
|
'Copy',
|
|
|
|
|
'Publish',
|
|
|
|
|
'Pin',
|
|
|
|
|
'Favorite',
|
|
|
|
|
'Attachments',
|
|
|
|
|
'Vault',
|
|
|
|
|
'Delete',
|
|
|
|
|
'RemoveTopic',
|
|
|
|
|
'History',
|
|
|
|
|
...android,
|
|
|
|
|
...buttons
|
|
|
|
|
]);
|
|
|
|
|
break;
|
|
|
|
|
case 'notebook':
|
|
|
|
|
props.push(['Edit Notebook', 'Pin', 'Add Shortcut', 'Delete']);
|
|
|
|
|
break;
|
|
|
|
|
case 'topic':
|
2022-02-08 15:44:34 +05:00
|
|
|
props.push(['Move notes', 'Edit Topic', 'Add Shortcut', 'Delete']);
|
2022-01-07 13:05:24 +05:00
|
|
|
break;
|
|
|
|
|
case 'tag':
|
|
|
|
|
props.push(['Add Shortcut', 'Delete', 'Rename Tag']);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-01-07 23:42:58 +05:00
|
|
|
|
|
|
|
|
presentSheet({
|
|
|
|
|
component: (ref, close) => (
|
|
|
|
|
<Properties
|
|
|
|
|
close={() => {
|
|
|
|
|
close();
|
|
|
|
|
}}
|
|
|
|
|
getRef={() => ref}
|
|
|
|
|
item={props[0]}
|
|
|
|
|
buttons={props[1]}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
});
|
2022-01-07 13:05:24 +05:00
|
|
|
};
|