From fd1e39cee42a00937a3e3b1db01cc362827a3205 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Wed, 7 Feb 2024 11:00:24 +0500 Subject: [PATCH] mobile: minor fixes --- .../components/dialogs/color-picker/index.tsx | 25 ++-- .../app/components/list/reorderable-list.tsx | 3 + .../app/components/properties/color-tags.tsx | 123 ++++++++++-------- .../app/components/properties/date-meta.js | 2 +- .../mobile/app/components/properties/index.js | 61 ++++++--- .../mobile/app/components/properties/items.js | 4 +- apps/mobile/app/components/properties/tags.js | 11 +- .../components/side-menu/color-section.tsx | 19 +-- apps/mobile/app/hooks/use-actions.tsx | 99 ++++++++++---- packages/core/src/collections/vaults.ts | 6 +- 10 files changed, 215 insertions(+), 138 deletions(-) diff --git a/apps/mobile/app/components/dialogs/color-picker/index.tsx b/apps/mobile/app/components/dialogs/color-picker/index.tsx index a80d1060f..e68d7dfb9 100644 --- a/apps/mobile/app/components/dialogs/color-picker/index.tsx +++ b/apps/mobile/app/components/dialogs/color-picker/index.tsx @@ -16,23 +16,24 @@ 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 . */ -import { isThemeColor, useThemeColors } from "@notesnook/theme"; +import { useThemeColors } from "@notesnook/theme"; import React, { useRef, useState } from "react"; import { TextInput, View } from "react-native"; -import { FlashList } from "react-native-actions-sheet"; +import { FlashList } from "react-native-actions-sheet/dist/src/views/FlashList"; import Icon from "react-native-vector-icons/MaterialCommunityIcons"; +import { db } from "../../../common/database"; +import { ToastManager } from "../../../services/event-manager"; +import { useMenuStore } from "../../../stores/use-menu-store"; +import { useRelationStore } from "../../../stores/use-relation-store"; import { useSettingStore } from "../../../stores/use-setting-store"; import { SIZE } from "../../../utils/size"; import BaseDialog from "../../dialog/base-dialog"; import DialogContainer from "../../dialog/dialog-container"; +import { Toast } from "../../toast"; import { Button } from "../../ui/button"; import Input from "../../ui/input"; import { PressableButton } from "../../ui/pressable"; -import { ToastManager } from "../../../services/event-manager"; -import { Toast } from "../../toast"; -import { db } from "../../../common/database"; -import { useRelationStore } from "../../../stores/use-relation-store"; -import { useMenuStore } from "../../../stores/use-menu-store"; +import { Color } from "@notesnook/core"; const arrayOfColors = [ "#FF5733", "#33FF57", @@ -142,10 +143,12 @@ const convertToColorObjects = (colors: string[]) => { const ColorPicker = ({ visible, - setVisible + setVisible, + onColorAdded }: { visible: boolean; setVisible: (value: boolean) => void; + onColorAdded: (color: Color) => void; }) => { const [selectedColor, setSelectedColor] = useState(); const { colors } = useThemeColors(); @@ -282,13 +285,17 @@ const ColorPicker = ({ new Error(`Color #${selectedColor} already exists`) ); - await db.colors.add({ + const id = await db.colors.add({ title: title.current, colorCode: selectedColor }); useRelationStore.getState().update(); useMenuStore.getState().setColorNotes(); setVisible(false); + const color = await db.colors.color(id); + if (color) { + onColorAdded?.(color); + } }} type={selectedColor ? "grayAccent" : "grayBg"} width="100%" diff --git a/apps/mobile/app/components/list/reorderable-list.tsx b/apps/mobile/app/components/list/reorderable-list.tsx index ec8802ba2..6940b7e0b 100644 --- a/apps/mobile/app/components/list/reorderable-list.tsx +++ b/apps/mobile/app/components/list/reorderable-list.tsx @@ -40,6 +40,7 @@ interface ReorderableListProps hiddenItems: string[]; onHiddenItemsChanged?: (data: string[]) => void; canHideItems?: boolean; + disableDefaultDrag?: boolean; } function ReorderableList({ @@ -50,6 +51,7 @@ function ReorderableList({ itemOrder = [], onHiddenItemsChanged, canHideItems = true, + disableDefaultDrag, ...restProps }: ReorderableListProps) { const { colors } = useThemeColors(); @@ -158,6 +160,7 @@ function ReorderableList({ dragging: true }) } + itemsDraggable={disableDefaultDrag ? dragging : true} lockItemDragsToMainAxis onItemReorder={({ fromIndex, fromItem, toIndex, toItem }) => { const newOrder = getOrderedItems().map((item) => item.id); diff --git a/apps/mobile/app/components/properties/color-tags.tsx b/apps/mobile/app/components/properties/color-tags.tsx index 1bc8fdced..dfedad84c 100644 --- a/apps/mobile/app/components/properties/color-tags.tsx +++ b/apps/mobile/app/components/properties/color-tags.tsx @@ -20,7 +20,8 @@ along with this program. If not, see . import { Color, Note } from "@notesnook/core/dist/types"; import { useThemeColors } from "@notesnook/theme"; import React, { useCallback, useEffect, useState } from "react"; -import { ScrollView, View } from "react-native"; +import { View } from "react-native"; +import { FlashList } from "react-native-actions-sheet/dist/src/views/FlashList"; import Icon from "react-native-vector-icons/MaterialCommunityIcons"; import { notesnook } from "../../../e2e/test.ids"; import { db } from "../../common/database"; @@ -32,9 +33,9 @@ import { useSettingStore } from "../../stores/use-setting-store"; import { refreshNotesPage } from "../../utils/events"; import { SIZE } from "../../utils/size"; import ColorPicker from "../dialogs/color-picker"; -import { PressableButton } from "../ui/pressable"; -import { FlashList } from "react-native-actions-sheet"; import { Button } from "../ui/button"; +import { PressableButton } from "../ui/pressable"; +import NativeTooltip from "../../utils/tooltip"; const ColorItem = ({ item, note }: { item: Color; note: Note }) => { const { colors } = useThemeColors(); @@ -70,9 +71,12 @@ const ColorItem = ({ item, note }: { item: Color; note: Note }) => { testID={notesnook.ids.dialogs.actionsheet.color(item.colorCode)} key={item.id} onPress={toggleColor} + onLongPress={(event) => { + NativeTooltip.show(event, item.title, NativeTooltip.POSITIONS.TOP); + }} customStyle={{ - width: 30, - height: 30, + width: 35, + height: 35, borderRadius: 100, justifyContent: "center", alignItems: "center", @@ -103,60 +107,24 @@ export const ColorTags = ({ item }: { item: Note }) => { return ( <> - + { + await db.relations.add(color, note); + useRelationStore.getState().update(); + useMenuStore.getState().setColorNotes(); + Navigation.queueRoutesForUpdate(); + eSendEvent(refreshNotesPage); + }} + /> - {!colorNotes || !colorNotes.length ? ( -