|
| 1 | +import React from "react"; |
| 2 | +import styled from "styled-components"; |
| 3 | +import XIcon from "svgs/socialmedia/x.svg"; |
| 4 | + |
| 5 | +const Container = styled.div` |
| 6 | + display: flex; |
| 7 | + flex-direction: row; |
| 8 | + align-items: center; |
| 9 | + justify-content: space-between; |
| 10 | +`; |
| 11 | + |
| 12 | +const StyledTitle = styled.h1` |
| 13 | + margin-bottom: calc(16px + (48 - 16) * (min(max(100vw, 375px), 1250px) - 375px) / 875); |
| 14 | +`; |
| 15 | + |
| 16 | +const XLinkContainer = styled.div` |
| 17 | + display: flex; |
| 18 | + color: ${({ theme }) => theme.primaryBlue}; |
| 19 | + margin-bottom: calc(16px + (48 - 16) * (min(max(100vw, 375px), 1250px) - 375px) / 875); |
| 20 | +`; |
| 21 | + |
| 22 | +const StyledXIcon = styled(XIcon)` |
| 23 | + fill: ${({ theme }) => theme.primaryBlue}; |
| 24 | + width: 16px; |
| 25 | + height: 16px; |
| 26 | +`; |
| 27 | + |
| 28 | +const StyledLink = styled.a` |
| 29 | + display: flex; |
| 30 | + border: 0px; |
| 31 | + align-items: center; |
| 32 | + gap: 8px; |
| 33 | +
|
| 34 | + &:hover { |
| 35 | + text-decoration: underline; |
| 36 | + } |
| 37 | +`; |
| 38 | + |
| 39 | +interface IHeader { |
| 40 | + levelTitle: string; |
| 41 | + levelNumber: number; |
| 42 | + totalCoherent: number; |
| 43 | + totalResolvedDisputes: number; |
| 44 | +} |
| 45 | + |
| 46 | +const Header: React.FC<IHeader> = ({ levelTitle, levelNumber, totalCoherent, totalResolvedDisputes }) => { |
| 47 | + const coherencePercentage = parseFloat(((totalCoherent / Math.max(totalResolvedDisputes, 1)) * 100).toFixed(2)); |
| 48 | + const courtUrl = window.location.origin; |
| 49 | + const xPostText = `Hey I've been busy as a Juror on the Kleros court, check out my score: \n\nLevel: ${levelNumber} (${levelTitle})\nCoherence Percentage: ${coherencePercentage}%\nCoherent Votes: ${totalCoherent}/${totalResolvedDisputes}\n\nBe a juror with me! ➡️ ${courtUrl}`; |
| 50 | + const xShareUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent(xPostText)}`; |
| 51 | + |
| 52 | + return ( |
| 53 | + <Container> |
| 54 | + <StyledTitle>Juror Dashboard</StyledTitle> |
| 55 | + <XLinkContainer> |
| 56 | + <StyledLink href={xShareUrl} target="_blank" rel="noreferrer"> |
| 57 | + <StyledXIcon /> <span>Share your juror score</span> |
| 58 | + </StyledLink> |
| 59 | + </XLinkContainer> |
| 60 | + </Container> |
| 61 | + ); |
| 62 | +}; |
| 63 | + |
| 64 | +export default Header; |
0 commit comments