Projekt

Obecné

Profil

« Předchozí | Další » 

Revize f386a4fe

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

re #10818 Toast: implementation to pages

Zobrazit rozdíly:

src/components/listView/ListView.tsx
1 1
import { useEffect, useState } from "react"
2
import { ScrollView, Text, VStack } from "native-base"
2
import { ScrollView, Text, VStack, useToast } from "native-base"
3 3
import { useSelector } from "react-redux"
4 4
import { RootState } from "../../stores/store"
5 5
import ItemPreview from "./ItemPreview"
6 6
import { ItemPreviewType } from "../../types/listViewTypes"
7 7
import { log } from "../../logging/logger"
8 8
import ListViewInventoryGroup from "./ListViewInventoryGroup"
9
import { ErrorToast } from "../toast/ErrorToast"
9 10

  
10 11
type ListViewProps = {
11 12
    navigation: any
......
17 18
    const numberOfResults = useSelector((state: RootState) => state.listView.numOfResults)
18 19

  
19 20

  
21
    const lastError = useSelector((state: RootState) => state.listView.lastError)
22
    const toast = useToast();
23

  
24
    useEffect(() => {
25
        if (lastError) {
26
            toast.closeAll()
27
            toast.show({
28
                render: ({
29
                    id
30
                }) => {
31
                    return <ErrorToast headerText={"Error"} text={lastError} onClose={() => toast.close(id)} />;
32
                },
33
                duration: 3000
34
            });
35
        }
36
    }, [lastError])
37

  
20 38
    return (
21 39
        <>
22
            <Text fontSize={ 16 } fontWeight={ "bold" } color={"primary.500"}>Search results{numberOfResults ? ` (${numberOfResults})` : ""}:</Text>
23
            { inventories && inventories.length > 0 ?
40
            <Text fontSize={16} fontWeight={"bold"} color={"primary.500"}>Search results{numberOfResults ? ` (${numberOfResults})` : ""}:</Text>
41
            {inventories && inventories.length > 0 ?
24 42
                (inventories.length > 1 ?
25 43
                    inventories.map((inventory) => (
26
                            <ListViewInventoryGroup
27
                                inventoryName={ inventory.name }
28
                                inventoryLabel={ inventory.label }
29
                                navigation={ props.navigation }
30
                            />
31
                        )
44
                        <ListViewInventoryGroup
45
                            inventoryName={inventory.name}
46
                            inventoryLabel={inventory.label}
47
                            navigation={props.navigation}
48
                        />
49
                    )
32 50
                    ) : (
33 51
                        <ListViewInventoryGroup
34
                            inventoryName={ inventories[0].name }
35
                            inventoryLabel={ inventories[0].label }
36
                            navigation={ props.navigation }
37
                            defaultOpen={ true }
52
                            inventoryName={inventories[0].name}
53
                            inventoryLabel={inventories[0].label}
54
                            navigation={props.navigation}
55
                            defaultOpen={true}
38 56
                        />
39 57
                    )) : (
40
                    <Text alignSelf={ "center" }>No results found</Text>
58
                    <Text alignSelf={"center"}>No results found</Text>
41 59
                )
42 60
            }
43 61
        </>
src/components/notes/NotesListView.tsx
8 8
import { AppDispatch } from "../../stores/store";
9 9
import { useDispatch } from "react-redux";
10 10
import { Dimensions } from "react-native";
11
import { InfoToast } from "../toast/InfoToast";
11 12

  
12 13

  
13 14

  
14 15
const NotesListView = (props: { notes: Note[], navigation: any, handleCreateComment: any, requestPending: boolean }) => {
15 16
    const notes = props.notes;
16 17

  
17
    const toast = useToast();
18

  
19 18
    const [newComment, setNewComment] = useState<string>("");
20 19
    const [replyingTo, setReplyingTo] = useState<{ messageId: string; userName: string } | null>(null);
21 20

  
21
    const toast = useToast();
22

  
22 23
    const [renderedNotes, setRenderedNotes] = useState(6);
23 24

  
24 25
    const cancelRef = React.useRef(null);
......
53 54
        }
54 55
    }, [dispatch, props.requestPending]);
