-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Kiel-H-Byrne/addListingCard
Add listing card
- Loading branch information
Showing
15 changed files
with
350 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { IListing } from "@/types"; | ||
import fetcher from "@/util/fetch"; | ||
import { HStack } from '@chakra-ui/react'; | ||
import SWR from "swr"; | ||
import BusinessCard from "./ListingCard2"; | ||
const AppList = () => { | ||
const data_uri = "api/listings"; | ||
const { data: fetchData, error } = SWR(data_uri, fetcher, { | ||
loadingTimeout: 1000, | ||
errorRetryCount: 2, | ||
}); | ||
return ( | ||
<HStack flexWrap={'wrap'}> | ||
{fetchData && fetchData.map((listing: IListing) => | ||
<BusinessCard activeListing={listing} key={listing.name} /> | ||
)} | ||
</HStack> | ||
); | ||
}; | ||
|
||
export default AppList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { IClaims, IListing } from "@/types"; | ||
import { Box, Button, Collapse, Heading, Image, Text } from "@chakra-ui/react"; | ||
import { useState } from "react"; | ||
|
||
const ListingCard = ({ activeListing }: { activeListing: IListing }) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const toggleCollapse = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
const { name, address, description, claims, imageUri } = activeListing; | ||
const getLikelyOwnerInfo = (claims: IClaims) => claims[0]; | ||
const ownerInfo = claims && getLikelyOwnerInfo(claims); | ||
return ( | ||
<Box | ||
borderWidth="1px" | ||
borderRadius="lg" | ||
overflow="hidden" | ||
boxShadow="lg" | ||
p={4} | ||
maxW="400px" | ||
> | ||
<Box position="relative"> | ||
<Image src={imageUri} alt={name} h="200px" w="100%" objectFit="cover" /> | ||
<Box | ||
position="absolute" | ||
bottom="0" | ||
left="0" | ||
right="0" | ||
bg="rgba(0, 0, 0, 0.6)" | ||
color="white" | ||
p={4} | ||
> | ||
<Text fontSize="sm">{address}</Text> | ||
<Heading fontSize="2xl" mt={2}> | ||
{name} | ||
</Heading> | ||
<Text fontSize="md" mt={2}> | ||
{description} | ||
</Text> | ||
<Box mt={4}> | ||
<Button size="sm" variant="ghost" onClick={toggleCollapse}> | ||
Owned by {ownerInfo?.member.name} | ||
</Button> | ||
<Collapse in={isOpen} animateOpacity> | ||
<Box mt={2} p={2} bg="gray.100"> | ||
{/* Additional owner information */} | ||
</Box> | ||
</Collapse> | ||
</Box> | ||
</Box> | ||
</Box> | ||
<Box mt={4}> | ||
<Button colorScheme="blue" size="sm" mr={2}> | ||
Get Directions | ||
</Button> | ||
<Button colorScheme="blue" size="sm"> | ||
Share | ||
</Button> | ||
{/* Additional CTA buttons */} | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default ListingCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { IListing, PHA_LODGES } from "@/types"; | ||
import { ChevronDownIcon, ChevronUpIcon } from "@chakra-ui/icons"; | ||
import { | ||
Box, | ||
Button, | ||
Collapse, | ||
Flex, | ||
IconButton, | ||
Image, | ||
Text, | ||
} from "@chakra-ui/react"; | ||
import { useState } from "react"; | ||
import { MdDirections, MdShare } from "react-icons/md"; | ||
|
||
const getLodgeName = ({ | ||
state, | ||
lodgeNo, | ||
}: { | ||
state: string | undefined; | ||
lodgeNo: number | undefined; | ||
//@ts-ignore | ||
}) => state && lodgeNo && (PHA_LODGES[state] as any[lodgeNo]); | ||
|
||
const BusinessCard = ({ activeListing }: { activeListing: IListing }) => { | ||
const [isOwnerInfoOpen, setIsOwnerInfoOpen] = useState(false); | ||
const { claims, imageUri, creator } = activeListing; | ||
const owner = claims?.[0].member || creator; | ||
|
||
const handleOwnerInfoToggle = () => { | ||
setIsOwnerInfoOpen(!isOwnerInfoOpen); | ||
}; | ||
|
||
return ( | ||
<Box | ||
maxW="md" | ||
mx="auto" | ||
borderWidth="1px" | ||
borderRadius="lg" | ||
overflow="hidden" | ||
boxShadow="md" | ||
> | ||
{/* Image section */} | ||
<Image src={imageUri} alt="Business Image" /> | ||
|
||
{/* Business Information */} | ||
<Box p="4"> | ||
<Text fontWeight="bold" fontSize="lg"> | ||
{activeListing.name} | ||
</Text> | ||
<Text fontSize="sm" color="gray.600"> | ||
{owner?.name} | ||
</Text> | ||
<Text fontSize="sm" color="gray.600"> | ||
{activeListing.address} | ||
</Text> | ||
|
||
{/* Owner Information Dropdown */} | ||
<Flex justify="space-between" align="center" mt="2"> | ||
<Button size="sm" colorScheme="teal" onClick={handleOwnerInfoToggle}> | ||
Owned by {owner?.name} | ||
</Button> | ||
|
||
<IconButton | ||
icon={isOwnerInfoOpen ? <ChevronUpIcon /> : <ChevronDownIcon />} | ||
aria-label="Toggle Owner Info" | ||
variant="outline" | ||
size="sm" | ||
onClick={handleOwnerInfoToggle} | ||
/> | ||
</Flex> | ||
|
||
<Collapse in={isOwnerInfoOpen} animateOpacity> | ||
<Box p="4" mt="2" bg="gray.100" rounded="md"> | ||
<Text fontSize="sm" fontWeight="bold"> | ||
Owner Information | ||
</Text> | ||
<Text fontSize="sm">{owner?.name}</Text> | ||
<Text fontSize="sm"> | ||
{getLodgeName({ | ||
state: owner?.profile.lodgeState, | ||
lodgeNo: owner?.profile.lodgeNumber, | ||
})} | ||
</Text> | ||
</Box> | ||
</Collapse> | ||
|
||
{/* Call to Action Buttons */} | ||
<Flex justify="space-between" align="center" mt="4"> | ||
<Button | ||
leftIcon={<MdDirections />} | ||
colorScheme="blue" | ||
size="sm" | ||
rounded="full" | ||
// onClick={directions} | ||
> | ||
Get Directions | ||
</Button> | ||
|
||
<Button | ||
leftIcon={<MdShare />} | ||
colorScheme="teal" | ||
size="sm" | ||
rounded="full" | ||
// onClick={share} | ||
> | ||
Share Business | ||
</Button> | ||
</Flex> | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default BusinessCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.