-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace TwitterFeed with SlippiStore upsell banner (#420)
* chore: replace twitter feed with shop upsell * chore: switch to stylex * use stylex * add countdown * clear countdown on shop closure * why am i such a derp * remove seconds from countdown * dont memoize countdown * define interval before checkTime * only show seconds when theres less than an hour left --------- Co-authored-by: Vince Au <vinceau09@gmail.com>
- Loading branch information
Showing
5 changed files
with
124 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { Button, Typography } from "@mui/material"; | ||
import * as stylex from "@stylexjs/stylex"; | ||
import type { Duration } from "date-fns"; | ||
import { formatDuration, intervalToDuration, isBefore } from "date-fns"; | ||
import React from "react"; | ||
|
||
import { ExternalLink } from "@/components/external_link"; | ||
import { shortEnLocale } from "@/lib/time"; | ||
import shopImage from "@/styles/images/shop-image.png"; | ||
|
||
const SHOP_CLOSES_AT = new Date("2024-02-28T08:00:00.000Z"); | ||
|
||
const styles = stylex.create({ | ||
container: { | ||
position: "relative", | ||
flex: "1", | ||
overflow: "hidden", | ||
backgroundColor: "#21ba44", | ||
}, | ||
image: { | ||
position: "absolute", | ||
width: "100%", | ||
objectFit: "cover", | ||
}, | ||
buttonContainer: { | ||
position: "absolute", | ||
top: "150px", | ||
left: "40px", | ||
width: "220px !important", | ||
}, | ||
closeDate: { | ||
position: "absolute", | ||
fontWeight: "bold", | ||
top: "200px", | ||
width: "100%", | ||
color: "white", | ||
fontSize: 15, | ||
textAlign: "center", | ||
}, | ||
}); | ||
|
||
const InternalSlippiStore = ({ shopOpen, countdown }: { shopOpen: boolean; countdown: string }) => { | ||
const buttonText = shopOpen ? "Click to Shop" : "Shop closed"; | ||
return ( | ||
<div {...stylex.props(styles.container)}> | ||
<img src={shopImage} {...stylex.props(styles.image)} /> | ||
<div {...stylex.props(styles.buttonContainer)}> | ||
<Button | ||
variant="contained" | ||
sx={{ color: "white", textTransform: "uppercase" }} | ||
color="secondary" | ||
fullWidth={true} | ||
LinkComponent={ExternalLink} | ||
href="https://start.gg/slippi/shop" | ||
disabled={!shopOpen} | ||
> | ||
{buttonText} | ||
</Button> | ||
</div> | ||
{countdown && ( | ||
<div {...stylex.props(styles.closeDate)}> | ||
<Typography variant="overline" sx={{ lineHeight: "initial" }}> | ||
Shop closes in | ||
</Typography> | ||
<Typography fontWeight="bold">{countdown}</Typography> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export const SlippiStore = React.memo(function SlippiStore() { | ||
const [shopOpen, setShopOpen] = React.useState(true); | ||
const [countdown, setCountdown] = React.useState<string>(""); | ||
|
||
React.useEffect(() => { | ||
const endDate = SHOP_CLOSES_AT; | ||
|
||
// eslint-disable-next-line prefer-const | ||
let interval: number | undefined; | ||
const checkTime = () => { | ||
const now = new Date(); | ||
const duration = intervalToDuration({ start: now, end: endDate }); | ||
|
||
if (isBefore(endDate, now)) { | ||
setShopOpen(false); | ||
setCountdown(""); | ||
window.clearInterval(interval); | ||
} else { | ||
const format: (keyof Duration)[] = | ||
(duration.hours ?? 0) < 1 ? ["minutes", "seconds"] : ["days", "hours", "minutes"]; | ||
setCountdown(formatDuration(duration, { format, locale: shortEnLocale })); | ||
} | ||
}; | ||
checkTime(); | ||
|
||
interval = window.setInterval(checkTime, 1000); | ||
return () => window.clearInterval(interval); | ||
}, []); | ||
|
||
return <InternalSlippiStore shopOpen={shopOpen} countdown={countdown} />; | ||
}); |
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.