commit 56626a630d260b7f09053c94e5560fb50fa46c80
Author: Fantič <58391275+FantaFantic@users.noreply.github.com>
Date:   Wed Oct 4 11:15:24 2023 +0200

    #re 10797 NotesListView set replying optimize

diff --git a/src/components/item/ItemView.tsx b/src/components/item/ItemView.tsx
index 9f67d31..4d64295 100644
--- a/src/components/item/ItemView.tsx
+++ b/src/components/item/ItemView.tsx
@@ -1,5 +1,5 @@
 import { Center, Box, VStack, Button, HStack, Text, Image, ScrollView, View, Spacer, Card, Heading, Switch, Flex } from "native-base"
-import React, { useEffect, useState } from "react"
+import React, { useCallback, useEffect, useState } from "react"
 import { Item } from "../../types/item"
 import { Note } from "../../types/note"
 import LoadingBox from "../loading/LoadingBox"
@@ -145,21 +145,19 @@ const ItemNotes = (props: { item: Item, notes: Note[], notesLoading: boolean, na
         }
     }
 
-    const handleCreateItemComment = (newComment: string, replyingTo: { messageId: string; userName: string } | null) => {
-        if (!requestPending) {
-            // creating new comment
-            if (replyingTo != null) {
-                dispatch(createNote({
-                    newNote: { note: newComment, reply_to: replyingTo.messageId } as Note
-                }))
+    const handleCreateItemComment = useCallback(
+        (newComment: string, replyingTo: { messageId: string; userName: string } | null) => {
+            if (!requestPending) {
+                // creating new comment
+                if (replyingTo != null) {
+                    dispatch(createNote({ newNote: { note: newComment, reply_to: replyingTo.messageId } as Note }));
+                } else {
+                    dispatch(createNote({ newNote: { note: newComment, items: props.item.id } as any }));
+                }
             }
-            else {
-                dispatch(createNote({
-                    newNote: { note: newComment, items: props.item.id } as any
-                }))
-            }
-        }
-    }
+        },
+        [props.item.id]
+    );
 
     return (
 
diff --git a/src/components/notes/NoteView.tsx b/src/components/notes/NoteView.tsx
index deb1148..777ece5 100644
--- a/src/components/notes/NoteView.tsx
+++ b/src/components/notes/NoteView.tsx
@@ -4,15 +4,16 @@ import { EditIcon } from "../general/Icons";
 import { AVATAR_URL } from "../../api/constants";
 import { useState } from "react";
 import React from "react";
-import { ConfirmDialog } from "../general/Dialogs";
 
-const NoteView = (props: { note: Note, handleReply: any, handleDelete: any, handleEdit: any, setConfirmDialog: any, navigation: any }) => {
+const NoteView =  React.memo((props: { note: Note, handleReply: any, handleDelete: any, handleEdit: any, setConfirmDialog: any, navigation: any }) => {
     const note = props.note;
 
     const [isEdited, setIsEdited] = useState(false);
 
     const [text, setText] = useState(note.note);
 
+    console.log("rerender");
+
     const getDateString = (timestamp: Date): string => {
         return new Date(timestamp).toLocaleString("en-US",
             { year: "numeric", month: "short", day: "2-digit", hour: "2-digit", minute: "2-digit", hour12: false }
@@ -142,7 +143,7 @@ const NoteView = (props: { note: Note, handleReply: any, handleDelete: any, hand
             </VStack>
         </HStack>
     );
-}
+})
 
 export default NoteView
 
diff --git a/src/components/notes/NotesListView.tsx b/src/components/notes/NotesListView.tsx
index f74e355..5090e97 100644
--- a/src/components/notes/NotesListView.tsx
+++ b/src/components/notes/NotesListView.tsx
@@ -2,7 +2,7 @@ import { VStack, Box, Text, HStack, ScrollView, Flex, Button, CloseIcon, IconBut
 import { Note } from "../../types/note";
 import NoteView from "./NoteView";
 import { MessageIcon } from "../general/Icons";
-import React, { useState } from "react";
+import React, { useCallback, useState } from "react";
 import { updateNote, deleteNote } from "../../stores/actions/notesThunks";
 import { ConfirmDialog } from "../general/Dialogs";
 import { AppDispatch } from "../../stores/store";
@@ -28,19 +28,21 @@ const NotesListView = (props: { notes: Note[], navigation: any, handleCreateComm
         onSubmit?: () => void;
     } | null>(null);
 
-    const handleReply = (messageId: string, userName: string) => {
-        setReplyingTo({ messageId, userName })
-    }
-
-    const handleEdit = (note: Note) => {
-        if (!props.requestPending)
+    const handleReply = useCallback((messageId: string, userName: string) => {
+        setReplyingTo({ messageId, userName });
+    }, [setReplyingTo]);
+    
+    const handleEdit = useCallback((note: Note) => {
+        if (!props.requestPending) {
             dispatch(updateNote(note));
-    }
-
-    const handleDelete = (messageId: string) => {
-        if (!props.requestPending)
-            dispatch(deleteNote({ noteId: messageId }))
-    }
+        }
+    }, [dispatch, props.requestPending]);
+    
+    const handleDelete = useCallback((messageId: string) => {
+        if (!props.requestPending) {
+            dispatch(deleteNote({ noteId: messageId }));
+        }
+    }, [dispatch, props.requestPending]);
 
     return (
         <VStack>
diff --git a/src/stores/actions/itemThunks.ts b/src/stores/actions/itemThunks.ts
index 35043a6..c3656eb 100644
--- a/src/stores/actions/itemThunks.ts
+++ b/src/stores/actions/itemThunks.ts
@@ -123,6 +123,7 @@ export const getItemNotes = createAsyncThunk(
                             note: (note as any).note,
                             avatarUrl: (note as any).avatar,
                             items: (note as any).items,
+                            replies: (note as any).replies ?? undefined,
                             createdTime: (note as any).created, 
                             updatedTime: (note as any).updated,
                             noteColor: (note as any).note_color,
diff --git a/src/stores/actions/notesThunks.ts b/src/stores/actions/notesThunks.ts
index d0dc094..eb4e3ee 100644
--- a/src/stores/actions/notesThunks.ts
+++ b/src/stores/actions/notesThunks.ts
@@ -93,6 +93,7 @@ export const getAllNotes = createAsyncThunk(
                             note: (note as any).note,
                             avatarUrl: (note as any).avatar,
                             items: (note as any).items,
+                            replies: (note as any).replies ?? undefined,
                             createdTime: (note as any).created,
                             updatedTime: (note as any).updated,
                             noteColor: (note as any).note_color,
diff --git a/src/types/note.ts b/src/types/note.ts
index 6a16193..f80589b 100644
--- a/src/types/note.ts
+++ b/src/types/note.ts
@@ -5,10 +5,11 @@ export interface Note {
     note: string // text
     avatarUrl: string
     items: string[]
+    replies?: Note[]
     createdTime: Date 
     updatedTime: Date
     noteColor: string
-    reply_to: string // parent id
+    reply_to?: string // parent id
 }
 
 
