Togglescroll?

This commit is contained in:
Daniel Schädler 2025-03-17 16:07:41 +01:00
parent 01f8a8e34f
commit e1bfa05b9f
1 changed files with 78 additions and 49 deletions

View File

@ -11,6 +11,10 @@ export default class GroupStage extends Component {
super(props); super(props);
this.state = {showMatches: this.props.showMatches}; this.state = {showMatches: this.props.showMatches};
this.toggleShowMatches = this.toggleShowMatches.bind(this); this.toggleShowMatches = this.toggleShowMatches.bind(this);
this.groupRefs = this.props.groups.reduce((acc, group) => {
acc[group.id] = React.createRef();
return acc;
}, {});
} }
toggleShowMatches() { toggleShowMatches() {
@ -18,21 +22,26 @@ export default class GroupStage extends Component {
} }
render() { render() {
return (<div className='py-2 px-1'> return (
<h1 className='custom-font m-2'> <div className="py-2 px-1">
<span className='px-2'>Gruppenphase</span> <h1 className="custom-font m-2">
<span className="px-2">Gruppenphase</span>
</h1> </h1>
<Row className=''> <Row className="">
{this.props.groups.map(group => <Group {this.props.groups.map(group => (
<Group
group={group} group={group}
key={group.id} key={group.id}
isSignedIn={this.props.isSignedIn} isSignedIn={this.props.isSignedIn}
isOwner={this.props.isOwner} isOwner={this.props.isOwner}
showMatches={this.state.showMatches} showMatches={this.state.showMatches}
showMatchesToggle={this.toggleShowMatches} showMatchesToggle={this.toggleShowMatches}
/>)} groupRef={this.groupRefs[group.id]}
/>
))}
</Row> </Row>
</div>); </div>
);
} }
} }
@ -40,11 +49,11 @@ function ShowMatchesToggleChevron(props) {
const toggleClass = props.show ? 'rotate' : ''; const toggleClass = props.show ? 'rotate' : '';
return ( return (
<Button <Button
color='link' color="link"
onClick={props.toggle} onClick={props.toggle}
className='position-absolute top-0 end-0 m-2 mt-1 button-no-focus' className="position-absolute top-0 end-0 m-2 mt-1 button-no-focus"
> >
<FaChevronDown className={`my-chevron ${toggleClass}`} /> <FaChevronDown className={`my-chevron ${toggleClass}`}/>
</Button> </Button>
); );
} }
@ -54,10 +63,18 @@ export class Group extends Component {
super(props); super(props);
this.state = props.group; this.state = props.group;
this.reload = this.reload.bind(this); this.reload = this.reload.bind(this);
this.handleToggle = this.handleToggle.bind(this);
this.onReloadSuccess = this.onReloadSuccess.bind(this); this.onReloadSuccess = this.onReloadSuccess.bind(this);
this.onReloadError = this.onReloadError.bind(this); this.onReloadError = this.onReloadError.bind(this);
} }
handleToggle() {
this.props.showMatchesToggle();
if (this.props.groupRef.current) {
this.props.groupRef.current.scrollIntoView({behavior: 'smooth', block: 'center'});
}
}
reload() { reload() {
getGroup(this.state.id, this.onReloadSuccess, this.onReloadError); getGroup(this.state.id, this.onReloadSuccess, this.onReloadError);
} }
@ -71,27 +88,39 @@ export class Group extends Component {
} }
render() { render() {
return (<Col className='minw-25 py-2'> return (
<Col className="minw-25 py-2" ref={this.props.groupRef}>
<Card> <Card>
<CardBody className="position-relative"> <CardBody className="position-relative">
<h3 className='custom-font'> <h3 className="custom-font">
Gruppe {this.state.number} Gruppe {this.state.number}
</h3> </h3>
<ShowMatchesToggleChevron show={this.props.showMatches} toggle={this.props.showMatchesToggle}/> <ShowMatchesToggleChevron
show={this.props.showMatches}
toggle={this.handleToggle}
/>
<Collapse isOpen={this.props.showMatches}> <Collapse isOpen={this.props.showMatches}>
{this.state.matches.sort(sortMatchesByPositionAscending()).map((match => ( {this.state.matches.sort(sortMatchesByPositionAscending()).map(match => (
<Match match={match} isSignedIn={this.props.isSignedIn} isOwner={this.props.isOwner} <Match
onChange={this.reload} key={match.id}/>)))} match={match}
isSignedIn={this.props.isSignedIn}
isOwner={this.props.isOwner}
onChange={this.reload}
key={match.id}
/>
))}
</Collapse> </Collapse>
<GroupScoresTable scores={this.state.scores}/> <GroupScoresTable scores={this.state.scores}/>
</CardBody> </CardBody>
</Card> </Card>
</Col>); </Col>
);
} }
} }
function GroupScoresTable(props) { function GroupScoresTable(props) {
return (<Table className='mt-4' striped size='sm' responsive> return (
<Table className="mt-4" striped size="sm" responsive>
<thead> <thead>
<tr> <tr>
<th>#</th> <th>#</th>
@ -104,10 +133,10 @@ function GroupScoresTable(props) {
<tbody> <tbody>
{props.scores.map(groupScore => <GroupScoresTableRow score={groupScore} key={groupScore.id}/>)} {props.scores.map(groupScore => <GroupScoresTableRow score={groupScore} key={groupScore.id}/>)}
</tbody> </tbody>
</Table>); </Table>
);
} }
function GroupScoresTableRow(props) { function GroupScoresTableRow(props) {
const teamId = `favorite-team-groupstage-${props.score.team.id}`; const teamId = `favorite-team-groupstage-${props.score.team.id}`;
return ( return (