launch item page links in new window when embedded

This commit is contained in:
Emi Matchu 2020-09-12 23:10:29 -07:00
parent b812cb30a9
commit 0725a7b1e8

View file

@ -12,7 +12,12 @@ import {
useTheme, useTheme,
useToast, useToast,
} from "@chakra-ui/core"; } from "@chakra-ui/core";
import { CheckIcon, ExternalLinkIcon, StarIcon } from "@chakra-ui/icons"; import {
CheckIcon,
ExternalLinkIcon,
ChevronRightIcon,
StarIcon,
} from "@chakra-ui/icons";
import gql from "graphql-tag"; import gql from "graphql-tag";
import { useQuery } from "@apollo/client"; import { useQuery } from "@apollo/client";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
@ -90,13 +95,13 @@ function ItemPageHeader({ itemId, isEmbedded }) {
{item?.name || "Item name here"} {item?.name || "Item name here"}
</Heading1> </Heading1>
</Skeleton> </Skeleton>
<ItemPageBadges item={item} /> <ItemPageBadges item={item} isEmbedded={isEmbedded} />
</Box> </Box>
</Box> </Box>
); );
} }
function ItemPageBadges({ item }) { function ItemPageBadges({ item, isEmbedded }) {
const searchBadgesAreLoaded = item?.name != null && item?.isNc != null; const searchBadgesAreLoaded = item?.name != null && item?.isNc != null;
return ( return (
@ -105,7 +110,10 @@ function ItemPageBadges({ item }) {
{item?.isNc ? <NcBadge /> : <NpBadge />} {item?.isNc ? <NcBadge /> : <NpBadge />}
</Skeleton> </Skeleton>
<Skeleton isLoaded={searchBadgesAreLoaded}> <Skeleton isLoaded={searchBadgesAreLoaded}>
<LinkBadge href={`https://impress.openneo.net/items/${item.id}`}> <LinkBadge
href={`https://impress.openneo.net/items/${item.id}`}
isEmbedded={isEmbedded}
>
Old DTI Old DTI
</LinkBadge> </LinkBadge>
</Skeleton> </Skeleton>
@ -116,6 +124,7 @@ function ItemPageBadges({ item }) {
encodeURIComponent(item.name) + encodeURIComponent(item.name) +
"&name_type=3" "&name_type=3"
} }
isEmbedded={isEmbedded}
> >
Jellyneo Jellyneo
</LinkBadge> </LinkBadge>
@ -127,6 +136,7 @@ function ItemPageBadges({ item }) {
"http://www.neopets.com/market.phtml?type=wizard&string=" + "http://www.neopets.com/market.phtml?type=wizard&string=" +
encodeURIComponent(item.name) encodeURIComponent(item.name)
} }
isEmbedded={isEmbedded}
> >
Shop Wiz Shop Wiz
</LinkBadge> </LinkBadge>
@ -139,6 +149,7 @@ function ItemPageBadges({ item }) {
"http://www.neopets.com/portal/supershopwiz.phtml?string=" + "http://www.neopets.com/portal/supershopwiz.phtml?string=" +
encodeURIComponent(item.name) encodeURIComponent(item.name)
} }
isEmbedded={isEmbedded}
> >
Super Wiz Super Wiz
</LinkBadge> </LinkBadge>
@ -151,6 +162,7 @@ function ItemPageBadges({ item }) {
"http://www.neopets.com/island/tradingpost.phtml?type=browse&criteria=item_exact&search_string=" + "http://www.neopets.com/island/tradingpost.phtml?type=browse&criteria=item_exact&search_string=" +
encodeURIComponent(item.name) encodeURIComponent(item.name)
} }
isEmbedded={isEmbedded}
> >
Trade Post Trade Post
</LinkBadge> </LinkBadge>
@ -163,6 +175,7 @@ function ItemPageBadges({ item }) {
"http://www.neopets.com/genie.phtml?type=process_genie&criteria=exact&auctiongenie=" + "http://www.neopets.com/genie.phtml?type=process_genie&criteria=exact&auctiongenie=" +
encodeURIComponent(item.name) encodeURIComponent(item.name)
} }
isEmbedded={isEmbedded}
> >
Auctions Auctions
</LinkBadge> </LinkBadge>
@ -172,11 +185,24 @@ function ItemPageBadges({ item }) {
); );
} }
function LinkBadge({ children, href }) { function LinkBadge({ children, href, isEmbedded }) {
return ( return (
<Badge as="a" href={href} display="flex" alignItems="center"> <Badge
as="a"
href={href}
display="flex"
alignItems="center"
// Normally we want to act like a normal webpage, and treat links as
// normal. But when we're on the wardrobe page, we want to avoid
// disrupting the outfit, and open in a new window instead.
target={isEmbedded ? "_blank" : undefined}
>
{children} {children}
<ExternalLinkIcon marginLeft="1" /> {
// We also change the icon to signal whether this will launch in a new
// window or not!
isEmbedded ? <ExternalLinkIcon marginLeft="1" /> : <ChevronRightIcon />
}
</Badge> </Badge>
); );
} }