Files
notesnook/apps/mobile/app/components/properties/index.js

220 lines
5.9 KiB
JavaScript
Raw Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
Copyright (C) 2022 Streetwriters (Private) Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-08-30 16:13:11 +05:00
2022-08-29 16:19:17 +05:00
import React from "react";
import { Platform, View } from "react-native";
2022-08-29 16:19:17 +05:00
import { ScrollView } from "react-native-gesture-handler";
import { db } from "../../common/database";
import { DDS } from "../../services/device-detection";
import { presentSheet } from "../../services/event-manager";
2022-08-29 16:19:17 +05:00
import SearchService from "../../services/search";
import { useThemeStore } from "../../stores/use-theme-store";
import { COLORS_NOTE } from "../../utils/color-scheme";
import { SIZE } from "../../utils/size";
import Heading from "../ui/typography/heading";
import Paragraph from "../ui/typography/paragraph";
import { ColorTags } from "./color-tags";
import { DateMeta } from "./date-meta";
import { DevMode } from "./dev-mode";
import { Items } from "./items";
import Notebooks from "./notebooks";
import { Synced } from "./synced";
import { Tags } from "./tags";
import { Topics } from "./topics";
export const Properties = ({
close = () => {},
item,
buttons = [],
getRef
}) => {
const colors = useThemeStore((state) => state.colors);
2022-07-08 20:54:55 +05:00
const alias = item.alias || item.title;
const isColor = !!COLORS_NOTE[item.title];
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,
borderBottomLeftRadius: DDS.isLargeTablet() ? 10 : 1,
maxHeight: "95%"
2022-01-22 12:57:05 +05:00
}}
>
2022-01-07 13:05:24 +05:00
{!item || !item.id ? (
<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={{
marginTop: 5,
2021-07-19 13:25:32 +05:00
zIndex: 10
2022-01-22 12:57:05 +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}>
{item.type === "tag" && !isColor ? (
2022-07-08 20:54:55 +05:00
<Heading size={SIZE.xl} color={colors.accent}>
#
</Heading>
) : 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}
>
{(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}
{(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
{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
{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
}}
/>
{item.type === "note" ? <ColorTags close={close} item={item} /> : null}
2021-12-22 13:59:58 +05:00
2022-03-23 12:23:51 +05:00
<Items
item={item}
buttons={buttons}
close={() => {
close();
setTimeout(() => {
SearchService.updateAndSearch();
}, 1000);
}}
/>
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-02-19 11:13:46 +05:00
let props = [];
2022-01-22 12:57:05 +05:00
let android = [];
2022-01-07 13:05:24 +05:00
switch (type) {
case "trash":
2022-02-19 11:13:46 +05:00
props[0] = item;
props.push(["PermDelete", "Restore"]);
2022-01-07 13:05:24 +05:00
break;
case "note":
android = Platform.OS === "android" ? ["PinToNotif"] : [];
2022-02-19 11:13:46 +05:00
props[0] = db.notes.note(item.id).data;
2022-01-07 13:05:24 +05:00
props.push([
"Add to notebook",
"Share",
"Export",
"Copy",
"Publish",
"Pin",
"Favorite",
"Attachments",
"Vault",
"Delete",
"RemoveTopic",
"History",
"ReadOnly",
"Local only",
"Duplicate",
2022-01-07 13:05:24 +05:00
...android,
...buttons
]);
break;
case "notebook":
2022-02-19 11:13:46 +05:00
props[0] = db.notebooks.notebook(item.id).data;
props.push(["Edit Notebook", "Pin", "Add Shortcut", "Delete"]);
2022-01-07 13:05:24 +05:00
break;
case "topic":
props[0] = db.notebooks
.notebook(item.notebookId)
.topics.topic(item.id)._topic;
props.push(["Move notes", "Edit Topic", "Add Shortcut", "Delete"]);
2022-01-07 13:05:24 +05:00
break;
case "tag":
2022-02-19 11:13:46 +05:00
props[0] = db.tags.tag(item.id);
props.push(["Add Shortcut", "Delete", "Rename Tag"]);
2022-01-07 13:05:24 +05:00
break;
}
2022-03-14 16:28:54 +05:00
if (!props[0]) return;
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
};