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/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

  

Také k dispozici: Unified diff