Projekt

Obecné

Profil

« Předchozí | Další » 

Revize aac857cf

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

re #10871: PlanViewPage: CastlePlanView init : get map image

Zobrazit rozdíly:

package.json
26 26
    "react-native-deck-swiper": "^1.1.7",
27 27
    "react-native-gesture-handler": "~2.12.0",
28 28
    "react-native-logs": "^5.0.1",
29
    "react-native-maps": "^1.8.0",
29 30
    "react-native-multiple-select": "^0.5.12",
30 31
    "react-native-reanimated": "~3.3.0",
31 32
    "react-native-safe-area-context": "4.6.3",
......
43 44
    "@tsconfig/react-native": "^2.0.3",
44 45
    "@types/jest": "^29.5.0",
45 46
    "@types/react": "~18.2.14",
47
    "@types/react-native-maps": "^0.24.2",
46 48
    "@types/react-test-renderer": "^18.0.0",
47 49
    "typescript": "^5.1.3"
48 50
  },
src/api/planservice.ts
13 13
    )
14 14
}
15 15

  
16

  
17

  
16
export const getPlanFloorImageRequest = async (floorId: string) => {
17
    return await axiosInstance.get(`/downloads/${floorId}`);
18
}
18 19

  
19 20
/*
20

  
21

  
22 21
// inventories
23 22
@activeTab: index of selected inventory: result: Inventories (starting from 0)
24 23

  
src/components/plan/CastlePlanView.tsx
1
import { VStack, Box, Text, HStack, ScrollView, Flex, Button, CloseIcon, IconButton, TextArea, useToast } from "native-base";
2
import { Note } from "../../types/note";
3
import React, { useCallback, useState } from "react";
4
import { Floor, Room } from "../../types/plan";
5

  
6
import MapView, { Marker } from 'react-native-maps';
7
import Svg, { Image, SvgXml } from 'react-native-svg';
8
import SvgImage from "react-native-svg/lib/typescript/elements/Image";
9

  
10
const CastlePlanView = (props: { mapImage : string, selectedRoom?: Room }) => {
11

  
12
    const { mapImage, selectedRoom } = props
13

  
14
    console.log(mapImage.substring(0,500))
15

  
16
    return (
17
        <Box h={300}>
18
            {/* Display the background image */}
19
            <SvgXml
20
                xml={mapImage}
21
            />
22

  
23
            {/* Display the MapView on top of the background image */}
24
            <MapView
25
                style={{ flex: 1 }}
26
            // Add other map-related props as needed
27
            >
28
            </MapView>
29
        </Box>
30
    );
31
}
32

  
33
export default CastlePlanView
src/components/plan/PlanView.tsx
1
import { VStack, Box, Text, HStack, ScrollView, Flex, Button, CloseIcon, IconButton, TextArea, useToast, Image } from "native-base";
2
import { Note } from "../../types/note";
3
import React, { useCallback, useState } from "react";
4

  
5

  
6

  
7

  
8
const PlanView = (props: { imageUrl: string }) => {
9
    return (
10
        <Image size={250} alt="image" source={{ uri: props.imageUrl }} />
11
    );
12
}
13

  
14
export default PlanView
src/pages/PlanViewPage.tsx
8 8
import { Box, CloseIcon, Select, useToast, Button, Flex, Text, Center, VStack, ScrollView } from "native-base"
9 9
import { ErrorToast } from "../components/toast/ErrorToast"
10 10
import { Floor, Place, Room } from "../types/plan"
11
import { getFloorList, getPlanInventories, getPlanItems } from "../stores/actions/planThunks"
11
import { getFloorList, getPlanFloorImage, getPlanInventories, getPlanItems } from "../stores/actions/planThunks"
12 12
import { login } from "../stores/actions/userThunks"
13 13
import { getPlanItemsRequest } from "../api/planservice"
14 14
import ItemPreview from "../components/listView/ItemPreview"
15
import PlanView from "../components/plan/PlanView"
15
import PlanView from "../components/plan/CastlePlanView"
16 16
import { BASE_API_URL } from "../api/constants"
17 17
import ListView from "../components/listView/ListView"
18 18
import SearchForm from "../components/search/SearchForm"
19 19
import { loadItemsByInventory } from "../stores/actions/listViewThunks"
20
import CastlePlanView from "../components/plan/CastlePlanView"
20 21

  
21 22
const PlanViewPage = ({ route, navigation }: DrawerScreenProps<RootDrawerParamList, 'Plan'>) => {
22 23

  
......
46 47
  const dataLoading = useSelector((state: RootState) => state.planViewState.itemListLoading)
47 48
  const pagination = useSelector((state: RootState) => state.planViewState.itemListPagination)
48 49

  
50
  const floorMapImage = useSelector((state: RootState) => state.planViewState.mapImage)
51
  const floorMapImageLoading = useSelector((state: RootState) => state.planViewState.mapImageLoading)
52

  
49 53
  const toast = useToast();
50 54

  
51 55
  useEffect(() => {
......
62 66
        // if (!itemListLoading) {
63 67
        //   searchSubmit(currentPage, route.params.roomId, route.params.placeId)
64 68
        // }
65

  
66 69
      }
67 70
      else {
68 71
        selectFloor(DEFAULT_FLOOR)
......
78 81
    }
79 82
  }, [selectedPlace, selectedRoom])
