Revize 160b7073
Přidáno uživatelem Fantič před více než 1 rok
src/pages/PlanViewPage.tsx | ||
---|---|---|
6 | 6 |
import { log } from "../logging/logger" |
7 | 7 |
import { DrawerScreenProps } from "@react-navigation/drawer" |
8 | 8 |
import { RootDrawerParamList } from "./Navigation" |
9 |
import { Box, CloseIcon, Select, useToast, Button, Flex } from "native-base" |
|
9 |
import { Box, CloseIcon, Select, useToast, Button, Flex, Text } from "native-base"
|
|
10 | 10 |
import { ErrorToast } from "../components/toast/ErrorToast" |
11 | 11 |
import { Floor, Place, Room } from "../types/plan" |
12 |
import { getFloorList } from "../stores/actions/planThunks" |
|
12 |
import { getFloorList, getPlanInventories, getPlanItems } from "../stores/actions/planThunks"
|
|
13 | 13 |
import { login } from "../stores/actions/userThunks" |
14 |
import { getPlanItemsRequest } from "../api/planservice" |
|
15 |
import ItemPreview from "../components/listView/ItemPreview" |
|
16 |
import { parseArtists, parseImage } from "../components/listView/ListViewInventoryGroup" |
|
17 |
import PlanView from "../components/plan/PlanView" |
|
18 |
import { BASE_API_URL } from "../api/constants" |
|
14 | 19 | |
15 | 20 |
const PlanViewPage = ({ route, navigation }: DrawerScreenProps<RootDrawerParamList, 'Plan'>) => { |
16 | 21 | |
17 | 22 |
const layout = useWindowDimensions(); |
18 | 23 | |
19 |
// Route: set selected room / place from |
|
20 |
useEffect(() => { |
|
21 |
console.log("dispatching get floor list") |
|
22 |
// dispatch(login({username: "Viktorie", password: "Golem123."})) |
|
23 |
dispatch(getFloorList()) |
|
24 |
}, []) |
|
25 | ||
24 |
// Route: set selected room / place from |
|
25 |
useEffect(() => { |
|
26 |
console.log("dispatching get floor list") |
|
27 |
// dispatch(login({username: "Viktorie", password: "Golem123."})) |
|
28 |
dispatch(getFloorList()) |
|
29 |
}, []) |
|
26 | 30 | |
27 |
let page = 1
|
|
28 |
let pageSize = 20
|
|
29 |
let room = 0
|
|
31 |
const pageSize = 20
|
|
32 |
const currentPage = 0
|
|
33 |
const totalPages = 100
|
|
30 | 34 | |
31 | 35 |
const DEFAULT_FLOOR = "first_floor" |
32 | 36 | |
... | ... | |
36 | 40 | |
37 | 41 |
const dispatch = useDispatch<AppDispatch>(); |
38 | 42 | |
39 |
const { floorListLoading, floorList, itemListLoading, itemList, lastError } = useSelector((state: RootState) => state.planViewState) |
|
43 |
const { floorListLoading, floorList, itemListLoading, itemList, itemInventories, itemInventoriesLoading, totalItemsCount, lastError } = useSelector((state: RootState) => state.planViewState)
|
|
40 | 44 | |
41 | 45 |
const toast = useToast(); |
42 | 46 | |
... | ... | |
45 | 49 |
if (route.params && route.params.roomId) { |
46 | 50 | |
47 | 51 |
selectRoom(route.params.roomId) |
48 |
|
|
52 | ||
49 | 53 |
if (route.params.placeId) { |
50 | 54 |
selectPlace(route.params.placeId) |
51 | 55 |
} |
52 |
|
|
53 |
// todo dispatch get items |
|
54 |
// getPlanItems(page, pageSize, room) |
|
56 | ||
57 |
if (!itemListLoading) { |
|
58 |
searchSubmit(currentPage, route.params.roomId, route.params.placeId) |
|
59 |
} |
|
60 | ||
55 | 61 |
} |
56 |
else{ |
|
62 |
else {
|
|
57 | 63 |
selectFloor(DEFAULT_FLOOR) |
58 | 64 |
} |
59 | 65 |
} |
60 | 66 |
}, [floorList, route.params.roomId, route.params.placeId]) |
61 | 67 | |
68 |
useEffect(() => { |
|
69 |
if (floorList && selectedRoom) { |
|
70 |
if (!itemInventoriesLoading) { |
|
71 |
dispatch(getPlanInventories({ room: selectedRoom.id, place: selectedPlace?.id })) |
|
72 |
} |
|
73 |
} |
|
74 |
}, [selectedPlace, selectedRoom]) |
|
75 | ||
76 | ||
62 | 77 |
useEffect(() => { |
63 | 78 |
if (lastError) { |
64 | 79 |
toast.closeAll() |
... | ... | |
74 | 89 |
}, [lastError]) |
75 | 90 | |
76 | 91 | |
77 |
const searchSubmit = () => { |
|
92 |
const searchSubmit = (pageNumber: number, roomId: number, placeId?: number) => {
|
|
78 | 93 |
log.debug("PlanView", "searchSubmit") |
79 | 94 | |
95 |
console.log("searching " + roomId + ", " + placeId) |
|
96 | ||
97 |
dispatch(getPlanItems({ page: pageNumber, items: pageSize, room: roomId, place: placeId, activeTab: 0 })) |
|
80 | 98 |
} |
81 | 99 | |
82 | 100 |
const selectFloor = (floorId: string) => { |
... | ... | |
232 | 250 |
Reset |
233 | 251 |
</Button> |
234 | 252 |
<Button |
235 |
onPress={() => searchSubmit()} |
|
253 |
onPress={() => { |
|
254 |
if (selectedRoom && !selectedPlace) { |
|
255 |
searchSubmit(currentPage, selectedRoom.id) |
|
256 |
} |
|
257 |
else if (selectedRoom && selectedPlace) { |
|
258 |
searchSubmit(currentPage, selectedRoom.id, selectedPlace.id) |
|
259 |
} |
|
260 | ||
261 |
}} |
|
236 | 262 |
colorScheme="primary" |
237 | 263 |
background={"primary.100"} |
238 | 264 |
variant="solid" |
... | ... | |
248 | 274 | |
249 | 275 | |
250 | 276 |
{/* Plan */} |
277 |
{/* temporary prototype */} |
|
251 | 278 | |
279 |
{selectedFloor && !floorListLoading && |
|
280 |
<PlanView imageUrl={BASE_API_URL + "/downloads/" + selectedFloor.id} /> |
|
281 |
} |
|
252 | 282 | |
253 | 283 |
{/* Item List */} |
284 |
<> |
|
285 |
{itemInventoriesLoading ? |
|
286 |
<LoadingBox text="Loading available inventories..." /> |
|
287 |
: |
|
288 |
<> |
|
289 |
<Text>TODO view inventories in SearchItemPreview way</Text> |
|
290 |
{itemInventories.map((inventory) => { |
|
291 |
<Text>{inventory.label}</Text> |
|
292 |
})} |
|
293 |
</> |
|
294 | ||
295 |
} |
|
296 |
{/* |
|
297 |
{itemList.map((item, index) => { |
|
298 |
return ( |
|
299 |
<Box> |
|
300 |
<ItemPreview |
|
301 |
// @ts-ignore |
|
302 |
caption={item.object[0].caption} |
|
303 |
title={item.text} |
|
304 |
name={parseArtists(item)} |
|
305 |
image={parseImage(item)} |
|
306 |
itemId={item.xml_id} |
|
307 |
inventoryLabel={item.inventory.label} |
|
308 |
navigation={navigation} |
|
309 |
/> |
|
310 |
</Box> */} |
|
311 |
</> |
|
312 | ||
254 | 313 | |
255 |
{/* <ItemPreview |
|
256 |
// @ts-ignore |
|
257 |
caption={item.object[0].caption} |
|
258 |
title={item.text} |
|
259 |
name={parseArtists(item)} |
|
260 |
image={parseImage(item)} |
|
261 |
itemId={item.xml_id} |
|
262 |
inventoryLabel={props.inventoryLabel} |
|
263 |
navigation={props.navigation} |
|
264 |
/> */} |
|
265 | 314 |
</Box > |
266 | 315 | |
267 | 316 |
Také k dispozici: Unified diff
re #10844: PlanViewPage: GetItemInventories, GetPlanItems