commit b5ac72183d12cb4154254824dfc998aae22b8e13
Author: Fantič <58391275+FantaFantic@users.noreply.github.com>
Date:   Wed Oct 4 14:24:20 2023 +0200

    #re 10797 NoteViewPage refactor -> Responsive layout

diff --git a/src/components/notes/NoteView.tsx b/src/components/notes/NoteView.tsx
index bf23199..646b38d 100644
--- a/src/components/notes/NoteView.tsx
+++ b/src/components/notes/NoteView.tsx
@@ -74,8 +74,6 @@ const NoteView = React.memo((props: { note: Note, handleReply: any, handleDelete
         }
     }
 
-    note.items = ["helo"]
-
     return (
         <HStack marginTop={5}>
             <Box width="10" height="10" marginTop="2">
diff --git a/src/components/notes/NotesListView.tsx b/src/components/notes/NotesListView.tsx
index 5090e97..6082844 100644
--- a/src/components/notes/NotesListView.tsx
+++ b/src/components/notes/NotesListView.tsx
@@ -7,6 +7,7 @@ import { updateNote, deleteNote } from "../../stores/actions/notesThunks";
 import { ConfirmDialog } from "../general/Dialogs";
 import { AppDispatch } from "../../stores/store";
 import { useDispatch } from "react-redux";
+import { Dimensions } from "react-native";
 
 const NotesListView = (props: { notes: Note[], navigation: any, handleCreateComment: any, requestPending: boolean }) => {
     const notes = props.notes;
@@ -18,6 +19,8 @@ const NotesListView = (props: { notes: Note[], navigation: any, handleCreateComm
 
     const dispatch = useDispatch<AppDispatch>();
 
+    const windowHeight = Dimensions.get('window').height;
+
     const [confirmDialog, setConfirmDialog] = React.useState<{
         headerText?: string;
         bodyText?: string;
@@ -31,13 +34,13 @@ const NotesListView = (props: { notes: Note[], navigation: any, handleCreateComm
     const handleReply = useCallback((messageId: string, userName: string) => {
         setReplyingTo({ messageId, userName });
     }, [setReplyingTo]);
-    
+
     const handleEdit = useCallback((note: Note) => {
         if (!props.requestPending) {
             dispatch(updateNote(note));
         }
     }, [dispatch, props.requestPending]);
-    
+
     const handleDelete = useCallback((messageId: string) => {
         if (!props.requestPending) {
             dispatch(deleteNote({ noteId: messageId }));
@@ -46,14 +49,20 @@ const NotesListView = (props: { notes: Note[], navigation: any, handleCreateComm
 
     return (
         <VStack>
-            <Box h={props.handleCreateComment == null ? "88%" : (replyingTo != null ? "65%" : "70%")}>
+            <Box height={windowHeight - 70 - 160 - (replyingTo ? 40 : 0)} marginBottom={2}>
+                {/* Notes */}
                 <ScrollView contentContainerStyle={{ flexGrow: 1 }}>
                     {
                         notes && notes.length > 0 ? (
                             <VStack>
-                                {notes.map((note, index) => (
-                                    <NoteView key={index} note={note} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} navigation={props.navigation} />
-                                ))}
+                                {notes.map((note, index) => {
+                                    if(index >= 5){
+                                        return null;
+                                    }
+                                    return (
+                                        <NoteView key={index} note={note} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} navigation={props.navigation} />
+                                    )
+                                })}
                             </VStack>
                         ) : (
                             <Text>There are no notes.</Text>
@@ -61,29 +70,42 @@ const NotesListView = (props: { notes: Note[], navigation: any, handleCreateComm
                     }
                 </ScrollView>
             </Box>
-            {
-                props.handleCreateComment != null && replyingTo != null &&
-                <Flex direction="row" alignItems="center" justify="flex-end" h="5%" marginRight="10%">
-                    <Text>Replying to {replyingTo.userName}</Text>
-                    <IconButton onPress={() => setReplyingTo(null)} size="sm" icon={<CloseIcon />} marginLeft="-1%">
-                    </IconButton>
-                </Flex>
-            }
 
+            {/* Create comment */}
             {
                 props.handleCreateComment != null &&
-                <HStack h={replyingTo != null ? "20%" : "15%"} marginTop={replyingTo != null ? "0%" : "6%"}>
-                    <TextArea placeholder="Add comment" width="90%" fontSize={14} value={newComment} onChangeText={setNewComment} autoCompleteType={undefined} ></TextArea>
-                    <VStack>
-                        <Box h={replyingTo != null ? "30%" : "45%"}></Box>
-                        <Box marginLeft="2">
-                            <Button onPress={() => props.handleCreateComment(newComment , replyingTo)} startIcon={<MessageIcon color="#FFF" />}></Button>
-                        </Box>
-                    </VStack>
-                </HStack>
+                <VStack>
+
+                    {/* Replying to */}
+                    {replyingTo != null &&
+                        <Flex direction="row" alignItems="center" justify="flex-end" marginRight={20} height={10}>
+                            <Text>Replying to {replyingTo.userName}</Text>
+                            <IconButton onPress={() => setReplyingTo(null)} size="sm" icon={<CloseIcon />} marginLeft="-1%">
+                            </IconButton>
+                        </Flex>
+                    }
+                    
+
+                    {/* Add comment */}
+                    <HStack height={90} >
+                        <TextArea
+                            flex={1}
+                            placeholder="Add comment"
+                            fontSize={14}
+                            value={newComment}
+                            onChangeText={setNewComment}
+                            autoCompleteType={undefined}
+                        />
+                        <Flex marginLeft={2} marginBottom={8}>
+                            <Button onPress={() => props.handleCreateComment(newComment, replyingTo)} startIcon={<MessageIcon color="#FFF" />}>
+                                Send
+                            </Button>
+                        </Flex>
+                    </HStack>
+                </VStack>
             }
             <ConfirmDialog {...confirmDialog} isShown={confirmDialog != null} cancelRef={cancelRef} />
-        </VStack>
+        </VStack >
     );
 }
 
diff --git a/src/pages/NotesViewPage.tsx b/src/pages/NotesViewPage.tsx
index 01c2a11..775ceac 100644
--- a/src/pages/NotesViewPage.tsx
+++ b/src/pages/NotesViewPage.tsx
@@ -1,4 +1,4 @@
-import React, { useEffect, useState } from "react"
+import React, { useCallback, useEffect, useState } from "react"
 import { log } from "../logging/logger"
 import { DrawerScreenProps } from "@react-navigation/drawer"
 import { Box, Button, ChevronDownIcon, ChevronUpIcon, Flex, HStack, MinusIcon, Popover, Switch, Text, VStack } from "native-base"
@@ -10,6 +10,7 @@ import { AppDispatch, RootState } from "../stores/store"
 import LoadingBox from "../components/loading/LoadingBox"
 import { createNote, getAllNotes } from "../stores/actions/notesThunks"
 import { RootDrawerParamList } from "./Navigation"
+import { Dimensions } from "react-native"
 const NotesViewPage = ({ navigation }: DrawerScreenProps<RootDrawerParamList, 'Notes'>) => {
 
   const { notes, notesLoading, requestPending, triggerRefresh } = useSelector((state: RootState) => state.noteViewState)
@@ -26,7 +27,7 @@ const NotesViewPage = ({ navigation }: DrawerScreenProps<RootDrawerParamList, 'N
     date: SortOptions.None
   });
 
-  const handleSortChanged = (key: "items" | "date") => {
+  const handleSortChanged = useCallback((key: "items" | "date") => {
     let currentState = sortSettings[key];
     if (currentState == SortOptions.None) {
       setSortSettings({
@@ -46,7 +47,7 @@ const NotesViewPage = ({ navigation }: DrawerScreenProps<RootDrawerParamList, 'N
         [key]: SortOptions.None
       })
     }
-  }
+  }, [setSortSettings]);
 
   const getSortIcon = (sortOption: SortOptions, size: string) => {
     switch (sortOption) {
@@ -103,10 +104,10 @@ const NotesViewPage = ({ navigation }: DrawerScreenProps<RootDrawerParamList, 'N
 
 
   return (
-    <Box width="92%" marginLeft="5%">
+    <Box marginLeft={2.5} marginRight={2.5} marginTop={2.5}>
       <VStack>
-        <HStack marginTop="5%">
-          <Box width="30%" justifyContent={"center"}>
+        <HStack height={75} justifyContent="space-between">
+          <Box justifyContent={"center"}>
             <Popover // @ts-ignore
               trigger={triggerProps => {
                 return <Button colorScheme="primary" {...triggerProps} onPress={() => setIsSortOpen(true)}>
@@ -141,26 +142,25 @@ const NotesViewPage = ({ navigation }: DrawerScreenProps<RootDrawerParamList, 'N
               </Popover.Content>
             </Popover>
           </Box>
-          <VStack width="70%" space="0">
-            <Flex direction="row" alignItems="center" justify="flex-end">
+
+          <VStack space={0.5}>
+            <Flex direction="row" alignItems="center" justify="flex-end" height={35}>
               <Text>My comments</Text>
               <Switch isChecked={myCommentsCheck} onValueChange={() => { if (!notesLoading) setMyCommentsCheck(!myCommentsCheck) }} size="md" />
             </Flex>
-            <Flex direction="row" alignItems="center" justify="flex-end" marginTop="-7.5%">
+            <Flex direction="row" alignItems="center" justify="flex-end" height={35}>
               <Text>General comments</Text>
               <Switch isChecked={generalCommentsCheck} onValueChange={() => { if (!notesLoading) setGeneralCommentsCheck(!generalCommentsCheck) }} size="md" />
             </Flex>
           </VStack>
         </HStack>
-        <Box>
-          {
-            notesLoading ? (
-              <LoadingBox text="Loading notes" />
-            )
-              :
-              (<NotesListView notes={notes} navigation={navigation} handleCreateComment={handleCreateComment} requestPending={requestPending} />)
-          }
-        </Box>
+        {
+          notesLoading ? (
+            <LoadingBox text="Loading notes" />
+          )
+            :
+            (<NotesListView notes={notes} navigation={navigation} handleCreateComment={handleCreateComment} requestPending={requestPending} />)
+        }
 
 
       </VStack>
