Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b5ac7218

Přidáno uživatelem Fantič před více než 1 rok

#re 10797 NoteViewPage refactor -> Responsive layout

Zobrazit rozdíly:

src/components/notes/NoteView.tsx
74 74
        }
75 75
    }
76 76

  
77
    note.items = ["helo"]
78

  
79 77
    return (
80 78
        <HStack marginTop={5}>
81 79
            <Box width="10" height="10" marginTop="2">
src/components/notes/NotesListView.tsx
7 7
import { ConfirmDialog } from "../general/Dialogs";
8 8
import { AppDispatch } from "../../stores/store";
9 9
import { useDispatch } from "react-redux";
10
import { Dimensions } from "react-native";
10 11

  
11 12
const NotesListView = (props: { notes: Note[], navigation: any, handleCreateComment: any, requestPending: boolean }) => {
12 13
    const notes = props.notes;
......
18 19

  
19 20
    const dispatch = useDispatch<AppDispatch>();
20 21

  
22
    const windowHeight = Dimensions.get('window').height;
23

  
21 24
    const [confirmDialog, setConfirmDialog] = React.useState<{
22 25
        headerText?: string;
23 26
        bodyText?: string;
......
31 34
    const handleReply = useCallback((messageId: string, userName: string) => {
32 35
        setReplyingTo({ messageId, userName });
33 36
    }, [setReplyingTo]);
34
    
37

  
35 38
    const handleEdit = useCallback((note: Note) => {
36 39
        if (!props.requestPending) {
37 40
            dispatch(updateNote(note));
38 41
        }
39 42
    }, [dispatch, props.requestPending]);
40
    
43

  
41 44
    const handleDelete = useCallback((messageId: string) => {
42 45
        if (!props.requestPending) {
43 46
            dispatch(deleteNote({ noteId: messageId }));
......
46 49

  
47 50
    return (
48 51
        <VStack>
49
            <Box h={props.handleCreateComment == null ? "88%" : (replyingTo != null ? "65%" : "70%")}>
52
            <Box height={windowHeight - 70 - 160 - (replyingTo ? 40 : 0)} marginBottom={2}>
53
                {/* Notes */}
50 54
                <ScrollView contentContainerStyle={{ flexGrow: 1 }}>
51 55
                    {
52 56
                        notes && notes.length > 0 ? (
53 57
                            <VStack>
54
                                {notes.map((note, index) => (
55
                                    <NoteView key={index} note={note} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} navigation={props.navigation} />
56
                                ))}
58
                                {notes.map((note, index) => {
59
                                    if(index >= 5){
60
                                        return null;
61
                                    }
62
                                    return (
63
                                        <NoteView key={index} note={note} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} navigation={props.navigation} />
64
                                    )
65
                                })}
57 66
                            </VStack>
58 67
                        ) : (
59 68
                            <Text>There are no notes.</Text>
......
61 70
                    }
62 71
                </ScrollView>
63 72
            </Box>
64
            {
65
                props.handleCreateComment != null && replyingTo != null &&
66
                <Flex direction="row" alignItems="center" justify="flex-end" h="5%" marginRight="10%">
67
                    <Text>Replying to {replyingTo.userName}</Text>
68
                    <IconButton onPress={() => setReplyingTo(null)} size="sm" icon={<CloseIcon />} marginLeft="-1%">
69
                    </IconButton>
70
                </Flex>
71
            }
72 73

  
74
            {/* Create comment */}
73 75
            {
74 76
                props.handleCreateComment != null &&
75
                <HStack h={replyingTo != null ? "20%" : "15%"} marginTop={replyingTo != null ? "0%" : "6%"}>
76
                    <TextArea placeholder="Add comment" width="90%" fontSize={14} value={newComment} onChangeText={setNewComment} autoCompleteType={undefined} ></TextArea>
77
                    <VStack>
78
                        <Box h={replyingTo != null ? "30%" : "45%"}></Box>
79
                        <Box marginLeft="2">
80
                            <Button onPress={() => props.handleCreateComment(newComment , replyingTo)} startIcon={<MessageIcon color="#FFF" />}></Button>
81
                        </Box>
82
                    </VStack>
83
                </HStack>
77
                <VStack>
78

  
79
                    {/* Replying to */}
80
                    {replyingTo != null &&
81
                        <Flex direction="row" alignItems="center" justify="flex-end" marginRight={20} height={10}>
82
                            <Text>Replying to {replyingTo.userName}</Text>
83
                            <IconButton onPress={() => setReplyingTo(null)} size="sm" icon={<CloseIcon />} marginLeft="-1%">
84
                            </IconButton>
85
                        </Flex>
86
                    }
87
                    
88

  
89
                    {/* Add comment */}
90
                    <HStack height={90} >
91
                        <TextArea
92
                            flex={1}
93
                            placeholder="Add comment"
94
                            fontSize={14}
95
                            value={newComment}
96
                            onChangeText={setNewComment}
97
                            autoCompleteType={undefined}
98
                        />
99
                        <Flex marginLeft={2} marginBottom={8}>
100
                            <Button onPress={() => props.handleCreateComment(newComment, replyingTo)} startIcon={<MessageIcon color="#FFF" />}>
101
                                Send
102
                            </Button>
103
                        </Flex>
104
                    </HStack>
105
                </VStack>
84 106
            }
85 107
            <ConfirmDialog {...confirmDialog} isShown={confirmDialog != null} cancelRef={cancelRef} />
86
        </VStack>
108
        </VStack >
87 109
    );
88 110
}
89 111

  
src/pages/NotesViewPage.tsx
1
import React, { useEffect, useState } from "react"
1
import React, { useCallback, useEffect, useState } from "react"
2 2
import { log } from "../logging/logger"
3 3
import { DrawerScreenProps } from "@react-navigation/drawer"
4 4
import { Box, Button, ChevronDownIcon, ChevronUpIcon, Flex, HStack, MinusIcon, Popover, Switch, Text, VStack } from "native-base"
......
10 10
import LoadingBox from "../components/loading/LoadingBox"
11 11
import { createNote, getAllNotes } from "../stores/actions/notesThunks"
12 12
import { RootDrawerParamList } from "./Navigation"
13
import { Dimensions } from "react-native"
13 14
const NotesViewPage = ({ navigation }: DrawerScreenProps<RootDrawerParamList, 'Notes'>) => {
14 15

  
15 16
  const { notes, notesLoading, requestPending, triggerRefresh } = useSelector((state: RootState) => state.noteViewState)
......
26 27
    date: SortOptions.None
27 28
  });
28 29

  
29
  const handleSortChanged = (key: "items" | "date") => {
30
  const handleSortChanged = useCallback((key: "items" | "date") => {
30 31
    let currentState = sortSettings[key];
31 32
    if (currentState == SortOptions.None) {
32 33
      setSortSettings({
......
46 47
        [key]: SortOptions.None
47 48
      })
48 49
    }
49
  }
50
  }, [setSortSettings]);
50 51

  
51 52
  const getSortIcon = (sortOption: SortOptions, size: string) => {
52 53
    switch (sortOption) {
......
103 104

  
104 105

  
105 106
  return (
106
    <Box width="92%" marginLeft="5%">
107
    <Box marginLeft={2.5} marginRight={2.5} marginTop={2.5}>
107 108
      <VStack>
108
        <HStack marginTop="5%">
109
          <Box width="30%" justifyContent={"center"}>
109
        <HStack height={75} justifyContent="space-between">
110
          <Box justifyContent={"center"}>
110 111
            <Popover // @ts-ignore
111 112
              trigger={triggerProps => {
112 113
                return <Button colorScheme="primary" {...triggerProps} onPress={() => setIsSortOpen(true)}>
......
141 142
              </Popover.Content>
142 143
            </Popover>
143 144
          </Box>
144
          <VStack width="70%" space="0">
145
            <Flex direction="row" alignItems="center" justify="flex-end">
145

  
146
          <VStack space={0.5}>
147
            <Flex direction="row" alignItems="center" justify="flex-end" height={35}>
146 148
              <Text>My comments</Text>
147 149
              <Switch isChecked={myCommentsCheck} onValueChange={() => { if (!notesLoading) setMyCommentsCheck(!myCommentsCheck) }} size="md" />
148 150
            </Flex>
149
            <Flex direction="row" alignItems="center" justify="flex-end" marginTop="-7.5%">
151
            <Flex direction="row" alignItems="center" justify="flex-end" height={35}>
150 152
              <Text>General comments</Text>
151 153
              <Switch isChecked={generalCommentsCheck} onValueChange={() => { if (!notesLoading) setGeneralCommentsCheck(!generalCommentsCheck) }} size="md" />
152 154
            </Flex>
153 155
          </VStack>
154 156
        </HStack>
155
        <Box>
156
          {
157
            notesLoading ? (
158
              <LoadingBox text="Loading notes" />
159
            )
160
              :
161
              (<NotesListView notes={notes} navigation={navigation} handleCreateComment={handleCreateComment} requestPending={requestPending} />)
162
          }
163
        </Box>
157
        {
158
          notesLoading ? (
159
            <LoadingBox text="Loading notes" />
160
          )
161
            :
162
            (<NotesListView notes={notes} navigation={navigation} handleCreateComment={handleCreateComment} requestPending={requestPending} />)
163
        }
164 164

  
165 165

  
166 166
      </VStack>

Také k dispozici: Unified diff