Revize 7a3ad946
Přidáno uživatelem Fantič před více než 1 rok
src/pages/PlanViewPage.tsx | ||
---|---|---|
5 | 5 |
import { log } from "../logging/logger" |
6 | 6 |
import { DrawerScreenProps } from "@react-navigation/drawer" |
7 | 7 |
import { RootDrawerParamList } from "./Navigation" |
8 |
import { Box, CloseIcon, Select, useToast, Button, Flex, Text, Center, VStack, ScrollView, View } from "native-base" |
|
8 |
import { Box, CloseIcon, Select, useToast, Button, Flex, Text, Center, VStack, ScrollView, View, HStack, Divider } from "native-base"
|
|
9 | 9 |
import { ErrorToast } from "../components/toast/ErrorToast" |
10 | 10 |
import { Floor, Place, Room } from "../types/plan" |
11 | 11 |
import { getFloorList, getPlanFloorImage, getPlanInventories, getPlanItems } from "../stores/actions/planThunks" |
... | ... | |
19 | 19 |
import { loadItemsByInventory } from "../stores/actions/listViewThunks" |
20 | 20 |
import CastlePlanView from "../components/plan/CastlePlanView" |
21 | 21 |
|
22 |
import { Dimensions } from 'react-native'; |
|
23 |
|
|
22 | 24 |
const PlanViewPage = ({ route, navigation }: DrawerScreenProps<RootDrawerParamList, 'Plan'>) => { |
23 | 25 |
|
24 | 26 |
const dispatch = useDispatch<AppDispatch>() |
... | ... | |
32 | 34 |
|
33 | 35 |
const DEFAULT_FLOOR = "first_floor" |
34 | 36 |
|
37 |
const [castlePlanShown, setCastlePlanShown] = useState<boolean>(true) |
|
38 |
|
|
35 | 39 |
const [selectedFloor, setSelectedFloor] = useState<Floor | undefined>(undefined) |
36 | 40 |
const [selectedRoom, setSelectedRoom] = useState<Room | undefined>(undefined) |
37 | 41 |
const [selectedPlace, setSelectedPlace] = useState<Place | undefined>(undefined) |
... | ... | |
182 | 186 |
|
183 | 187 |
return ( |
184 | 188 |
<Box flex={1}> |
185 |
{!castlePlanFullScreenMode ? ( |
|
186 |
<ScrollView flex={1} w={"100%"} nestedScrollEnabled={!isInteractingWithCastlePlan}> |
|
187 |
<VStack space={1} mr={4}> |
|
188 |
|
|
189 |
{/* Selection */} |
|
190 |
|
|
191 |
{ |
|
192 |
floorListLoading ? |
|
193 |
<LoadingBox text="Floor list loading"></LoadingBox> |
|
194 |
: |
|
195 |
<> |
|
196 |
{/* Floor */} |
|
197 |
<Select |
|
198 |
mt={2.5} |
|
199 |
ml={2.5} |
|
200 |
mr={2.5} |
|
189 |
{!castlePlanFullScreenMode || !castlePlanShown ? ( |
|
190 |
<Box h={Dimensions.get('window').height - 55}> |
|
191 |
<ScrollView flex={1} w={"100%"} nestedScrollEnabled={!isInteractingWithCastlePlan}> |
|
192 |
<VStack space={1}> |
|
193 |
|
|
194 |
{/* Selection */} |
|
195 |
|
|
196 |
{ |
|
197 |
floorListLoading ? |
|
198 |
<LoadingBox text="Floor list loading"></LoadingBox> |
|
199 |
: |
|
200 |
<> |
|
201 |
{/* Floor */} |
|
202 |
<Select |
|
203 |
mt={2.5} |
|
204 |
ml={2.5} |
|
205 |
mr={2.5} |
|
206 |
|
|
207 |
placeholder={"Floor"} |
|
208 |
selectedValue={selectedFloor?.id} |
|
209 |
onValueChange={selectFloor} |
|
210 |
variant="rounded" |
|
211 |
> |
|
212 |
{floorList.map((floor, index) => { |
|
213 |
return ( |
|
214 |
<Select.Item value={floor.id} label={floor.label} /> |
|
215 |
); |
|
216 |
})} |
|
217 |
</Select> |
|
218 |
|
|
219 |
{/* Room */} |
|
201 | 220 |
|
202 |
placeholder={"Floor"} |
|
203 |
selectedValue={selectedFloor?.id} |
|
204 |
onValueChange={selectFloor} |
|
205 |
variant="rounded" |
|
206 |
> |
|
207 |
{floorList.map((floor, index) => { |
|
208 |
return ( |
|
209 |
<Select.Item value={floor.id} label={floor.label} /> |
|
210 |
); |
|
211 |
})} |
|
212 |
</Select> |
|
213 |
|
|
214 |
{/* Room */} |
|
215 |
{selectedFloor && selectedFloor.roomList && selectedFloor.roomList.length > 0 && |
|
216 | 221 |
< Select |
217 | 222 |
mt={2.5} |
218 | 223 |
ml={2.5} |
219 | 224 |
mr={2.5} |
220 | 225 |
|
226 |
isDisabled={(selectedFloor && selectedFloor.roomList && selectedFloor.roomList.length) ? false : true} |
|
227 |
|
|
221 | 228 |
placeholder={"Room"} |
222 | 229 |
selectedValue={selectedRoom?.id.toString()} |
223 | 230 |
onValueChange={(value: string) => selectRoom(parseInt(value))} |
... | ... | |
231 | 238 |
} |
232 | 239 |
})} |
233 | 240 |
</Select> |
234 |
} |
|
235 | 241 |
|
236 |
{/* Place */} |
|
237 |
{selectedRoom && selectedRoom.places && selectedRoom.places.length > 0 && |
|
242 |
{/* Place */} |
|
238 | 243 |
<Select |
239 | 244 |
mt={2.5} |
240 | 245 |
ml={2.5} |
241 | 246 |
mr={2.5} |
242 | 247 |
|
248 |
isDisabled={(selectedRoom && selectedRoom.places && selectedRoom.places.length > 0) ? false : true} |
|
243 | 249 |
placeholder={"Place"} |
244 | 250 |
selectedValue={selectedPlace?.id.toString()} |
245 | 251 |
onValueChange={(value: string) => selectPlace(parseInt(value))} |
... | ... | |
251 | 257 |
); |
252 | 258 |
})} |
253 | 259 |
</Select> |
254 |
} |
|
255 | 260 |
|
256 |
{/* Filter */} |
|
257 |
<Flex direction="row" alignItems="center" justify="flex-end" |
|
258 |
mt={2.5} |
|
259 |
ml={2.5} |
|
260 |
mr={3} |
|
261 |
> |
|
262 |
<Button |
|
263 |
endIcon={ |
|
264 |
<CloseIcon size="xs" /> |
|
265 |
} |
|
266 |
onPress={clearForm} |
|
267 |
variant="outline" |
|
268 |
color="primary.500" |
|
269 |
borderColor="primary.100" |
|
270 |
mr={2} |
|
271 |
borderRadius={15} |
|
272 |
size={"md"} |
|
261 |
{/* Filter */} |
|
262 |
<Flex direction="row" alignItems="center" justify="flex-end" |
|
263 |
mt={2.5} |
|
264 |
ml={2.5} |
|
265 |
mr={3} |
|
273 | 266 |
> |
274 |
Reset |
|
275 |
</Button> |
|
276 |
<Button |
|
277 |
onPress={() => { |
|
278 |
if (selectedRoom && !selectedPlace) { |
|
279 |
searchSubmit(selectedRoom.id) |
|
280 |
} |
|
281 |
else if (selectedRoom && selectedPlace) { |
|
282 |
searchSubmit(selectedRoom.id, selectedPlace.id) |
|
267 |
<Button |
|
268 |
startIcon={ |
|
269 |
<CloseIcon size="xs" /> |
|
283 | 270 |
} |
271 |
onPress={clearForm} |
|
272 |
variant="subtle" |
|
273 |
color="secondary.500" |
|
274 |
mr={2} |
|
275 |
borderRadius={10} |
|
276 |
size={"sm"} |
|
277 |
> |
|
278 |
Reset |
|
279 |
</Button> |
|
280 |
<Button |
|
281 |
onPress={() => { |
|
282 |
if (selectedRoom && !selectedPlace) { |
|
283 |
searchSubmit(selectedRoom.id) |
|
284 |
} |
|
285 |
else if (selectedRoom && selectedPlace) { |
|
286 |
searchSubmit(selectedRoom.id, selectedPlace.id) |
|
287 |
} |
|
288 |
|
|
289 |
}} |
|
290 |
backgroundColor={"#654B07"} |
|
291 |
variant="subtle" |
|
292 |
borderRadius={10} |
|
293 |
size={"sm"} |
|
294 |
> |
|
295 |
<Text color="white" fontSize={11}> |
|
296 |
Search |
|
297 |
</Text> |
|
298 |
</Button> |
|
299 |
</Flex> |
|
300 |
</> |
|
301 |
} |
|
284 | 302 |
|
285 |
}} |
|
286 |
colorScheme="primary" |
|
287 |
background={"primary.100"} |
|
288 |
variant="solid" |
|
289 |
borderRadius={15} |
|
290 |
size={"md"} |
|
291 |
> |
|
292 |
Search |
|
293 |
</Button> |
|
294 |
</Flex> |
|
295 |
</> |
|
296 |
} |
|
297 |
|
|
298 |
{/* Plan */} |
|
299 |
{/* temporary prototype */} |
|
300 |
|
|
301 |
{selectedFloor && !floorListLoading && ( |
|
302 |
floorMapImageLoading ? |
|
303 |
<LoadingBox text="Loading castle plan" /> |
|
304 |
: |
|
305 |
floorMapImage && |
|
306 |
<Box mt={2.5} ml={2.5} |
|
307 |
onTouchStart={() => setIsInteractingWithCastlePlan(true)} |
|
308 |
onTouchEnd={() => setIsInteractingWithCastlePlan(true)}> |
|
309 |
<CastlePlanView mapImage={floorMapImage} selectedRoom={selectedRoom} roomList={selectedFloor.roomList} /> |
|
310 |
</Box> |
|
311 |
) |
|
312 |
} |
|
313 |
|
|
314 |
{/* Item List */} |
|
315 |
<> |
|
316 |
{inventoriesLoading ? |
|
317 |
<LoadingBox text="Loading available inventories..." /> |
|
318 |
: |
|
319 |
<Box mt={2.5} ml={2.5}> |
|
320 |
<ListView |
|
321 |
|
|
322 |
navigation={navigation} |
|
323 |
hideHeaderText |
|
324 |
|
|
325 |
inventories={inventories} |
|
326 |
numOfResults={numberOfResults} |
|
327 |
|
|
328 |
data={data} |
|
329 |
loadedPages={pagination ?? {}} |
|
330 |
inventoriesDataLoading={dataLoading ?? {}} |
|
331 |
handleLoadMoreItems={(inventoryName: string, cursor: number) => { |
|
332 |
dispatch(getPlanItems({ cursor: cursor, inventory: inventoryName, room: selectedRoom?.id ?? 0, place: selectedPlace?.id })) |
|
333 |
} |
|
334 |
} |
|
335 |
/> |
|
336 |
</Box> |
|
303 |
{/* Plan */} |
|
304 |
{castlePlanShown && selectedFloor && !floorListLoading && ( |
|
305 |
floorMapImageLoading ? |
|
306 |
<LoadingBox text="Loading castle plan" /> |
|
307 |
: |
|
308 |
floorMapImage && |
|
309 |
<Box |
|
310 |
mt={2.5} |
|
311 |
ml={2.5} |
|
312 |
mr={2.5} |
|
313 |
onTouchStart={() => setIsInteractingWithCastlePlan(true)} |
|
314 |
onTouchEnd={() => setIsInteractingWithCastlePlan(true)}> |
|
315 |
<CastlePlanView mapImage={floorMapImage} selectedRoom={selectedRoom} roomList={selectedFloor.roomList} height={Dimensions.get("window").height - 350} /> |
|
316 |
</Box> |
|
317 |
) |
|
337 | 318 |
} |
338 |
</> |
|
339 | 319 |
|
340 |
</VStack> |
|
341 |
</ScrollView>) |
|
320 |
{/* Item List */} |
|
321 |
<> |
|
322 |
{!castlePlanShown && ( |
|
323 |
inventoriesLoading ? |
|
324 |
<LoadingBox text="Loading available inventories..." /> |
|
325 |
: |
|
326 |
<Box mt={2.5} ml={2.5} mr={2.5}> |
|
327 |
<ListView |
|
328 |
|
|
329 |
navigation={navigation} |
|
330 |
hideHeaderText |
|
331 |
|
|
332 |
inventories={inventories} |
|
333 |
numOfResults={numberOfResults} |
|
334 |
|
|
335 |
data={data} |
|
336 |
loadedPages={pagination ?? {}} |
|
337 |
inventoriesDataLoading={dataLoading ?? {}} |
|
338 |
handleLoadMoreItems={(inventoryName: string, cursor: number) => { |
|
339 |
dispatch(getPlanItems({ cursor: cursor, inventory: inventoryName, room: selectedRoom?.id ?? 0, place: selectedPlace?.id })) |
|
340 |
}} |
|
341 |
|
|
342 |
/> |
|
343 |
</Box> |
|
344 |
) |
|
345 |
} |
|
346 |
</> |
|
347 |
|
|
348 |
</VStack> |
|
349 |
</ScrollView> |
|
350 |
{/* item notes switch tab */} |
|
351 |
<HStack alignItems="center"> |
|
352 |
<Button |
|
353 |
variant={"unstyled"} |
|
354 |
w="50%" |
|
355 |
onPress={() => { setCastlePlanShown(true) }} |
|
356 |
> |
|
357 |
<VStack alignItems={"center"}> |
|
358 |
<Text bold={castlePlanShown} mb={castlePlanShown ? undefined : 2}> |
|
359 |
Castle |
|
360 |
</Text> |
|
361 |
{castlePlanShown && <Divider borderWidth={1} width={60} mt={2} />} |
|
362 |
</VStack> |
|
363 |
</Button> |
|
364 |
<Button |
|
365 |
variant={"unstyled"} |
|
366 |
w="50%" |
|
367 |
onPress={() => { setCastlePlanShown(false) }} |
|
368 |
> |
|
369 |
<VStack alignItems={"center"}> |
|
370 |
<Text bold={!castlePlanShown} mb={!castlePlanShown ? undefined : 2}> |
|
371 |
Results |
|
372 |
</Text> |
|
373 |
{!castlePlanShown && <Divider borderWidth={1} width={60} mt={2} />} |
|
374 |
</VStack> |
|
375 |
</Button> |
|
376 |
</HStack> |
|
377 |
</Box> |
|
378 |
) |
|
342 | 379 |
: |
343 | 380 |
floorMapImageLoading ? |
344 | 381 |
<LoadingBox text="Loading castle plan" /> |
345 | 382 |
: |
346 |
floorMapImage && selectedFloor &&
|
|
383 |
floorMapImage && selectedFloor && |
|
347 | 384 |
<Box> |
348 | 385 |
<CastlePlanView fullScreenMode mapImage={floorMapImage} selectedRoom={selectedRoom} roomList={selectedFloor.roomList} /> |
349 | 386 |
</Box> |
Také k dispozici: Unified diff
re #10871: PlanViewPage: Tabs Castle/Results, styling