portal to decorate players by ref instead of ID
This commit is contained in:
@@ -17,7 +17,9 @@ export default (props: { playerKey: string } & Stylable) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
id={`player-${props.playerKey}`}
|
ref={(e) => {
|
||||||
|
if (table != null) table.playerRefs[props.playerKey] = e;
|
||||||
|
}}
|
||||||
style={{
|
style={{
|
||||||
...props.style,
|
...props.style,
|
||||||
"background-color": playerColor(props.playerKey),
|
"background-color": playerColor(props.playerKey),
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export const TableContext = createContext<{
|
|||||||
wsEvents: Stream<TWsOut, any>;
|
wsEvents: Stream<TWsOut, any>;
|
||||||
playerNames: Store<{ [key: string]: string }>;
|
playerNames: Store<{ [key: string]: string }>;
|
||||||
players: Accessor<string[]>;
|
players: Accessor<string[]>;
|
||||||
|
playerRefs: { [key: string]: HTMLDivElement };
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
export default (props: { tableKey: string }) => {
|
export default (props: { tableKey: string }) => {
|
||||||
@@ -94,6 +95,7 @@ export default (props: { tableKey: string }) => {
|
|||||||
view,
|
view,
|
||||||
playerNames,
|
playerNames,
|
||||||
players,
|
players,
|
||||||
|
playerRefs: {},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* Player avatars around the table */}
|
{/* Player avatars around the table */}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export default () => {
|
|||||||
>
|
>
|
||||||
{([playerKey, handCount], i) => (
|
{([playerKey, handCount], i) => (
|
||||||
<Portal
|
<Portal
|
||||||
mount={document.getElementById(`player-${playerKey}`)!}
|
mount={table.playerRefs[playerKey]}
|
||||||
ref={(ref) => {
|
ref={(ref) => {
|
||||||
console.log("Setting hand ref");
|
console.log("Setting hand ref");
|
||||||
const midOffset =
|
const midOffset =
|
||||||
|
|||||||
Reference in New Issue
Block a user