Skip to content

Commit

Permalink
feat: improve share on desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
ashhhleyyy committed Dec 21, 2024
1 parent 2379cb3 commit b39c0a7
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pages/players/[id]/wrapped.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,15 @@ const Slide7: React.FC<{player: PlayerProfile, static?: boolean, wrapped: Player
}

export const Slide8: React.FC<{player: PlayerProfile, wrapped: PlayerWrappedData, year: number, thank: boolean}> = (props) => {
const [shareSupported, setShareSupported] = useState(false);
function share() {
const url = `https://stats.nucleoid.xyz/player/${props.player.id}/wrapped?year=${props.year}`;

useEffect(() => {
setShareSupported(!!navigator.share);
}, []);
if (navigator.share) {
navigator.share({url})
} else {
navigator.clipboard.writeText(url).then(() => alert('Copied to clipboard!'));
}
}

return <>
<h1>
Expand All @@ -310,7 +314,7 @@ export const Slide8: React.FC<{player: PlayerProfile, wrapped: PlayerWrappedData
</p>

<p>
Here's everything on one page, {shareSupported ? 'scroll to the bottom' : ''} to share with your friends!
Here's everything on one page, scroll to the bottom to share with your friends!
</p>
</DelayFadeBlock>}

Expand All @@ -324,11 +328,11 @@ export const Slide8: React.FC<{player: PlayerProfile, wrapped: PlayerWrappedData
{props.wrapped.most_players_games.length > 1 && <Slide7 year={props.year} player={props.player} wrapped={props.wrapped} static />}
</DelayFade>

{shareSupported && <DelayFade delay={2000}>
<button className={styles.button} onClick={() => navigator.share({url: `https://stats.nucleoid.xyz/player/${props.player.id}/wrapped?year=${props.year}`})}>
<DelayFade delay={props.thank ? 1500 : 1000}>
<button className={styles.button} onClick={() => share()}>
Share
</button>
</DelayFade>}
</DelayFade>
</>
}

Expand Down

0 comments on commit b39c0a7

Please sign in to comment.