80 83

  
84
  useEffect(() => {
85
    if (selectedFloor) {
86
      console.log("Dispatching getFloorImage " + selectedFloor.id)
87
      dispatch(getPlanFloorImage(selectedFloor.id))
88
    }
89
  }, [selectedFloor])
90

  
81 91

  
82 92
  useEffect(() => {
83 93
    if (lastError) {
......
283 293
          {/* Plan */}
284 294
          {/* temporary prototype */}
285 295

  
286
          {/* {selectedFloor && !floorListLoading &&
287
            <PlanView imageUrl={BASE_API_URL + "/downloads/" + selectedFloor.id} />
288
          } */}
296
          {selectedFloor && !floorListLoading && (
297
            floorMapImageLoading ?
298
              <LoadingBox text="Loading castle plan" />
299
              :
300
              floorMapImage && <CastlePlanView mapImage={floorMapImage} selectedRoom={selectedRoom} />
301
          )
302
          }
289 303

  
290 304
          {/* Item List */}
291 305
          <>
src/stores/actions/planThunks.ts
1 1
import { createAsyncThunk } from "@reduxjs/toolkit"
2 2
import { SortOptions } from "../../types/general";
3 3
import { Note } from "../../types/note";
4
import { getPlanAllRequest, getPlanItemsRequest } from "../../api/planservice";
4
import { getPlanAllRequest, getPlanFloorImageRequest, getPlanItemsRequest } from "../../api/planservice";
5 5
import { Floor, Room } from "../../types/plan";
6 6
import { ItemPreviewType } from "../../types/listViewTypes";
7 7
import { StringLiteralType } from "typescript";
......
64 64
                const response = await getPlanItemsRequest({ cursor: 0, room: params.room, items: 1, place: params.place })
65 65
                if (response.status === 200) {
66 66

  
67
                    console.log("response")
68
                    console.log(response.data.pagination.inventories)
69

  
70 67
                    const inventories: Inventory[] = response.data.pagination.inventories
71 68
                    const allInventoriesRecords = response.data.pagination.records
72 69

  
......
113 110
                return Promise.reject(err.response.data)
114 111
            }
115 112

  
113
        } catch (err: any) {
114
            console.log(err);
115
            return Promise.reject(err.response.data)
116
        }
117
    }
118
)
119

  
120
export const getPlanFloorImage = createAsyncThunk(
121
    "plan/getPlanFloorImage",
122
    async (floorId: string) => {
123
        try {
124
            try {
125
                const response = await getPlanFloorImageRequest(floorId)
126

  
127
                if (response.status === 200) {
128
                    return response.data
129
                } else {
130
                    return Promise.reject(response.data ? response.data : "Get plan floor image request failed")
131
                }
132
            } catch (err: any) {
133
                return Promise.reject(err.response.data)
134
            }
135

  
116 136
        } catch (err: any) {
117 137
            console.log(err);
118 138
            return Promise.reject(err.response.data)
src/stores/reducers/planSlice.ts
1 1
import { PayloadAction, createSlice } from "@reduxjs/toolkit"
2 2
import { PlanViewState } from "../../types/plan";
3
import { getFloorList, getPlanInventories, getPlanItems } from "../actions/planThunks";
3
import { getFloorList, getPlanFloorImage, getPlanInventories, getPlanItems } from "../actions/planThunks";
4 4

  
5 5
const initialState: PlanViewState = {
6 6
    lastError: "",
......
96 96
            state.itemInventoriesLoading = false;
97 97
            state.lastError = action.error.message
98 98
        })
99

  
100
        // getPlanFloorImage
101
        builder.addCase(getPlanFloorImage.fulfilled, (state, action) => {
102
            state.mapImage = action.payload
103
            state.mapImageLoading = false
104
        })
105
        builder.addCase(getPlanFloorImage.pending, (state, action) => {
106
            state.mapImageLoading = true
107
        })
108
        builder.addCase(getPlanFloorImage.rejected, (state, action) => {
109
            state.mapImageLoading = false;
110
            state.lastError = action.error.message
111
        })
99 112
    }
100 113
})
101 114

  
src/types/plan.ts
51 51
    itemList: Record<string, ItemPreviewType[]>
52 52

  
53 53
    // plan
54
    // @TODO
55

  
54
    mapImage?: string
55
    mapImageLoading?: boolean
56 56

  
57 57
    // last error
58 58
    lastError?: string

Také k dispozici: Unified diff