55 56

  
57

  
58

  
56 59
    const handleScrollEnd = (event: any) => {
57 60
        const offsetY = event.nativeEvent.contentOffset.y;
58 61
        const contentHeight = event.nativeEvent.contentSize.height;
......
63 66
            const nextBatchSize = 5; // Number of notes to render in the next batch
64 67

  
65 68
            if ((renderedNotes + nextBatchSize) > notes.length && (renderedNotes + nextBatchSize) != notes.length) {
69
                toast.closeAll()
70
                toast.show({
71
                    render: ({
72
                        id
73
                    }) => {
74
                        return <InfoToast text={"All notes loaded..."} onClose={() => toast.close(id)} />;
75
                    },
76
                    duration: 3000
77
                });
66 78
                setRenderedNotes(notes.length);
67
                // TODO toast display info all rendered
79

  
68 80
            }
69 81
            else if ((renderedNotes + nextBatchSize) != notes.length) {
82
                toast.closeAll()
83
                toast.show({
84
                    render: ({
85
                        id
86
                    }) => {
87
                        return <InfoToast text={"Loading more notes..."} onClose={() => toast.close(id)} />;
88
                    },
89
                    duration: 3000
90
                });
70 91
                setRenderedNotes(renderedNotes + nextBatchSize);
71
                // TODO toast display loading more notes
92

  
72 93
            }
73 94
        }
74 95
    };
......
83 104
                            <VStack>
84 105
                                {
85 106
                                    notes.slice(0, renderedNotes).map((note, index) => {
86
                                        
87
                                        if(replyingTo?.messageId == note.uuid){
107

  
108
                                        if (replyingTo?.messageId == note.uuid) {
88 109
                                            return <NoteView higlighted key={index} note={note} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} navigation={props.navigation} />
89 110
                                        }
90
                                        
111

  
91 112
                                        return <NoteView key={index} note={note} handleReply={handleReply} handleDelete={handleDelete} handleEdit={handleEdit} setConfirmDialog={setConfirmDialog} navigation={props.navigation} />;
92
                                        
113

  
93 114
                                    })
94 115
                                }
95 116
                            </VStack>
......
107 128

  
108 129
                    {/* Replying to */}
109 130
                    {replyingTo != null &&
110
                        <Flex direction="row" alignItems="center" justify="flex-end" height={10} style={{backgroundColor: "#FFF8E1"}}>
131
                        <Flex direction="row" alignItems="center" justify="flex-end" height={10} style={{ backgroundColor: "#FFF8E1" }}>
111 132
                            <Text>Replying to {replyingTo.userName}</Text>
112
                            <IconButton onPress={() => setReplyingTo(null)} size="sm" icon={<CloseIcon />} marginLeft="-1%" marginRight={20 }/>
133
                            <IconButton onPress={() => setReplyingTo(null)} size="sm" icon={<CloseIcon />} marginLeft="-1%" marginRight={20} />
113 134
                        </Flex>
114 135
                    }
