Add auto-scrolling for log
Styling is still a WIP
This commit is contained in:
parent
4c8d27b659
commit
368dcd4a65
2 changed files with 28 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import {GameWasm, Letter as LetterData, MyResult, PlayedTile, PlayerAndScore, Tray, WordResult} from "word_grid";
|
import {GameWasm, Letter as LetterData, MyResult, PlayedTile, PlayerAndScore, Tray, WordResult} from "word_grid";
|
||||||
import {ChangeEvent, JSX, useEffect, useMemo, useReducer, useState} from "react";
|
import {ChangeEvent, JSX, useEffect, useMemo, useReducer, useRef, useState} from "react";
|
||||||
|
|
||||||
export interface Settings {
|
export interface Settings {
|
||||||
trayLength: number;
|
trayLength: number;
|
||||||
|
@ -200,6 +200,17 @@ export function Game(props: {wasm: GameWasm, settings: Settings}) {
|
||||||
|
|
||||||
}, [turnCount]);
|
}, [turnCount]);
|
||||||
|
|
||||||
|
const logDivRef = useRef(null);
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Effect is to keep the log window scrolled down
|
||||||
|
if (logDivRef.current != null) {
|
||||||
|
logDivRef.current.scrollTo(0, logDivRef.current.scrollHeight); // scroll down
|
||||||
|
}
|
||||||
|
}, [logInfo])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
|
@ -207,7 +218,7 @@ export function Game(props: {wasm: GameWasm, settings: Settings}) {
|
||||||
<Grid cellTypes={cellTypes} playerLetters={playerLetters} boardLetters={boardLetters} dispatch={trayDispatch}/>
|
<Grid cellTypes={cellTypes} playerLetters={playerLetters} boardLetters={boardLetters} dispatch={trayDispatch}/>
|
||||||
<div className="message-log">
|
<div className="message-log">
|
||||||
<Scores playerScores={playerAndScores}/>
|
<Scores playerScores={playerAndScores}/>
|
||||||
<div className="log">
|
<div className="log" ref={logDivRef}>
|
||||||
{logInfo}
|
{logInfo}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -125,19 +125,28 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.board-log {
|
.board-log {
|
||||||
display: flex;
|
display: grid;
|
||||||
justify-content: start;
|
grid-template-columns: @tile-width*@board-length+15px 1fr;
|
||||||
flex-flow: row wrap;
|
height: @tile-width*@board-length + 15px;
|
||||||
align-items: stretch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.message-log {
|
.message-log {
|
||||||
border-color: black;
|
border-color: black;
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
border-width: 2px;
|
border-width: 2px;
|
||||||
width: max-content;
|
width: 100%;
|
||||||
margin: 5px
|
margin: 5px;
|
||||||
|
height: inherit;
|
||||||
|
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: 6em 1fr;
|
||||||
|
|
||||||
|
.log {
|
||||||
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.scoring {
|
.scoring {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
Loading…
Reference in a new issue