Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 29f3811f

Přidáno uživatelem Schwobik před téměř 2 roky(ů)

ItemPreview custom image added instead of missing image
re #10715

Zobrazit rozdíly:

src/components/listView/ItemPreview.tsx
1
import { Center, HStack, Image, Pressable, ScrollView, Text, VStack } from "native-base"
1
import { Box, Center, HStack, Image, Pressable, ScrollView, Text, VStack } from "native-base"
2 2
import { useEffect } from "react"
3 3
import { DrawerScreenProps } from "@react-navigation/drawer"
4
import { RootDrawerParamList } from "../Navigation"
4
import { RootDrawerParamList } from "../../pages/Navigation"
5
import { ItemPreviewMissingImage } from "./ItemPreviewMissingImage"
5 6

  
6 7
interface ItemPreviewProps {
7 8
    caption: string
......
9 10
    name?: string
10 11
    image?: string
11 12
    itemId: string
13
    inventoryLabel: string
12 14
    navigation: any
13 15
}
14 16

  
15 17
const ItemPreview = (props: ItemPreviewProps) => {
16 18

  
17
    useEffect(() => {
18
        console.log("ItemPreview", "Props:", props)
19
    }, [props])
20

  
21 19
    return (
22 20
        <>
23 21
            <Pressable
......
27 25
                <HStack
28 26
                    space={ 2 }
29 27
                    flex={ 1 }
30
                    alignItems={ "start" }
28
                    alignItems={ "flex-start" }
29
                    key={props.itemId}
31 30
                >
31
                    {props.image ? (
32 32
                    <Image
33
                        source={ {uri: `http:/147.228.173.159/static/images/${ props.image ? "thumb-" + props.image : "thumb-Rel-78.png" }`} }
33
                        source={ {uri: `http:/147.228.173.159/static/images/thumb-${props.image}`} }
34 34
                        size={ "sm" }
35
                        alt={ props.image ? props.image : "thumb-Rel-78.png" }
35
                        alt={ props.image }
36 36
                    />
37
                    <VStack h={70}>
37
                    ) : (
38
                        <ItemPreviewMissingImage inventoryLabel={props.inventoryLabel} h={65} w={65} />
39
                    )}
40
                    <VStack h={70} maxW={"80%"}>
38 41
                        <Text fontSize={"sm"} italic>{ props.name }</Text>
39 42
                        <Text fontSize={"sm"} bold noOfLines={1}>{ props.caption }</Text>
40
                        <Text fontSize={"xs"}>{ props.title }</Text>
43
                        <Text fontSize={"2xs"} lineHeight={"2xs"} noOfLines={2}>{ props.title }</Text>
41 44
                    </VStack>
42 45
                </HStack>
43 46
            </Pressable>
src/components/listView/ItemPreviewMissingImage.tsx
1
import { Box, Center, Text, VStack } from "native-base"
2
import { useEffect, useState } from "react"
3
import { log } from "../../logging/logger"
4

  
5
interface ItemPreviewMissingImageProps {
6
    inventoryLabel: string
7
    w?: number
8
    h?: number
9
}
10

  
11
const DEFAULT_W = 65
12
const DEFAULT_H = 65
13

  
14
export const ItemPreviewMissingImage = (props: ItemPreviewMissingImageProps) => {
15
    const [firstPart, setFirstPart] = useState("")
16
    const [secondPart, setSecondPart] = useState("")
17

  
18
    useEffect(() => {
19
        setFirstPart(props.inventoryLabel.slice(0, props.inventoryLabel.indexOf(" ")))
20
        setSecondPart(props.inventoryLabel.slice(props.inventoryLabel.indexOf(" ") + 1))
21
        log.debug("ItemPreviewMissingImage", "inventoryLabel", props.inventoryLabel)
22
        log.debug("ItemPreviewMissingImage", "firstPart", firstPart)
23
        log.debug("ItemPreviewMissingImage", "secondPart", secondPart)
24
    }, [props.inventoryLabel])
25

  
26
    return (
27
        <Center>
28
            <Box
29
                bg="primary.100"
30
                w={props.w ? props.w : DEFAULT_W}
31
                h={props.h ? props.h : DEFAULT_H}
32
                borderColor={"primary.700"}
33
                borderWidth={4}
34
                alignItems="center"
35
                justifyContent="center"
36
            >
37
                <VStack space={0}>
38
                    <Text
39
                        fontSize="sm"
40
                        color="black"
41
                        textAlign={"center"}
42
                        bold
43
                        noOfLines={1}
44
                    >
45
                        { firstPart }
46
                    </Text>
47
                    <Text
48
                        fontSize="xs"
49
                        color="black"
50
                        textAlign={"center"}
51
                    >
52
                        { secondPart }
53
                    </Text>
54
                </VStack>
55
            </Box>
56
        </Center>
57
    )
58
}

Také k dispozici: Unified diff