-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
550 additions
and
157 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
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
92 changes: 92 additions & 0 deletions
92
dapp/src/components/shared/Activities/ActivityCard/ActivityCard.tsx
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,92 @@ | ||
import React, { useCallback } from "react" | ||
import { | ||
CardBody, | ||
CardFooter, | ||
CardHeader, | ||
CardProps, | ||
HStack, | ||
Icon, | ||
Tooltip, | ||
CloseButton, | ||
} from "@chakra-ui/react" | ||
import { useLocation } from "react-router-dom" | ||
import { ActivityInfo, LocationState } from "#/types" | ||
import { capitalize } from "#/utils" | ||
import { ChevronRightIcon } from "#/assets/icons" | ||
import { CurrencyBalance } from "#/components/shared/CurrencyBalance" | ||
import StatusInfo from "#/components/shared/StatusInfo" | ||
import { TextSm } from "#/components/shared/Typography" | ||
import { ActivityCardContainer } from "./ActivityCardContainer" | ||
import { ActivityCardLink } from "./ActivityCardLink" | ||
|
||
type ActivityCardType = CardProps & { | ||
activity: ActivityInfo | ||
onRemove: (txHash: string) => void | ||
} | ||
|
||
export function ActivityCard({ | ||
activity, | ||
onRemove, | ||
...props | ||
}: ActivityCardType) { | ||
const state = useLocation().state as LocationState | null | ||
const isActive = state ? activity.txHash === state.activity.txHash : false | ||
const isCompleted = activity.status === "completed" | ||
|
||
const onClose = useCallback( | ||
(event: React.MouseEvent) => { | ||
event.preventDefault() | ||
if (activity.txHash) { | ||
onRemove(activity.txHash) | ||
} | ||
}, | ||
[onRemove, activity.txHash], | ||
) | ||
|
||
return ( | ||
<ActivityCardLink activity={activity} {...props}> | ||
<ActivityCardContainer isCompleted={isCompleted} isActive={isActive}> | ||
<CardHeader p={0} w="100%"> | ||
<HStack justifyContent="space-between"> | ||
<CurrencyBalance | ||
currency={activity.currency} | ||
amount={activity.amount} | ||
size="xl" | ||
balanceFontWeight="black" | ||
symbolFontWeight="medium" | ||
/> | ||
{isCompleted ? ( | ||
<Tooltip label="Remove" placement="top" paddingX={3} paddingY={2}> | ||
<CloseButton | ||
size="sm" | ||
onClick={onClose} | ||
_hover={{ backgroundColor: undefined }} | ||
/> | ||
</Tooltip> | ||
) : ( | ||
<Icon | ||
as={ChevronRightIcon} | ||
boxSize={5} | ||
color={isActive ? "gold.700" : "grey.400"} | ||
_hover={isActive ? { color: "gold.700" } : undefined} | ||
/> | ||
)} | ||
</HStack> | ||
</CardHeader> | ||
<CardBody p={0}> | ||
<TextSm fontWeight="semibold" marginBottom={4}> | ||
{capitalize(activity.action)} | ||
</TextSm> | ||
</CardBody> | ||
<CardFooter p={0}> | ||
<StatusInfo | ||
status={activity.status} | ||
withIcon | ||
withDefaultColor | ||
fontWeight="medium" | ||
/> | ||
</CardFooter> | ||
</ActivityCardContainer> | ||
</ActivityCardLink> | ||
) | ||
} |
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
28 changes: 28 additions & 0 deletions
28
dapp/src/components/shared/Activities/ActivityCard/ActivityCardLink.tsx
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,28 @@ | ||
import React from "react" | ||
|
||
import { Link as ReactRouterLink } from "react-router-dom" | ||
import { Link as ChakraLink } from "@chakra-ui/react" | ||
import { ActivityInfo } from "#/types" | ||
|
||
type ActivityCardLinkProps = { | ||
activity: ActivityInfo | ||
children: React.ReactNode | ||
} | ||
|
||
export function ActivityCardLink({ | ||
activity, | ||
children, | ||
...props | ||
}: ActivityCardLinkProps) { | ||
return ( | ||
<ChakraLink | ||
as={ReactRouterLink} | ||
to="/activity-details" | ||
state={{ activity }} | ||
key={activity.txHash} | ||
{...props} | ||
> | ||
{children} | ||
</ChakraLink> | ||
) | ||
} |
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 @@ | ||
export * from "./ActivityCard" |
63 changes: 63 additions & 0 deletions
63
dapp/src/components/shared/Activities/ActivityCarousel/ActivityCarousel.tsx
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,63 @@ | ||
import React, { useCallback, useRef, useState } from "react" | ||
import Slider from "react-slick" | ||
import { Box, HStack, BoxProps } from "@chakra-ui/react" | ||
import { ActivityCard } from "../ActivityCard" | ||
import { activityCarouselSettings } from "./utils" | ||
import { mockedActivities } from "../mock-activities" | ||
|
||
export function ActivityCarousel({ ...props }: BoxProps) { | ||
const sliderRef = useRef<HTMLDivElement & Slider>(null) | ||
|
||
// TODO: Lines 12-30 should be replaced by redux store when subgraphs are implemented | ||
const [activities, setActivities] = useState(mockedActivities) | ||
|
||
const onRemove = useCallback( | ||
(activityHash: string) => { | ||
const removedIndex = activities.findIndex( | ||
(activity) => activity.txHash === activityHash, | ||
) | ||
const filteredActivities = activities.filter( | ||
(activity) => activity.txHash !== activityHash, | ||
) | ||
const isLastCard = removedIndex === activities.length - 1 | ||
if (isLastCard) { | ||
sliderRef.current?.slickPrev() | ||
} | ||
sliderRef.current?.forceUpdate() | ||
setActivities(filteredActivities) | ||
}, | ||
[activities], | ||
) | ||
|
||
return ( | ||
<Box pos="relative" {...props}> | ||
<HStack | ||
as={Slider} | ||
overflow="hidden" | ||
ref={sliderRef} | ||
pl={2} | ||
ml={-2} | ||
overflowX="hidden" | ||
pb={6} | ||
_after={{ | ||
content: '""', | ||
pos: "absolute", | ||
right: 0, | ||
w: 20, | ||
height: 40, | ||
bgGradient: "linear(to-r, transparent, gold.300)", | ||
}} | ||
{...activityCarouselSettings} | ||
> | ||
{activities.map((activity) => ( | ||
<ActivityCard | ||
key={activity.txHash} | ||
activity={activity} | ||
onRemove={onRemove} | ||
mr={3} | ||
/> | ||
))} | ||
</HStack> | ||
</Box> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
dapp/src/components/shared/Activities/ActivityCarousel/index.tsx
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 @@ | ||
export * from "./ActivityCarousel" |
48 changes: 48 additions & 0 deletions
48
dapp/src/components/shared/Activities/ActivityCarousel/utils/carouselArrows.tsx
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,48 @@ | ||
import React from "react" | ||
import { CustomArrowProps } from "react-slick" | ||
import { IconButton, IconButtonProps } from "@chakra-ui/react" | ||
import { ArrowLeft, ArrowRight } from "#/assets/icons" | ||
|
||
type PaginationArrowType = CustomArrowProps & IconButtonProps | ||
|
||
function PaginationArrow({ icon, onClick, ...props }: PaginationArrowType) { | ||
return ( | ||
<IconButton | ||
icon={icon} | ||
variant="pagination" | ||
size="sm" | ||
borderRadius={32} | ||
onClick={onClick} | ||
isDisabled={onClick === null} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
export function PrevArrowCarousel({ onClick }: CustomArrowProps) { | ||
return ( | ||
<PaginationArrow | ||
position="absolute" | ||
mr={2} | ||
right={-56} | ||
top={-10} | ||
onClick={onClick} | ||
icon={<ArrowLeft />} | ||
aria-label="prev" | ||
data-id="slick-arrow-prev" | ||
/> | ||
) | ||
} | ||
export function NextArrowCarousel({ onClick }: CustomArrowProps) { | ||
return ( | ||
<PaginationArrow | ||
position="absolute" | ||
right={-64} | ||
top={-10} | ||
onClick={onClick} | ||
icon={<ArrowRight />} | ||
aria-label="next" | ||
data-id="slick-arrow-next" | ||
/> | ||
) | ||
} |
Oops, something went wrong.