115 136

  
src/pages/HomePage.tsx
1
import { Center, Image, Pressable, ScrollView, Text } from "native-base"
1
import { Center, Image, Pressable, ScrollView, Text, useToast } from "native-base"
2 2
import { useDispatch, useSelector } from "react-redux"
3 3
import { AppDispatch, RootState } from "../stores/store"
4 4
import { useContext, useEffect, useState } from "react"
......
9 9
import { RootDrawerParamList } from "./Navigation"
10 10
import { log } from "../logging/logger"
11 11
import { HOME_PAGE_IMG_URL } from "../api/constants"
12
import { ErrorToast } from "../components/toast/ErrorToast"
12 13
// import { Image } from "react-native"
13 14

  
14 15
const HomePage = ({navigation}: DrawerScreenProps<RootDrawerParamList, 'Home'>) => {
15 16
    const data = useSelector((state: RootState) => state.homePage.data)
16 17
    const loading = useSelector((state: RootState) => state.homePage.loading)
17
    const lastError = useSelector((state: RootState) => state.homePage.lastError)
18

  
18
    const lastError = useSelector((state: RootState) => state.itemViewState.lastError)
19
    const toast = useToast();
20
  
19 21
    useEffect(() => {
20 22
        if (lastError) {
21

  
23
            toast.closeAll()
24
            toast.show({
25
                render: ({
26
                    id
27
                }) => {
28
                    return <ErrorToast headerText={"Error"} text={lastError} onClose={() => toast.close(id)} />;
29
                },
30
                duration: 3000
31
            });
22 32
        }
23

  
24 33
    }, [lastError])
25 34

  
26 35
    const [aspectRatio, setAspectRatio] = useState(1.0)
src/pages/ItemViewPage.tsx
11 11
import { log } from "../logging/logger"
12 12
import { DrawerScreenProps } from "@react-navigation/drawer"
13 13
import { RootDrawerParamList } from "./Navigation"
14
import { useToast } from "native-base"
15
import { ErrorToast } from "../components/toast/ErrorToast"
14 16

  
15 17

  
16 18
const ItemViewPage = ({route, navigation}: DrawerScreenProps<RootDrawerParamList, 'Item'>) => {
......
31 33

  
32 34
  const { item, itemLoading, notes, notesLoading, concordances } = useSelector((state: RootState) => state.itemViewState)
33 35

  
36
  const lastError = useSelector((state: RootState) => state.itemViewState.lastError)
37
  const toast = useToast();
38

  
39
  useEffect(() => {
40
      if (lastError) {
41
          toast.closeAll()
42
          toast.show({
43
              render: ({
44
                  id
45
              }) => {
46
                  return <ErrorToast headerText={"Error"} text={lastError} onClose={() => toast.close(id)} />;
47
              },
48
              duration: 3000
49
          });
50
      }
51
  }, [lastError])
52

  
34 53
  // initial: load main item
35 54
  useEffect(() => {
36 55
    dispatch(getItem(route.params.itemId));
src/pages/LoginPage.tsx
30 30
    const [password, setPassword] = useState("")
31 31

  
32 32
    const lastError = useSelector((state: RootState) => state.user.lastError)
33

  
34 33
    const toast = useToast();
35 34

  
36

  
37 35
    useEffect(() => {
38 36
        if (lastError) {
39 37
            toast.closeAll()
......
46 44
                duration: 3000
47 45
            });
48 46
        }
49

  
50 47
    }, [lastError])
51 48

  
52 49
    const dispatch = useDispatch<AppDispatch>()
src/pages/NotesViewPage.tsx
1 1
import React, { useCallback, useEffect, useState } from "react"
2 2
import { log } from "../logging/logger"
3 3
import { DrawerScreenProps } from "@react-navigation/drawer"
4
import { Box, Button, ChevronDownIcon, ChevronUpIcon, Flex, HStack, MinusIcon, Popover, Switch, Text, VStack } from "native-base"
4
import { Box, Button, ChevronDownIcon, ChevronUpIcon, Flex, HStack, MinusIcon, Popover, Switch, Text, VStack, useToast } from "native-base"
5 5
import { SortOptions } from "../types/general"
6 6
import { Note } from "../types/note"
7 7
import NotesListView from "../components/notes/NotesListView"
......
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 { ErrorToast } from "../components/toast/ErrorToast"
13 14

  
14 15
const NotesViewPage = ({ navigation }: DrawerScreenProps<RootDrawerParamList, 'Notes'>) => {
15 16

  
......
22 23
  const [myCommentsCheck, setMyCommentsCheck] = useState(false);
23 24
  const [generalCommentsCheck, setGeneralCommentsCheck] = useState(true);
24 25

  
26
  const lastError = useSelector((state: RootState) => state.noteViewState.lastError)
27
  const toast = useToast();
28

  
29
  useEffect(() => {
30
      if (lastError) {
31
          toast.closeAll()
32
          toast.show({
33
              render: ({
34
                  id
35
              }) => {
36
                  return <ErrorToast headerText={"Error"} text={lastError} onClose={() => toast.close(id)} />;
37
              },
38
              duration: 3000
39
          });
40
      }
41
  }, [lastError])
42

  
25 43
  const [sortSettings, setSortSettings] = useState({
26 44
    items: SortOptions.None,
27 45
    date: SortOptions.None

Také k dispozici: Unified diff