fork/replay-manager-for-slippi
git clone https://git.julia.blue/fork/replay-manager-for-slippi
c9ee152
2.3.4
1import { formatDistanceToNowStrict } from 'date-fns' ; 2import styled from '@emotion/styled' ; 3import { 4Backup , 5CheckBox , 6HourglassTop , 7NotificationsActive , 8Tv , 9} from '@mui/icons-material' ; 10import { Box , Stack , Tooltip , Typography } from '@mui/material' ; 11import { useState } from 'react' ; 12import { NameWithHighlight , State , Station , Stream } from '../common/types' ; 13import { calledColor , highlightColor , startedColor } from '../common/constants' ; 14 15const EntrantNames = styled ( Stack ) ` 16width: calc(100% - 22px); 17` ; 18 19const EntrantSection = styled ( Stack ) ` 20align-items: center; 21box-sizing: border-box; 22width: 50%; 23` ; 24 25const EntrantScore = styled ( Box ) ` 26overflow-x: hidden; 27margin: 0 4px; 28text-overflow: ellipsis; 29width: 14px; 30` ; 31 32const Name = styled . div ` 33overflow-x: hidden; 34text-overflow: ellipsis; 35white-space: nowrap; 36` ; 37 38function EntrantName ({ entrantName} :{ entrantName :NameWithHighlight }) { 39if ( ! entrantName . highlight ) { 40return < Name >{ entrantName . name }</ Name >; 41} 42 43return ( 44< Name > 45< span >{ entrantName . name . substring ( 0 , entrantName . highlight . start )}</ span > 46< span style = {{ backgroundColor :highlightColor }}> 47{ entrantName . name . substring ( 48entrantName . highlight . start , 49entrantName . highlight . end , 50)} 51</ span > 52< span >{ entrantName . name . substring ( entrantName . highlight . end )}</ span > 53</ Name > 54); 55} 56 57function CallTimer ({ 58 updatedAtMs, 59 matchState, 60} :{ 61updatedAtMs :number ; 62matchState :number ; 63}) { 64const [ timeAgo , setTimeAgo ] = useState ( 65formatDistanceToNowStrict ( updatedAtMs , { addSuffix :true }), 66); 67const handleOpen = () => { 68setTimeAgo ( formatDistanceToNowStrict ( updatedAtMs , { addSuffix :true })); 69}; 70 71if ( matchState === State . STARTED ) { 72return ( 73< Tooltip 74arrow 75placement = "left-start" 76onOpen = { handleOpen } 77title = { `Started ${ timeAgo } ` } 78> 79< HourglassTop 80fontSize = "small" 81style = {{ color :startedColor , padding :'9px 0' }} 82/> 83</ Tooltip > 84); 85} 86 87if ( matchState === State . CALLED ) { 88return ( 89< Tooltip 90arrow 91placement = "left-start" 92onOpen = { handleOpen } 93title = { `Called ${ timeAgo } ` } 94> 95< NotificationsActive 96fontSize = "small" 97style = {{ color :calledColor , padding :'9px 0' }} 98/> 99</ Tooltip > 100); 101} 102 103return null ; 104} 105 106export default function SetView ({ 107 entrant1Names, 108 entrant1Score, 109 entrant1Win, 110 entrant2Names, 111 entrant2Score, 112 fullRoundText, 113 showScores, 114 state, 115 stream, 116 station, 117 wasReported, 118 updatedAtMs, 119} :{ 120entrant1Names :NameWithHighlight []; 121entrant1Score :number | null ; 122entrant1Win :boolean ; 123entrant2Names :NameWithHighlight []; 124entrant2Score :number | null ; 125fullRoundText :string ; 126showScores :boolean ; 127state :number ; 128stream :Stream | null ; 129station :Station | null ; 130wasReported :boolean ; 131updatedAtMs :number ; 132}) { 133let leftScore = '\u00A0' ; 134let rightScore = '\u00A0' ; 135if ( showScores ) { 136if ( entrant1Score || entrant2Score ) { 137leftScore = entrant1Score ?entrant1Score . toString ( 10 ) :'0' ; 138rightScore = entrant2Score ?entrant2Score . toString ( 10 ) :'0' ; 139} else if ( entrant1Win ) { 140leftScore = 'W' ; 141rightScore = 'L' ; 142} else { 143leftScore = 'L' ; 144rightScore = 'W' ; 145} 146} 147 148let streamVerb = 'Queued' ; 149if ( state === State . STARTED ) { 150streamVerb = 'Streaming' ; 151} else if ( state === State . COMPLETED ) { 152streamVerb = 'Streamed' ; 153} 154 155let stationVerb = 'Queued' ; 156if ( state === State . STARTED ) { 157stationVerb = 'Playing' ; 158} else if ( state === State . COMPLETED ) { 159stationVerb = 'Played' ; 160} 161 162return ( 163< Stack direction = "row" width = "100%" > 164< Stack alignItems = "center" direction = "row" width = "20px" > 165{ wasReported && ( 166< Tooltip arrow title = "Reported" > 167< CheckBox /> 168</ Tooltip > 169)} 170{ ! wasReported && stream && ( 171< Tooltip arrow title = { ` ${ streamVerb } on ${ stream . path } ` }> 172< Tv fontSize = "small" /> 173</ Tooltip > 174)} 175{ ! wasReported && ! stream && station && ( 176< Tooltip arrow title = { ` ${ stationVerb } at station ${ station . number } ` }> 177< Typography variant = "body1" textAlign = "center" width = "20px" > 178{ station . number } 179</ Typography > 180</ Tooltip > 181)} 182</ Stack > 183< Stack width = "calc(100% - 40px)" > 184< Box sx = {{ typography :'caption' }} textAlign = "center" > 185{ fullRoundText } 186</ Box > 187< Stack alignItems = "center" direction = "row" sx = {{ typography :'body2' }}> 188< EntrantSection borderRight = { 1 } direction = "row-reverse" > 189< EntrantScore textAlign = "right" >{ leftScore }</ EntrantScore > 190< EntrantNames textAlign = "right" > 191< EntrantName entrantName = { entrant1Names [ 0 ]} /> 192{ entrant1Names . length > 1 && ( 193< EntrantName entrantName = { entrant1Names [ 1 ]} /> 194)} 195</ EntrantNames > 196</ EntrantSection > 197< EntrantSection borderLeft = { 1 } direction = "row" > 198< EntrantScore >{ rightScore }</ EntrantScore > 199< EntrantNames > 200< EntrantName entrantName = { entrant2Names [ 0 ]} /> 201{ entrant2Names . length > 1 && ( 202< EntrantName entrantName = { entrant2Names [ 1 ]} /> 203)} 204</ EntrantNames > 205</ EntrantSection > 206</ Stack > 207</ Stack > 208< Stack 209alignItems = "center" 210direction = "row" 211justifyContent = "flex-end" 212width = "20px" 213> 214{( state === State . CALLED || state === State . STARTED ) && ( 215< CallTimer updatedAtMs = { updatedAtMs } matchState = { state } /> 216)} 217{ state === State . COMPLETED && ( 218< Tooltip arrow title = "Completed" > 219< Backup fontSize = "small" /> 220</ Tooltip > 221)} 222</ Stack > 223</ Stack > 224); 225}