Skip to content

Commit

Permalink
cursors 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Pangoraw committed Nov 24, 2023
1 parent a02ca7f commit 6a1ea98
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 0 additions & 2 deletions frontend/components/CellInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,6 @@ export const CellInput = ({
throw to_throw
}

console.log(users)

const notebook_id_ref = useRef(notebook_id)
notebook_id_ref.current = notebook_id

Expand Down
24 changes: 10 additions & 14 deletions frontend/components/MultiplayerPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PlutoActionsContext } from "../common/PlutoContext.js"

// TODO: investigate why effect is bad with low throttle rate?
// .... update notebook should be pretty fast.
const CURSOR_THROTTLE_RATE = 100
const CURSOR_THROTTLE_RATE = 75
const DEFAULT_CURSOR_COLOR = "#eeeeee"

const mouse_data_to_point = ({relative_to_cell, relative_x, relative_y}) => {
Expand Down Expand Up @@ -86,13 +86,13 @@ const Cursor = ({ mouse: point, color }) => {
<div
ref=${r}
style=${{
position: "fixed",
position: "absolute",
top: -10,
left: -10,
width: 20,
height: 20,
borderRadius: 10,
border: "solid 4px " + hexToRGBA(color , 0.5),
border: "solid 4px " + hexToRGBA(color, 0.5),
backgroundColor: color,
"-webkit-background-clip": "padding-box", /* for Safari */
backgroundClip: "padding-box", /* for IE9+, Firefox 4+, Opera, Chrome */
Expand All @@ -109,7 +109,7 @@ const usePassiveDocumentEventListener = (event_name, handler_fn, deps) => {
}

export const MultiplayerPanel = ({ users, client_id }) => {
if (!users || Object.keys(users).length == 1) return
if (!users || Object.keys(users).every(user_id => user_id == client_id)) return
const { update_notebook } = useContext(PlutoActionsContext)

usePassiveDocumentEventListener("mousemove", _.throttle((event) => {
Expand All @@ -128,15 +128,11 @@ export const MultiplayerPanel = ({ users, client_id }) => {
usePassiveDocumentEventListener("blur", hide_mouse_for_client, [hide_mouse_for_client])

return html`
<div className="pluto-multiplayer">
<ul>
${Object.entries(users).map(
([clientID, { name, mouse, color, focused_cell }]) =>
html`<li key=${clientID} style=${`color: ${color};`}>${name} - ${focused_cell}
${client_id == clientID || !mouse ? null : html`<${Cursor} mouse=${mouse_data_to_point(mouse)} color=${color} />`}
</li>`
)}
</ul>
</div>
<pluto-cursor-list>
${Object.entries(users).map(
([clientID, { name, mouse, color, focused_cell }]) =>
client_id == clientID || !mouse ? null : html`<${Cursor} key=${clientID} mouse=${mouse_data_to_point(mouse)} color=${color} />`
)}
</pluto-cursor-list>
`
}
7 changes: 7 additions & 0 deletions frontend/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -3600,6 +3600,13 @@ pluto-cell.hooked_up pluto-output {
z-index: 1000;
}

pluto-cursor-list {
position: fixed;
top: 0;
left: 0;
z-index: 1000;
}

.pluto-multiplayer ul {
margin: 0;
padding: 5px;
Expand Down

0 comments on commit 6a1ea98

Please sign in to comment.